I have a function that gets all the processes accessing a particular folder and split it's process id. In this function, all the ids are saved in an array. I want to give this array to another function. The code i have is:
$CLRJson = Get-Content -Raw -Path "C:\Users\Lokal-keeran\Documents\Ausbildung\Aufgaben\Powershell\PI-Kill\PIKill.json" | ConvertFrom-Json
##Directory path to be scanned to see if there are processes accessing the files in the given directory.
$CLRDIRProd = $CLRJson.CLRExtproc_PARA_PROD.CLRDIR
$PIDGF = @()
#Get all Processes, accessing a folder
function Get-FileHandle ($HPath){
$handle = handle.exe $HPath
[System.Collections.ArrayList]$Process = $handle | Select-String -Pattern '.*?(?= +type:)' | Select-String -Pattern 'mstsc.exe' -NotMatch
Foreach ($pro in $Process.Matches.Value) {
$AddtoArray = $pro -split(":") | Select-Object -Last 1
$PIDGF += $AddtoArray
}
}
#Stop the Processes accessing that folder
function stop-FileHandle ([string[]]$HPathtoGFH) {
Get-FileHandle -HPath $CLRDIRProd
"The Third Value of this Array is: $PIDGF[2]"
#Stop Command......
}
stop-FileHandle -HPathtoGFH $CLRDIRProd
If i revoke stop-filehandle no output will be shown. Also the global array doesn't contain any value. But if i run the commands in the function Get-Filehandle, it shows me some process ids one below the another, just like it should be.....
Why array could not be given to another function ?