Link to home
Start Free TrialLog in
Avatar of Kopfan A
Kopfan A

asked on

Powershell Script on a CSV file

Powershell Script to change particular attribute

I have the following script :

import-module activedirectory
Get-ADUser -SearchBase "OU=exampme,OU=example,DC=example,DC=co,DC=uk" -Filter * | ForEach-Object {
      $User = [ADSI]"LDAP://$($_.DistinguishedName)"
         $User.psbase.invokeset("TerminalServicesProfilePath","C:\PooledVDIConfig\MandatoryProfile")
         $User.setinfo()
         }


The above works fine for all objects in an OU - I would like to run the above on a csv file which has First name and Last name

Any idea how this can be done?
Avatar of Michael Pfister
Michael Pfister
Flag of Germany image

Create csv containing

Givenname,Surname
user1GN,user1SN
user2GN,user2SN
:

Open in new window


import-module activedirectory
$Userlist = Import-CSV userlist.csv

foreach($User in $Userlist) {
Get-ADUser -SearchBase "OU=exampme,OU=example,DC=example,DC=co,DC=uk" -Filter   {GivenName -eq  "$($User.Givenname)" -and Surname -eq "$($User.Surname)"}
 | ForEach-Object {
      $User = [ADSI]"LDAP://$($_.DistinguishedName)"
         $User.psbase.invokeset("TerminalServicesProfilePath","C:\PooledVDIConfig\MandatoryProfile")
         $User.setinfo()
         }
 }

Open in new window

Avatar of Kopfan A
Kopfan A

ASKER

Thank you Michael, very helpful.

In regards to the line where it looks in the OU - we have multiple 'user OU's' that these listed users may be in - any idea how that will work - for it to search more than 1 OU?

Regards,
Kopfan
ASKER CERTIFIED SOLUTION
Avatar of Michael Pfister
Michael Pfister
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
No feedback from asker, solution should work