PowerShell foreach loop with embedded if statement yields "cannot accept 'True' as positional parameter" -


i'm trying write simple ps line take exported .csv of ad groups in particular "regions" have set up, take groupscope (universal vs. global), , depending on scope of group, write "department" attribute either "universal" or "global." reason doing identify between 2 scopes within sharepoint.

$uni="universal" import-csv \\usershare\user\me\output\groups.csv | foreach {get-adgroup -identity $_.name -properties * | set-adgroup if($_.groupscope -eq $uni){-replace @{department=$uni}}} 

this returning following error message though: "a positional parameter cannot found accepts argument 'true.'"

i'm missing simple here started out , i'm self-teaching trial , error mostly. can provide!

you're use of if block not valid trying accomplish, return true or false , set-adgroup not know hence error.

try this:

$uni="universal" $csv = import-csv -path '\\usershare\user\me\output\groups.csv' foreach($i in $csv) {     if($i.groupscope -eq $uni)     {         get-adgroup -identity $i.name -properties 'department' |             set-adgroup -replace @{department=$uni}     } } 

i've set properties pull department smaller scope speed query.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -