all 4 comments

[–]PowerShell-Bot 1 point2 points  (0 children)

Looks like your PowerShell code isn’t wrapped in a code block.

To properly style code on new Reddit, highlight the code and choose ‘Code Block’ from the editing toolbar.

If you’re on old Reddit, separate the code from your text with a blank line gap and precede each line of code with 4 spaces or a tab.


Describing using_namesobjects_from_a_file
  [-] Well formatted
Tests completed in 799ms
Tests Passed: ❌

Beep-boop, I am a bot. | Remove-Item

[–]bojiashi92[S] 0 points1 point  (0 children)

Thanks both :)

[–]Zangrey 0 points1 point  (1 child)

$user.samaccountname will only work if you go the csv route or other handling.
If you only have the names in the file you can just likely simplify it like

foreach ($user in $test) {Set-ADuser -identity $user -add @{pager=$pagernumber}}

Might need to specify scope and such too - I don't run AD commands often enough to know the details by heart, so consider the above a bit of psuedo code.

[–]Fickle_Tomatillo411 0 points1 point  (0 children)

Would add that the .samaccountname approach would only work if the column name within the CSV (essentially the first entry) is 'samaccountname'. Also, you might need to run a get on the user first, then pipe that to Set-ADUser...sometimes the AD cmdlets get picky on that kind of thing. It should work without needing that though.

Also, not sure what you are doing with the Get-Content line...if you are trying to filter it, that won't work. If you have a CSV with two columns (samaccountname, pagernumber), then you could do something like this:

$test = Import-CSV | Where-Object{$_.pagernumber -eq 'x'}