Skip to content

Set-TenantServicePrincipal

SharePoint Online: Enables or disables the service principal

#Requires -Version 5.1
#Requires -Modules Microsoft.Online.SharePoint.PowerShell

[CmdletBinding()]
Param(
    [Parameter(Mandatory = $true)]
    [bool]$Disable
)

Process {
    try {
        if ($Disable -eq $false) {
            $result = Enable-SPOTenantServicePrincipal -Confirm:$false -ErrorAction Stop | Select-Object *
        }
        else {
            $result = Disable-SPOTenantServicePrincipal -Confirm:$false -ErrorAction Stop | Select-Object *
        }
        if ($null -ne $result) { foreach ($item in $result) { $item | Add-Member -NotePropertyName Timestamp -NotePropertyValue (Get-Date -Format "yyyy-MM-dd HH:mm:ss") -PassThru -Force } }
    }
    catch { throw }
}

Set to $true to disable, $false to enable the service principal

An interactive directory of PowerShell scripts.