functions/general/Deactivate-AzurePIMConfiguration.ps1
function Deactivate-AzurePIMConfiguration { <# .SYNOPSIS Deactivate already AzurePIM configuration. .DESCRIPTION Deactivate configurations you don't want to apply to your tenant. Only activated configuration will be considered when testing or invoking configurations. .PARAMETER Name Provide the name of the AzurePIM configuration to deactivate. .PARAMETER Path Provide a path to the AzurePIM configuration to deactivate. .PARAMETER All Deactivate all configurations currently activated. .EXAMPLE PS> Deactivate-AzurePIMConfiguration -Path "C:\Temp\SomeConfiguration" Deactivates the configuration in path C:\Temp\SomeConfiguration. .EXAMPLE PS> Deactivate-AzurePIMConfiguration -Name "SomeConfiguration" Deactivates the configuration with name "SomeConfiguration". .EXAMPLE PS> Deactivate-AzurePIMConfiguration -All Deactivates all configurations. #> [CmdletBinding(DefaultParameterSetName = 'Name')] Param ( [Parameter(Mandatory = $true, ParameterSetName = "Name")] [string] $Name, [Parameter(Mandatory = $true, ParameterSetName = "Path")] [string] $Path, [Parameter(ParameterSetName = "All")] [switch] $All ) begin { if ($All) { return } if ($PSCmdlet.ParameterSetName -eq "Path") { if ($Path -notmatch ".*configuration.json$") { $configurationFilePath = "{0}\configuration.json" -f $Path } if (!(Test-Path $configurationFilePath)) { Stop-PSFFunction -String "AzurePIM.ConfigurationFileNotFound" -StringValues $configurationFilePath return } $configurationFilePath = Resolve-PSFPath -Provider FileSystem -Path $configurationFilePath -SingleItem $Name = (Get-Content $configurationFilePath | ConvertFrom-Json -ErrorAction Stop).Name } if ($script:activatedConfigurations.Name -notcontains $Name) { Stop-PSFFunction -String "Deactivate-AzurePIMConfiguration.NotActivated" -StringValues $Name return } } process { if (Test-PSFFunctionInterrupt) { return } if ($All) { Write-PSFMessage -Level Host -String "Deactivate-AzurePIMConfiguration.DeactivatingAll" -NoNewLine $script:activatedConfigurations = @() $script:desiredConfiguration = @{} Write-PSFHostColor -String ' [<c="green">DONE</c>]' } else { Write-PSFMessage -Level Host -String "Deactivate-AzurePIMConfiguration.Deactivating" -StringValues $Name -NoNewLine $script:activatedConfigurations = @($script:activatedConfigurations | Where-Object {$_.Name -ne $Name}) Write-PSFHostColor -String ' [<c="green">DONE</c>]' } } end { Load-AzurePIMConfiguration } } |