【发布时间】:2016-12-23 14:03:25
【问题描述】:
我是 PS 新手,我正在尝试编写一个从全局变量中获取参数的函数。我想将从 .txt 文件中读取的路径名传递给同一脚本中的函数。
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)
}
对于#Testpoint 1,它会正确返回路径名\\C:\test1\test_a。但是在#Testpoint 2 中,它返回\\C:\test1\test_a 20 30 System.Object。
我不明白20 30 System.Object 是什么意思,它来自哪里?有人可以对此有所启发吗?谢谢
【问题讨论】:
标签: powershell parameter-passing pathname