调用此函数时,我得到调用null错误的异常。
代码:
if(Test-Path($Env:TEMP)) {
$hsPrefDataDirectories = Get-ChildItem "$Env:TEMP" | where {$_.Name -match "hsperfdata"} | Format-Table name -hideTableHeaders | Out-String -stream
$hsPrefDataDirectories = [regex]::Replace($hsPrefDataDirectories, "^\s+", '')
$hsPrefDataDirectories = [regex]::Replace($hsPrefDataDirectories, "\s+", ',')
$hsPrefDataDirectories = [regex]::Replace($hsPrefDataDirectories, ",$", '')
$hsPrefDataDirectories = $hsPrefDataDirectories.split(",")
.....
$hsPrefDataDirectories = $hsPrefDataDirectories.split(",")
Error:
Exception calling "Replace" with "3" argument(s): "Value cannot be null.
Parameter name: input"
...
You cannot call a method on a null-valued expression.
答案 0 :(得分:0)
您收到此错误,因为在您的" $ Env:TEMP"文件夹没有匹配字符串" hsperfdata"。
在尝试替换字符之前,请确保$ hsPrefDataDirectories不为空。