Could someone out there please help me create a PowerShell script that does the following?<\/p>\n
Filter out users who are missing any of the following attributes and set accordingly.<\/p>\n
-SearchBase “OU=IT,DC=contoso,DC=com”<\/p>\n
“Office” set “SFO”
\n“City” set “San Francisco”
\n“State” set “CA”
\n“PostalCode” set “94105”
\n“Country” set “US”
\n“Company” set “Contoso”<\/p>\n
Also, set home directory to H: (\\server\\share%username%)<\/p>\n
Thanks,
\nSam<\/p>","upvoteCount":5,"answerCount":5,"datePublished":"2018-08-02T22:55:30.000Z","author":{"@type":"Person","name":"samuelcolt","url":"https://community.spiceworks.com/u/samuelcolt"},"suggestedAnswer":[{"@type":"Answer","text":"
Could someone out there please help me create a PowerShell script that does the following?<\/p>\n
Filter out users who are missing any of the following attributes and set accordingly.<\/p>\n
-SearchBase “OU=IT,DC=contoso,DC=com”<\/p>\n
“Office” set “SFO”
\n“City” set “San Francisco”
\n“State” set “CA”
\n“PostalCode” set “94105”
\n“Country” set “US”
\n“Company” set “Contoso”<\/p>\n
Also, set home directory to H: (\\server\\share%username%)<\/p>\n
Thanks,
\nSam<\/p>","upvoteCount":5,"datePublished":"2018-08-02T22:55:30.000Z","url":"https://community.spiceworks.com/t/powershell-ad-attributes-update-if-missing/665780/1","author":{"@type":"Person","name":"samuelcolt","url":"https://community.spiceworks.com/u/samuelcolt"}},{"@type":"Answer","text":"
What have you tried so far? Where are you stuck with that?<\/p>\n
Get-aduser should get you all the info.<\/p>\n
Set-aduser will set them for you.<\/p>\n
In between you want some evaluation. If/else would work<\/p>","upvoteCount":1,"datePublished":"2018-08-02T23:05:15.000Z","url":"https://community.spiceworks.com/t/powershell-ad-attributes-update-if-missing/665780/2","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"
Set home folder here https://community.spiceworks.com/scripts/show/4157-bulk-update-and-create-ad-users-home-folder-with-permissions<\/a><\/p>\n you can also select all users at once and paste home folder \\server\\share%username%<\/p>\n Try this not tested edited: tested<\/p>\n Or make it simpler.<\/p>\n If the properties are all the same for every user then just set them all again. So you can use Jiten’s code without the filter:<\/p>\n Use searchbase in the Get-ADUser to limit the change to the users that need the changes made, i.e. actual users and not service accounts.<\/p>","upvoteCount":2,"datePublished":"2018-08-03T07:23:52.000Z","url":"https://community.spiceworks.com/t/powershell-ad-attributes-update-if-missing/665780/4","author":{"@type":"Person","name":"psophos","url":"https://community.spiceworks.com/u/psophos"}},{"@type":"Answer","text":" What have you tried so far?<\/p>\n This is not a 'we do your homework/write your scripts for you site! \n```\n$params = @{\nOffice = 'SFO'\nCity = 'San Francisco'\nState ='CA'\nPostalCode ='94105'\nCountry = 'US'\nCompany= 'Contoso'\n}\n$Filter = {(office -notlike '*') -or (City -notlike '*') -or (state -notlike '*')-or (Postalcode -notlike '*') -or (country -notlike '*')-or(company -notlike '*')}\nget-aduser -Filter $filter -searchbase \"OU=contoso,DC=domain,dc=com\" |\nSet-ADUser @params\n```\n\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2018-08-03T01:47:54.000Z","url":"https://community.spiceworks.com/t/powershell-ad-attributes-update-if-missing/665780/3","author":{"@type":"Person","name":"jitensh","url":"https://community.spiceworks.com/u/jitensh"}},{"@type":"Answer","text":"
$params = @{\n Office = 'SFO'\n City = 'San Francisco'\n State = 'CA'\n PostalCode = '94105'\n Country = 'US'\n Company = 'Contoso'\n}\nget-aduser -Filter * -searchbase \"OU=contoso,DC=domain,dc=com\" | \n Set-ADUser @params\n<\/code><\/pre>\n
This site is best to solve specific problems you are having. So please, read the post at: PLEASE READ BEFORE POSTING! Read if you're new to the PowerShell forum!<\/a> Please try to solve the issue and ask for help where you are not succeeding.<\/p>","upvoteCount":1,"datePublished":"2018-08-03T09:46:29.000Z","url":"https://community.spiceworks.com/t/powershell-ad-attributes-update-if-missing/665780/5","author":{"@type":"Person","name":"DoctorDNS","url":"https://community.spiceworks.com/u/DoctorDNS"}}]}}