Created
January 15, 2015 01:33
-
-
Save mattmcnabb/ba14f6e7f8df715b325f to your computer and use it in GitHub Desktop.
Add -Whatif to MSOnline Cmdlets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function Set-MsolUserLicense | |
{ | |
[CmdletBinding(DefaultParameterSetName='SetUserLicenses__0', SupportsShouldProcess=$true)] | |
param | |
( | |
[Parameter(ParameterSetName='SetUserLicenses__0', Mandatory=$true, ValueFromPipelineByPropertyName=$true)] | |
[guid] | |
$ObjectId, | |
[Parameter(ParameterSetName='SetUserLicensesByUpn__0', ValueFromPipelineByPropertyName=$true)] | |
[Parameter(ParameterSetName='SetUserLicenses__0', ValueFromPipelineByPropertyName=$true)] | |
[AllowEmptyCollection()] | |
[Microsoft.Online.Administration.LicenseOption[]] | |
$LicenseOptions, | |
[Parameter(ParameterSetName='SetUserLicensesByUpn__0', Mandatory=$true, ValueFromPipelineByPropertyName=$true)] | |
[string] | |
$UserPrincipalName, | |
[Parameter(ValueFromPipelineByPropertyName=$true)] | |
[string[]] | |
$AddLicenses, | |
[Parameter(ValueFromPipelineByPropertyName=$true)] | |
[string[]] | |
$RemoveLicenses, | |
[Parameter(ValueFromPipelineByPropertyName=$true)] | |
[System.Nullable[guid]] | |
$TenantId | |
) | |
process | |
{ | |
switch ($PSCmdlet.ParameterSetName) | |
{ | |
'SetUserLicenses__0' {$Processor = $ObjectId} | |
'SetUserLicensesByUpn__0' {$Processor = $UserPrincipalName} | |
} | |
if ($PSCmdlet.ShouldProcess($Processor)) | |
{ | |
$wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Set-MsolUserLicense', [System.Management.Automation.CommandTypes]::Cmdlet) | |
$scriptCmd = {& $wrappedCmd @PSBoundParameters} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment