mlunn82 Posted March 27, 2017 Posted March 27, 2017 Hi, Was seeing if there is anyone that could help with power shell scripts. I have ad connect enable and want a way that if a staff member is in a security group called staff that they would get the office 365 education for faculty and if a student is in the student group they would get the office 365 education for students licence. i have been having a play but unable to get it to work. Hope someone would be kind enough to help or share. Thanks Mark Office 365 Education for facultyOffice 365 Education for facultyOffice 365 Education for faculty
Norphy Posted March 27, 2017 Posted March 27, 2017 You can use the Get-ADUser cmdlet to get their group membership get-aduser -identity (user) -properties memberof
mlunn82 Posted March 27, 2017 Author Posted March 27, 2017 Hi Norphy, Thanks for the reply i was seeing if their is a script that would add uses in certain AD groups to the correct office 365 licence so i couldn't have to do it manually. I have been looking and trying but can't get it to work Thanks You can use the Get-ADUser cmdlet to get their group membership get-aduser -identity (user) -properties memberof
Norphy Posted March 27, 2017 Posted March 27, 2017 (edited) DISCLAIMER: I've not tested this. I don't know if it will work (it should) but I'm not responsible if this burns your cattle and steals your farm. Use at your own risk. This script requires the AD PowerShell and the MSOnline Powershell modules to be installed. Something like this should work: #MSOL Credentials $O365UN = "[email protected]@O365Domain.onmicrosoft.com" $O365PW = "PasswordForAboveAccount" $O365PW_SS = ConvertTo-SecureString -String $O365PW -AsPlainText -Force $O365Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $O365UN, $O365PW_SS #Connect to MSOL Service Connect-MsolService -Credential $O365Credential #Get all AD Users $ADUsers = Get-ADUser -Filter {enabled -eq $true} #cycle through users $ADUsers | foreach { #get user's group membership $GroupMembership = $(Get-ADUser -Identity $_.name -Properties memberof).memberof #if staff user if ($GroupMembership -match "staff") { #set location to GB get-msoluser -UserPrincipalName $_.userprincipalname | Set-MsolUser -UsageLocation GB #Assign License get-msoluser -UserPrincipalName $_.userprincipalname | Set-MsolUserLicense -AddLicenses "NameOfStaffLicenseHere" } #if student user if ($GroupMembership -match "students") { #set location to GB get-msoluser -UserPrincipalName $_.userprincipalname | Set-MsolUser -UsageLocation GB #Assign license get-msoluser -UserPrincipalName $_.userprincipalname | Set-MsolUserLicense -AddLicenses "NameOfStudentLicenseHere" } } Some tweaking will be required, you'll have to change the group names and license names Edited March 27, 2017 by Norphy 1
mlunn82 Posted March 27, 2017 Author Posted March 27, 2017 Hi Norphy, I will have a look and play with the script on a few test users and groups. Thanks Mark DISCLAIMER: I've not tested this. I don't know if it will work (it should) but I'm not responsible if this burns your cattle and steals your farm. Use at your own risk. This script requires the AD PowerShell and the MSOnline Powershell modules to be installed. Something like this should work: #MSOL Credentials $O365UN = "[email protected]@O365Domain.onmicrosoft.com" $O365PW = "PasswordForAboveAccount" $O365PW_SS = ConvertTo-SecureString -String $O365PW -AsPlainText -Force $O365Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $O365UN, $O365PW_SS #Connect to MSOL Service Connect-MsolService -Credential $O365Credential #Get all AD Users $ADUsers = Get-ADUser -Filter {enabled -eq $true} #cycle through users $ADUsers | foreach { #get user's group membership $GroupMembership = $(Get-ADUser -Identity $_.name -Properties memberof).memberof #if staff user if ($GroupMembership -match "staff") { #set location to GB get-msoluser -UserPrincipalName $_.userprincipalname | Set-MsolUser -UsageLocation GB #Assign License get-msoluser -UserPrincipalName $_.userprincipalname | Set-MsolUserLicense -AddLicenses "NameOfStaffLicenseHere" } #if student user if ($GroupMembership -match "students") { #set location to GB get-msoluser -UserPrincipalName $_.userprincipalname | Set-MsolUser -UsageLocation GB #Assign license get-msoluser -UserPrincipalName $_.userprincipalname | Set-MsolUserLicense -AddLicenses "NameOfStudentLicenseHere" } } Some tweaking will be required, you'll have to change the group names and license names
mlunn82 Posted March 29, 2017 Author Posted March 29, 2017 Hi Norphy, I have been having a play but getting stuck when runnign the scrips. I get a message saying - cmdlet ForEach-Object at command pipeline position 1Supply values for the following parameters:Process[0]: Any ideas please? Thanks Mark 1
Norphy Posted March 29, 2017 Posted March 29, 2017 Sorry, minor bug. Move the brace after ForEach to the same line as foreach. It should then start working. 1
mlunn82 Posted March 29, 2017 Author Posted March 29, 2017 Hope you don't mind have sent you a message as i think i am being stupid with this code as been looking at it for ages. Thanks Mark
NetworkNinja Posted March 29, 2017 Posted March 29, 2017 I have created the following code which assigns licenses for all users in office 365. This works for me and you can use at your own risk. #1. STEP#USE ADMINISTRATOR CREDENTIALS [email protected] FOR EXAMPLE$UserCredential = Get-Credential$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection$Office365PS = Import-PSSession $Session #2. STEP#USE ADMINISTRATOR CREDENTIALS [email protected] FOR EXAMPLEConnect-MsolService #3. STEP#FIND OUT ALL THE LICENCESGet-MsolAccountSku #4. STEP#SWITCH THE LICENSES$OldActSku = get-MsolAccountSku| where-object {$_.AccountSkuId -eq "SCHOOLNAMEco:EXCHANGESTANDARD_STUDENT"}$NewActSku = get-MsolAccountSku| where-object {$_.AccountSkuId -eq "SCHOOLNAMEco:STANDARDWOFFPACK_IW_STUDENT"}get-msoluser -all | where-object {$_.Licenses[0].AccountSkuId -eq $OldActSku.AccountSkuId} | Set-MsolUserLicense -RemoveLicenses $OldActSku.AccountSkuId -AddLicenses $NewActSku.AccountSkuId #5. STEP#CLOSE THE SESSION!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!VERY IMPORTANT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Remove-PSSession $Session 1
mlunn82 Posted March 29, 2017 Author Posted March 29, 2017 Norphy, You are great. Thank you for this :-) i have only tested it little and seems to work. I am goign to test to see if it will also do the Microsoft classroom licence too. Sorry, minor bug. Move the brace after ForEach to the same line as foreach. It should then start working.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now