I've been working on creating a new script to further automate our user on-boarding process and I've run into something of a wall. I want to be able to populate different aspects of a new user account with address details, move to a specific OU, etc. based on that users physical location. So the way this works is I'll either get a csv file from HR with the users location information but i also have code i can uncomment to prompt for the same details for someone running the script without the csv file.
For address details, I've got a csv file: office,streetaddress,city,state,zip. So based on the office a user will work from, I want to populate variables based on that location. So I am trying to do something like this:
$addressFile = "\\path-to-csv\addresses.csv"
$office = "Okemos"
$username='user@domain.com'
Import-Csv $addressFile|? Office -eq $office | Where-Object {
{
$streetaddress=$addressFile.streetaddress
$city=$addressfile.city
$state=$addressFile.stateorprovence
$zipcode=$addressFile.postalcode
$country=$addressFile.country
set-aduser -identity $username -replace @{"streetAddress"=$streetaddress}
set-aduser -identity $username -replace @{"postalcode"=$zipcode}
set-aduser -identity $username -replace @{"Country"=$Country}
set-aduser -identity $username -city $addressfile.city
set-aduser -identity $username -replace @{"stateorprovence"=$state}
}
}
And what's happening is I'm not getting those variables populated with any data.
I want to do the same thing with the OU the account is placed in as well. Same principal, just different data. The OU is based on department and location. So I created a csv with all possible combinations of office and department and their associated OU. For example, if a user will be in St. Louis Sales, the OU the account goes in is for that specific office/department. The reason for this is mostly application of policy.
It is entirely possible that I am approaching this wrong and shouldn't be using a csv but rather excel docs or possibly even a sql db (though I feel that's overkill for something like this), however, I'd appreciate any guidance on this please. Once i have the theory down for what I'm wanting to accomplish i can take it from there.
Thanks all.
For address details, I've got a csv file: office,streetaddress,city,state,zip. So based on the office a user will work from, I want to populate variables based on that location. So I am trying to do something like this:
$addressFile = "\\path-to-csv\addresses.csv"
$office = "Okemos"
$username='user@domain.com'
Import-Csv $addressFile|? Office -eq $office | Where-Object {
{
$streetaddress=$addressFile.streetaddress
$city=$addressfile.city
$state=$addressFile.stateorprovence
$zipcode=$addressFile.postalcode
$country=$addressFile.country
set-aduser -identity $username -replace @{"streetAddress"=$streetaddress}
set-aduser -identity $username -replace @{"postalcode"=$zipcode}
set-aduser -identity $username -replace @{"Country"=$Country}
set-aduser -identity $username -city $addressfile.city
set-aduser -identity $username -replace @{"stateorprovence"=$state}
}
}
And what's happening is I'm not getting those variables populated with any data.
I want to do the same thing with the OU the account is placed in as well. Same principal, just different data. The OU is based on department and location. So I created a csv with all possible combinations of office and department and their associated OU. For example, if a user will be in St. Louis Sales, the OU the account goes in is for that specific office/department. The reason for this is mostly application of policy.
It is entirely possible that I am approaching this wrong and shouldn't be using a csv but rather excel docs or possibly even a sql db (though I feel that's overkill for something like this), however, I'd appreciate any guidance on this please. Once i have the theory down for what I'm wanting to accomplish i can take it from there.
Thanks all.