Reputation: 61
Right up front, I want to say I have 0 knowledge of Powershell. I'm taking a chance to see if someone out there could help me.
I've been tasked to create a script that will look into a CSV file, run through each row, and based on the location of a User apply certain policies.
Example
CSV Contains
Name Number Location
ironman +123456789 USA
superboy +456987654 UK
Blackwidow 00789456798 Asia
Upvotes: 0
Views: 251
Reputation: 174845
Use a hashtable to create a "mapping" between different locations and their relevant policy names. Then all you need to do is check whether the location in question has an associated mapping and apply that:
$policyMappings = @{
'USA' = 'Policy 1'
'UK' = 'Policy 2'
'Asia' = 'Policy 3'
}
foreach($user in Import-Csv .\path\to\users.csv){
# fetch the identifying information already in the CSV row
$upn = $user.userprincipalname
$phone = $user.Phonenumber
# resolve the policy name
if($policyMappings.ContainsKey($user.Location)){
$policy = $policyMappings[$user.Location]
}
else {
# default to the global policy if no mapping is found
$policy = 'Global'
}
Set-CsUser -Identity $upn -EnterpriseVoiceEnabled $true
Set-CsPhoneNumberAssignment -Identity $upn -PhoneNumber $phone -PhoneNumberType DirectRouting
Grant-CsOnlineVoiceRoutingPolicy -PolicyName $policy -Identity $upn
Grant-CsTeamsCallingPolicy -PolicyName $policy -Identity $upn
}
Upvotes: 2