Skip to content

Instantly share code, notes, and snippets.

@mattmcnabb
Created January 15, 2015 01:33
Show Gist options
  • Save mattmcnabb/ba14f6e7f8df715b325f to your computer and use it in GitHub Desktop.
Save mattmcnabb/ba14f6e7f8df715b325f to your computer and use it in GitHub Desktop.
Add -Whatif to MSOnline Cmdlets
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