I'm trying to write a script to accept a list of user names and assign each one a quota on a netapp storage box invoking a netapp command within a PowerShell script as per below:
$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'
}
Running the command gives the following errors:
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.
How do I get the variable $target to be recognised within the command I invoke so that for each loop it accepts a different user from my list?
Resolved by using double quotes:
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"