如何在命令

时间:2015-11-02 17:13:20

标签: powershell powershell-v3.0 netapp

我尝试编写脚本来接受用户名列表,并在netapp存储框中为每个用户名分配一个配额,在PowerShell脚本中调用netapp命令,如下所示:

$names = @("AD\test1", "AD\test2")
foreach ($user in $names) {
    $target = $user
    Invoke-NcSsh -Command 'volume quota policy rule create -vserver FS-ONE -policy-name default -volume testdaffy -type user -target $target -qtree "" -user-mapping off -disk-limit 5MB -soft-disk-limit 3MB -threshold 5MB'
}

运行该命令会出现以下错误:

PS C:\Windows\system32> C:\Users\user\Desktop\add_quota.ps1

Error: command failed: User name $target not found. Reason: general failure.
Error: command failed: User name $target not found. Reason: general failure.

如何在我调用的命令中识别变量$ target,以便每个循环接受我的列表中的其他用户?

使用双引号解决:

Invoke-NcSsh -Command "volume quota policy rule create -vserver FS-ONE -policy-name default -volume testdaffy -type user -target $target -qtree """" -user-mapping off -disk-limit 5MB -soft-disk-limit 3MB -threshold 5MB"

0 个答案:

没有答案