We have 10 Server 2016 AD servers with around 1500 users.<\/p>\n
We’ve been tasked to update all users Department, Job Title, Description and contact numbers for these users.<\/p>\n
Now I want to update all these users via PS but want to first get a export of all users<\/p>\n
Get-AdUser -Filter * | Format-Table SamAccount,Name,Description,Job Title,Department | Export-Csv -Path c:\\Reporting\n<\/code><\/pre>\nBut this results in an error:<\/p>\n
Format-Table : A positional parameter cannot be found that accepts argument 'System.Object[]'.\nAt line:1 char:24\n+ ... -Filter * | Format-Table SamAccount,Name,Description,Job Title,Depart ...\n+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n + CategoryInfo : InvalidArgument: (:) [Format-Table], ParameterBindingException\n + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.FormatTableCommand\n<\/code><\/pre>\nNot sure why I’m getting an error on Format-Table SamAccount,Name,Description,Job Title,Department<\/p>\n
I want the CSV to show me the SamAccount,Name,Description,Job Title,Department info of all the users.<\/p>\n
Once we have this info, we’ll create new csv files with the correct info and update the users. To do this I was thinking of using a command similar to this:<\/p>\n
Import-Module ActiveDirectory \n\n$users = Import-csv -Path c:\\powershell\\ad_users.csv\n\nforeach ($user in $users) {\n\nGet-ADUser -Filter \"employeeID -eq '$($user.employeeID)'\" -Properties * -SearchBase \"OU=Asia_Sales,dc=shellgeek,dc=com\" |Set-ADUser -department $($user.department) -title $($user.title) \n}\n<\/code><\/pre>\nSome guidance would be appreciated.<\/p>","upvoteCount":12,"answerCount":24,"datePublished":"2022-04-22T03:47:33.000Z","author":{"@type":"Person","name":"divanmohr","url":"https://community.spiceworks.com/u/divanmohr"},"suggestedAnswer":[{"@type":"Answer","text":"
A few thing that i would guess, unsure the use of ‘Format-Table’ in that context when you can just select the parameters you want thru the get-aduser command.<\/p>\n
And the parameters you are using seem to not be the right ones.<\/p>\n
Try to use<\/p>\n
Get-ADUser -filter {SamAccountName -eq \"paubry-at\"} -Properties *\n<\/code><\/pre>\nThat’ll show all the parameters you can get out of it.<\/p>\n
and then to display the better option would be :<\/p>\n
Get-ADUser -filter * -Properties SamAccountName,Name,Description,Title,Department\n\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2022-04-22T05:30:36.000Z","url":"https://community.spiceworks.com/t/powershell-issue/831051/5","author":{"@type":"Person","name":"peter-ere","url":"https://community.spiceworks.com/u/peter-ere"}},{"@type":"Answer","text":"