0 powershell parameter-passing pathname
我是 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)
}
Run Code Online (Sandbox Code Playgroud)
对于#Testpoint 1,它正确返回路径名,即\\C:\test1\test_a。然而其中#Testpoint 2却又回归\\C:\test1\test_a 20 30 System.Object。
我不明白这是什么20 30 System.Object意思以及它来自哪里?有人可以解释一下吗?谢谢
更改最后一行
GetCorrectChildren ("$homepath",$min,$max,$OriRow)
Run Code Online (Sandbox Code Playgroud)
到
GetCorrectChildren $homepath $min $max $OriRow
Run Code Online (Sandbox Code Playgroud)
as("$homepath",$min,$max,$OriRow)创建一个包含四个值的数组,并将其GetCorrectChildren作为第一个参数传递给函数,以便write-host "homepath = $homepath"在其中打印所有 4 个值
| 归档时间: |
|
| 查看次数: |
2420 次 |
| 最近记录: |