Hi All. I am very new to PowerShell. What I am trying to accomplish is to get bulk information updated in AD from other sources. I have a CSV spreadsheet formatted below:<\/p>\n
Test City<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>
Advertisement
Below is my script:<\/p>\n
### Update AD Users\n# Import active directory module for running AD cmdlets\nImport-Module activedirectory\n\n#Store the data from ADUsers.csv in the $ADUsers variable\n$ADUsers = Import-csv C:\\Users\\mwaskosky\\Downloads\\Projects\\UpdateADusers5-7-2021importtest.csv\n\n#Loop through each row containing user details in the excel file\nforeach ($User in $ADUsers)\n{\n#Read user data from each field in each row and assign the data to a variable as below\n\n### -Remove - Add - Replace - Clear @{Attribute1LDAPDisplayName=value1, value2, ...; Attribute2LDAPDisplayName=value1, value2, ...; AttributeNLDAPDisplayName=value1, value2, ...}\n### [-Replace <Hashtable>]\nSet-ADUser -Replace `\n-Name \"$($User.Givenname)$($User.Surname)\"`\n-GivenName $($User.GivenName) `\n-Surname $($User.Surname) `\n-DisplayName \"$($User.DisplayName)\" `\n-Path $($User.Path) `\n-City $($User.City) `\n-Company $($User.Company) `\n-State $($User.State) `\n-StreetAddress $($User.streetaddress) `\n-OfficePhone $($User.OfficePhone) `\n-MobliePhone $($User.MobilePhone) `\n-EmailAddress $($User.email) `\n-Title $($User.jobtitle) `\n-Department $($User.Department) `\n-Discription $($User.Discription) `\n}\n<\/code><\/pre>\n
Advertisement
I am not sure what do do next I have been working on this for a long time now and I have tried many different things. And I think that I am close.<\/p>\n
### Update AD Users\n# Import active directory module for running AD cmdlets\nImport-Module activedirectory\n \n#Store the data from ADUsers.csv in the $ADUsers variable\n$ADUsers = Import-csv C:\\Users\\mwaskosky\\Downloads\\Projects\\UpdateADusers5-7-2021importtest.csv\n\n#Loop through each row containing user details in the CSV file \nforeach ($User in $ADUsers)\n{\n #Read user data from each field in each row and assign the data to a variable as below\n\n \n ### -Remove - Add - Replace - Clear @{Attribute1LDAPDisplayName=value1, value2, ...; Attribute2LDAPDisplayName=value1, value2, ...; AttributeNLDAPDisplayName=value1, value2, ...}\n ### [-Replace <Hashtable>]\n Set-ADUser -Replace `\n -Name \"$($User.Firstname)$($User.Lastname)\"`\n -GivenName $($User.GivenName) `\n -Surname $($User.Surname) `\n -DisplayName \"$($User.DisplayName)\" `\n -Path $($User.Path) `\n -City $($User.City) `\n -Company $($User.Company) `\n -State $($User.State) `\n -StreetAddress $($User.streetaddress) `\n -OfficePhone $($User.OfficePhone) `\n -MobliePhone $($User.MobilePhone) `\n -EmailAddress $($User.email) `\n -Title $($User.jobtitle) `\n -Department $($User.Department) `\n -Discription $($User.Discription) `\n }\n```\n<\/code><\/pre>\n
I am getting the error: \nSet-ADUser : Cannot bind parameter ‘Replace’. Cannot convert the “-Name” value of type “System.String” to type “System.Collections.Hashtable”. At C:\\Users\\mwaskosky\\Documents\\PowerShell PS1\\RMS\\UpdateAD User Accounts.ps1:16 char:13 + Set-ADUser -Replace ` + ~~~~~~~~ + CategoryInfo : InvalidArgument: ( [Set-ADUser], ParameterBindingException + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.ActiveDirectory.Management.Commands.SetADUser<\/p>\n
Any help would be much appreciated. What I am trying to do is to import just information into existing AD accounts.<\/p>\n
Set-ADUser : Cannot bind parameter 'Replace'. Cannot convert the \"-Name\" value of type \"System.String\" to type \"System.Collections.Hashtable\".\nAt C:\\Users\\mwaskosky\\Documents\\PowerShell PS1\\RMS\\UpdateAD User Accounts.ps1:16 char:13\n+ Set-ADUser -Replace `\n+ ~~~~~~~~\n + CategoryInfo : InvalidArgument: (:) [Set-ADUser], ParameterBindingException\n + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.ActiveDirectory.Management.Commands.SetADUser\n\n<\/code><\/pre>","upvoteCount":3,"answerCount":21,"datePublished":"2021-05-17T13:38:04.000Z","author":{"@type":"Person","name":"mwaskosky","url":"https://community.spiceworks.com/u/mwaskosky"},"suggestedAnswer":[{"@type":"Answer","text":"
Hi All. I am very new to PowerShell. What I am trying to accomplish is to get bulk information updated in AD from other sources. I have a CSV spreadsheet formatted below:<\/p>\n
Test City<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>
Below is my script:<\/p>\n
### Update AD Users\n# Import active directory module for running AD cmdlets\nImport-Module activedirectory\n\n#Store the data from ADUsers.csv in the $ADUsers variable\n$ADUsers = Import-csv C:\\Users\\mwaskosky\\Downloads\\Projects\\UpdateADusers5-7-2021importtest.csv\n\n#Loop through each row containing user details in the excel file\nforeach ($User in $ADUsers)\n{\n#Read user data from each field in each row and assign the data to a variable as below\n\n### -Remove - Add - Replace - Clear @{Attribute1LDAPDisplayName=value1, value2, ...; Attribute2LDAPDisplayName=value1, value2, ...; AttributeNLDAPDisplayName=value1, value2, ...}\n### [-Replace <Hashtable>]\nSet-ADUser -Replace `\n-Name \"$($User.Givenname)$($User.Surname)\"`\n-GivenName $($User.GivenName) `\n-Surname $($User.Surname) `\n-DisplayName \"$($User.DisplayName)\" `\n-Path $($User.Path) `\n-City $($User.City) `\n-Company $($User.Company) `\n-State $($User.State) `\n-StreetAddress $($User.streetaddress) `\n-OfficePhone $($User.OfficePhone) `\n-MobliePhone $($User.MobilePhone) `\n-EmailAddress $($User.email) `\n-Title $($User.jobtitle) `\n-Department $($User.Department) `\n-Discription $($User.Discription) `\n}\n<\/code><\/pre>\n
I am not sure what do do next I have been working on this for a long time now and I have tried many different things. And I think that I am close.<\/p>\n
### Update AD Users\n# Import active directory module for running AD cmdlets\nImport-Module activedirectory\n \n#Store the data from ADUsers.csv in the $ADUsers variable\n$ADUsers = Import-csv C:\\Users\\mwaskosky\\Downloads\\Projects\\UpdateADusers5-7-2021importtest.csv\n\n#Loop through each row containing user details in the CSV file \nforeach ($User in $ADUsers)\n{\n #Read user data from each field in each row and assign the data to a variable as below\n\n \n ### -Remove - Add - Replace - Clear @{Attribute1LDAPDisplayName=value1, value2, ...; Attribute2LDAPDisplayName=value1, value2, ...; AttributeNLDAPDisplayName=value1, value2, ...}\n ### [-Replace <Hashtable>]\n Set-ADUser -Replace `\n -Name \"$($User.Firstname)$($User.Lastname)\"`\n -GivenName $($User.GivenName) `\n -Surname $($User.Surname) `\n -DisplayName \"$($User.DisplayName)\" `\n -Path $($User.Path) `\n -City $($User.City) `\n -Company $($User.Company) `\n -State $($User.State) `\n -StreetAddress $($User.streetaddress) `\n -OfficePhone $($User.OfficePhone) `\n -MobliePhone $($User.MobilePhone) `\n -EmailAddress $($User.email) `\n -Title $($User.jobtitle) `\n -Department $($User.Department) `\n -Discription $($User.Discription) `\n }\n```\n<\/code><\/pre>\n
I am getting the error: \nSet-ADUser : Cannot bind parameter ‘Replace’. Cannot convert the “-Name” value of type “System.String” to type “System.Collections.Hashtable”. At C:\\Users\\mwaskosky\\Documents\\PowerShell PS1\\RMS\\UpdateAD User Accounts.ps1:16 char:13 + Set-ADUser -Replace ` + ~~~~~~~~ + CategoryInfo : InvalidArgument: ( [Set-ADUser], ParameterBindingException + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.ActiveDirectory.Management.Commands.SetADUser<\/p>\n
Any help would be much appreciated. What I am trying to do is to import just information into existing AD accounts.<\/p>\n
Set-ADUser : Cannot bind parameter 'Replace'. Cannot convert the \"-Name\" value of type \"System.String\" to type \"System.Collections.Hashtable\".\nAt C:\\Users\\mwaskosky\\Documents\\PowerShell PS1\\RMS\\UpdateAD User Accounts.ps1:16 char:13\n+ Set-ADUser -Replace `\n+ ~~~~~~~~\n + CategoryInfo : InvalidArgument: (:) [Set-ADUser], ParameterBindingException\n + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.ActiveDirectory.Management.Commands.SetADUser\n\n<\/code><\/pre>","upvoteCount":3,"datePublished":"2021-05-17T13:38:04.000Z","url":"https://community.spiceworks.com/t/import-ad-info-in-bulk/800061/1","author":{"@type":"Person","name":"mwaskosky","url":"https://community.spiceworks.com/u/mwaskosky"}},{"@type":"Answer","text":"
If you post code, please use the ‘Insert Code’ button. Please and thank you!<\/p>\n