0

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"
frodo
  • 1,053
  • 5
  • 17
  • 33
  • 4
    The issue is your quotes. You have single quotes which dont allow the variable to expand. I understand you have them because of the double quotes. Can you switch those to single instead? Or escape them by doubling them up. `-qtree ''` or `-qtree """"` – Matt Nov 02 '15 at 17:28
  • 1
    To add to Matt's suggestions, drop $target altogether, it's not needed. $user already has the username. – Eric Walker Nov 02 '15 at 17:41
  • Thanks for the help - I have tried both suggestions re quotes but still get the same error....I have also removed the $target and use $user instead but still get the same error - except this time telling me $user not found... – frodo Nov 03 '15 at 10:25
  • I have resolved this after looking at your suggestions again by using doiuble 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" – frodo Nov 03 '15 at 11:28

0 Answers0