I am new to PS and I am trying to write a function which takes in parameters from a global variable. I want to pass a path name read from a .txt file into a function in the same script.
function GetCorrectChildren ([string] $homepath,$min,$max,$row)
{
#Testpoint 2
write-host "homepath = $homepath"
$ColItem = (Get-ChildItem $homepath |? {$_.PSIsContainer} | sort-object)
}
foreach ($homepath in (Get-Content $PSScriptRoot\homepath_short.txt))
{
$freeSpace = [win32api]::GetDiskFreeSpace("$homepath").FreeBytesAvailable / 1073741824
$totalSpace = [win32api]::GetDiskFreeSpace("$homepath").TotalNumberOfBytes / 1073741824
$percentageFreeSpace = $freeSpace / $totalSpace * 100
if($freeSpace -lt $threshold)
{
#Testpoint 1
write-host "homepath = $homepath"
GetCorrectChildren ("$homepath",$min,$max,$OriRow)
}
For #Testpoint 1
, it returns the path name correctly which is \\C:\test1\test_a
. However in #Testpoint 2
it returns \\C:\test1\test_a 20 30 System.Object
.
I don't understand what does the 20 30 System.Object
mean and where does it come from? Can some one shine some light on this? Thanks