【问题标题】:PowerShell - Error in path while Set-FsrmQuotaPowerShell - Set-FsrmQuota 时路径错误
【发布时间】:2016-08-04 17:12:30
【问题描述】:

我正在尝试编写一个脚本来更改远程服务器上特定目录的配额。为此,我使用以下代码($Quota$chosen_username 作为参数输入):

$prefix_path = "C:\Shares\Users\";
$path = $prefix_path + $chosen_username;

if($Quota){
    invoke-command -computername $servername {Set-FsrmQuota -path $path -Size $Quota+"GB"}
}

if((invoke-command -computername $servername {Get-FsrmQuota -path $path} | select @{n='QuotaSize'; e={$_.Size / 1gb -as [int]}}).QuotaSize -eq $Quota){
    return "Success."
} else {
    return "Failed."
}

它给了我这个错误:

Cannot bind argument to parameter 'Path' because it is an empty string.
       + CategoryInfo          : InvalidData: (:) [Set-FsrmQuota], ParameterBindingValidationException
       + FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Set-FsrmQuota
       + PSComputerName        : ServerName

我已经调试过了,$path 的值是正确的。

【问题讨论】:

  • 这里有错字:$path = $prefixo_path+$chosen_username ($prefix o _path) ?
  • 在这种情况下,是的,因为我正在翻译成英文,对不起。但在代码中是正确的。

标签: powershell fileserver


【解决方案1】:

在远程计算机上使用invoke-command 时,远程主机的本地变量是未知的,因此您必须使用以下任一:

  • 使用前缀表示 PS >= 3

    invoke-command -computername $servername {Set-FsrmQuota -path $using:path -Size $using:Quota+"GB"}
    
  • PS 的argumentlist参数

    invoke-command -computername $servername {Set-FsrmQuota -path $args[0] -Size $args[1]+"GB"} -argumentlist $path,$quota
    

【讨论】:

    猜你喜欢
    • 2014-06-25
    • 1970-01-01
    • 1970-01-01
    • 2019-03-18
    • 1970-01-01
    • 2021-05-27
    • 2012-08-12
    • 2019-08-25
    • 2017-09-18
    相关资源
    最近更新 更多