# Licensed Materials - Property of IBM # # IBM Cognos Products: btsv # # (C) Copyright IBM Corp. 2016, 2017 # # US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. # # Get caRoot since this script locates in $caRoot/bin or $caRoot/bin64. $curPSScriptRoot = split-path -parent $MyInvocation.MyCommand.Definition $caRoot = Split-Path -Path $curPSScriptRoot $caPIDFile = "$caRoot\logs\capids.log" $wlpBootPIDFile = "$caRoot\logs\wlp_cogbootstrap_service.pid" $allPIDFile = "$caRoot\logs\allpids.log" # Function for get children PIDs. pid and name will be put into caPIDFile Function GetChildPID { Param($aPID) $allProc | Where { $_.ParentProcessID -eq $aPID} | ForEach-Object { $aPName = '{0}' -f $_.Name if ( $aPName -ne "conhost.exe") { $pidName = '{0} {1}' -f $_.ProcessID, $_.Name | Out-File -append $caPIDFile } # Recurse call GetChildPID -aPID $_.ProcessID } } # Main starts here # Delete $caPIDFile if it exists if ( Test-Path -Path $caPIDFile) { del $caPIDFile } # Check the existence of $wlpBootPIDFile. If yes get content else exit if ( Test-Path -Path $wlpBootPIDFile) { $bootPID = Get-Content $wlpBootPIDFile if ( !$bootPID ) { exit 0 } } else { exit 0 } # Delete $allPIDFile if it exists if ( Test-Path -Path $allPIDFile) { del $allPIDFile } # Put $bootPID and process name into $caPIDFile $bootProc = Get-Process -id $bootPID if ( $bootProc -ne $null ) { $pidName = '{0} {1}' -f $bootProc.Id, $bootProc.ProcessName | Out-File -append $caPIDFile } # Get information for all processes $allProc = Get-WmiObject -Class Win32_process # Get information for all processes $CAPath = [regex]::escape($caRoot) $allProc | ForEach-Object { $procInfo = '{0} {1} {2} {3}' -f $_.ProcessID, $_.ParentProcessID, $_.Name, $_.Path $procPath = $_.Path if ( $procPath -cmatch $CAPath ) { "-- $procInfo" | Out-File -append $allPIDFile } else { "$procInfo" | Out-File -append $allPIDFile } } # Call function GetChildPID GetChildPID -aPID $bootPID