Forum Discussion
Lucky1998
Jul 17, 2020Copper Contributor
Correct my powershell please. Set-MsolUserLicence
Hey Guys relatively new to Powershell but creating a termination script. all working well and good apart from this section to remove 365 licences. This is what i want to be able to do but doesn't...
- Jul 17, 2020
Oh sorry, I thought it was the other way around, my bad. So basically, you need to get just the UPN value, not the object. Either use
$upn.UserPrincipalName
or set the value like this:
$upn = Get-AdUser blabla | select -ExpandProperty UserPrincipalName
VasilMichev
Jul 17, 2020MVP
Any particular error? It looks OK to me.
Lucky1998
Jul 17, 2020Copper Contributor
tried several variations.
When i type in the UPN manually like above it works fine but when trying to get it by the Get-AdUser command it doesn't like it. Recognises its there though.
get-MsolUser : User Not Found. User: @{UserPrincipalName=365.test1@domain.com.au}.
At line:2 char:2
+ (get-MsolUser -UserPrincipalName $upn).licenses.AccountSkuId |
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [Get-MsolUser], MicrosoftOnlineException
+ FullyQualifiedErrorId : Microsoft.Online.Administration.Automation.UserNotFoundException,Microsoft.Online.Administration.Automation.GetUser
- VasilMichevJul 17, 2020MVP
Oh sorry, I thought it was the other way around, my bad. So basically, you need to get just the UPN value, not the object. Either use
$upn.UserPrincipalName
or set the value like this:
$upn = Get-AdUser blabla | select -ExpandProperty UserPrincipalName
- Lucky1998Jul 21, 2020Copper Contributor