Quantcast
Channel: PowerShell General
Viewing all articles
Browse latest Browse all 10624

Office 365 Script binding problem

$
0
0

I am working on a script that doing auto licensing for Office 365 Users, 

here is the script

 

 

$password = ConvertTo-SecureString "password" -AsPlainText –Force $credential = New-Object System.Management.Automation.PsCredential("myusername",$password) $cred = Get-Credential -cred $credential Import-Module MSOnline Connect-MsolService -Credential $cred $msoExchangeURL = “https://ps.outlook.com/powershell/” $session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri $msoExchangeURL -Credential $cred -Authentication Basic -AllowRedirection $Users = Get-MsolUser -Maxresults 200000 -DomainName MyDomain.com –UnlicensedUsersOnly | Select UserPrincipalName $AccountSkuIdFACULTY = "MyDomain:STANDARDWOFFPACK_FACULTY" $AccountSkuIdSTUDENT = "MyDomain:STANDARDWOFFPACK_STUDENT" $UsageLocation = "US" $LicenseOptions = New-MsolLicenseOptions -AccountSkuId $AccountSkuId $LicenseOptionsFACULTY = New-MsolLicenseOptions -AccountSkuId $AccountSkuIdFACULTY -DisabledPlans SHAREPOINTWAC_EDU,MCOSTANDARD,SHAREPOINTSTANDARD_EDU $LicenseOptionsSTUDENT = New-MsolLicenseOptions -AccountSkuId $AccountSkuIdSTUDENT -DisabledPlans SHAREPOINTWAC_EDU,MCOSTANDARD,SHAREPOINTSTANDARD_EDU $Users | Where-Object {$_.CustomAttribute7 -like "S_*"}| ForEach-Object {Set-MsolUser -UserPrincipalName $_.UserPrincipalName -UsageLocation $UsageLocation Set-MsolUserLicense -UserPrincipalName $_.UserPrincipalName -AddLicenses $AccountSkuIdSTUDENT -LicenseOptions $LicenseOptionsSTUDENT }

 

 

when using this statement only it is working fine with me 

Get-MsolUser -Maxresults 200000 -DomainName education.qa –UnlicensedUsersOnly | Select UserPrincipalName

 

but when binding it with | Where-Object {$_.CustomAttribute7 -like "S_*"} as below it does not getting any result and if i changed the $_.CustomAttribute7 -like "S_*" to $_.CustomAttribute7 -like "*" it works but getting all results

$Users | Where-Object {$_.CustomAttribute7 -like "S_*"}| ForEach-Object {Set-MsolUser -UserPrincipalName $_.UserPrincipalName -UsageLocation $UsageLocation
Set-MsolUserLicense -UserPrincipalName $_.UserPrincipalName -AddLicenses $AccountSkuIdSTUDENT  -LicenseOptions $LicenseOptionsSTUDENT }

 

 

 

can anyone help me please to get this script working

 

 

 

 


Viewing all articles
Browse latest Browse all 10624

Trending Articles