我正在尝试编写一个脚本来接受用户名列表,并在 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"