Microsoft 365: Konfiguracja Usługi online do korzystania z usługi Azure Rights Management

Poniższe sekcje ułatwiają konfigurowanie usług Exchange Online, Microsoft SharePoint i Microsoft OneDrive do korzystania z usługi Azure Rights Management z usługi Azure Information Protection.

Exchange Online: konfiguracja usługi IRM

Aby uzyskać informacje na temat sposobu działania usługi Exchange Online z usługą Azure Rights Management, zobacz sekcję Exchange Online i Exchange Server w temacie How aplikacja pakietu Office lications and services support Azure Rights Management (Jak aplikacja pakietu Office lications and services support Azure Rights Management).

Usługa Exchange Online może być już włączona do korzystania z usługi Azure Rights Management. Aby to sprawdzić, uruchom następujące polecenia:

  1. Jeśli po raz pierwszy użyto programu Windows PowerShell dla usługi Exchange Online na komputerze, należy skonfigurować program Windows PowerShell do uruchamiania podpisanych skryptów. Uruchom sesję programu Windows PowerShell przy użyciu opcji Uruchom jako administrator , a następnie wpisz:

    Set-ExecutionPolicy RemoteSigned
    

    Naciśnij klawisz Y , aby potwierdzić.

  2. W sesji programu Windows PowerShell zaloguj się do usługi Exchange Online przy użyciu konta, które jest włączone na potrzeby dostępu zdalnego powłoki. Domyślnie wszystkie konta utworzone w usłudze Exchange Online są włączone na potrzeby dostępu zdalnego powłoki, ale można je wyłączyć (i włączyć) za pomocą polecenia Set-UserIdentity><-RemotePowerShellEnabled.

    Aby się zalogować, najpierw wpisz:

    Connect-ExchangeOnline
    

    Następnie w oknie dialogowym Żądanie poświadczeń programu Windows PowerShell podaj nazwę użytkownika i hasło platformy Microsoft 365.

  3. Uruchom polecenie Get-IRMConfiguration, aby wyświetlić konfigurację usługi Exchange Online dla usługi ochrony:

    Get-IRMConfiguration
    

    Z danych wyjściowych znajdź wartość AzureRMSLicensingEnabled :

    • Jeśli parametr AzureRMSLicensingEnabled ma wartość True, usługa Exchange Online jest już włączona dla usługi Azure Rights Management.

    • Jeśli parametr AzureRMSLicensingEnabled ma wartość False, uruchom następujące polecenie, aby włączyć usługę Exchange Online dla usługi Azure Rights Management: Set-IRMConfiguration -AzureRMSLicensingEnabled $true

  4. Aby sprawdzić, czy usługa Exchange Online została pomyślnie skonfigurowana, uruchom następujące polecenie:

    Test-IRMConfiguration -Sender <user email address>
    

    Na przykład: Test-IRMConfiguration -Sender adams@contoso.com

    To polecenie uruchamia serię testów, które obejmują weryfikowanie łączności z usługą, pobieranie konfiguracji, pobieranie identyfikatorów URI, licencji i wszystkich szablonów. W sesji programu Windows PowerShell zostaną wyświetlone wyniki każdego elementu i na końcu, jeśli wszystko przejdzie następujące testy: OGÓLNY WYNIK: PASS

Po włączeniu usługi Exchange Online do korzystania z usługi Azure Rights Management można skonfigurować następujące funkcje:

  • Szyfrowanie komunikatów usługi Purview przy użyciu reguł przepływu poczty.

  • Szyfrowanie przy użyciu zasad ochrony przed utratą danych (DLP).

  • Etykiety poufności z szyfrowaniem przy użyciu programu Outlook w sieci Web, mac, iOS i Android.

  • Zasady automatycznego etykietowania w programie Exchange w celu zastosowania etykiet poufności z szyfrowaniem do wiadomości e-mail i chronionych wiadomości poczty głosowej.

Program SharePoint w usługach Microsoft 365 i OneDrive: konfiguracja usługi IRM

Aby uzyskać informacje na temat sposobu działania usługi IRM programu SharePoint z usługą Azure Rights Management, zobacz SharePoint w usługach Microsoft 365 i SharePoint Server w sekcji Ochrona usługi Rights Management w tej dokumentacji.

Aby skonfigurować program SharePoint w usługach Microsoft 365 i OneDrive do obsługi usługi Azure Rights Management, należy najpierw włączyć usługę zarządzania prawami do informacji (IRM) dla programu SharePoint przy użyciu centrum administracyjnego programu SharePoint. Następnie właściciele witryn mogą chronić listy i biblioteki dokumentów programu SharePoint, a użytkownicy mogą chronić bibliotekę usługi OneDrive w taki sposób, aby dokumenty, które zostały tam zapisane i udostępnione innym osobom, były automatycznie chronione przez usługę Azure Rights Management.

Uwaga

Biblioteki chronione za pomocą usługi IRM dla programu SharePoint na platformie Microsoft 365 i w usłudze OneDrive wymagają najnowszej wersji nowego klienta synchronizacja usługi OneDrive (OneDrive.exe) oraz wersji klienta usługi RMS z Centrum pobierania Microsoft. Zainstaluj tę wersję klienta usługi RMS, nawet jeśli zainstalowano klienta usługi Azure Information Protection. Aby uzyskać więcej informacji na temat tego scenariusza wdrażania, zobacz Wdrażanie nowego klienta synchronizacja usługi OneDrive w środowisku przedsiębiorstwa.

Aby włączyć usługę zarządzania prawami do informacji (IRM) dla programu SharePoint, zapoznaj się z następującymi instrukcjami w dokumentacji pakietu Office:

Ta konfiguracja jest wykonywana przez administratora platformy Microsoft 365.

Konfigurowanie usługi IRM dla bibliotek i list

Po włączeniu usługi IRM dla programu SharePoint właściciele witryn mogą chronić biblioteki i listy dokumentów programu SharePoint przez funkcję IRM. Aby uzyskać instrukcje, zobacz następujące informacje w witrynie internetowej pakietu Office:

Ta konfiguracja jest wykonywana przez administratora witryny programu SharePoint.

Konfigurowanie usługi IRM dla usługi OneDrive

Po włączeniu usługi IRM dla programu SharePoint można skonfigurować bibliotekę dokumentów usługi OneDrive użytkowników lub poszczególne foldery na potrzeby ochrony usługi Rights Management. Użytkownicy mogą skonfigurować to dla siebie przy użyciu witryny internetowej usługi OneDrive. Mimo że administratorzy nie mogą skonfigurować tej ochrony dla nich przy użyciu centrum administracyjnego programu SharePoint, można to zrobić przy użyciu programu Windows PowerShell.

Uwaga

Aby uzyskać więcej informacji na temat konfigurowania usługi OneDrive, zobacz dokumentację usługi OneDrive .

Konfiguracja dla użytkowników

Przekaż użytkownikom następujące instrukcje, aby mogli skonfigurować usługę OneDrive w celu ochrony plików biznesowych.

  1. Zaloguj się do platformy Microsoft 365 przy użyciu konta służbowego i przejdź do witryny internetowej usługi OneDrive.

  2. W okienku nawigacji u dołu wybierz pozycję Powróć do klasycznej usługi OneDrive.

  3. Wybierz ikonę Ustawienia. W okienku Ustawienia, jeśli wstążkama wartość Wyłączone, wybierz to ustawienie, aby włączyć wstążkę.

  4. Aby skonfigurować wszystkie pliki usługi OneDrive do ochrony, wybierz kartę BIBLIOTEKA na wstążce, a następnie wybierz pozycję Biblioteka Ustawienia.

  5. Na stronie Dokumenty > Ustawienia w sekcji Uprawnienia i zarządzanie wybierz pozycję Zarządzanie prawami do informacji.

  6. Na stronie Zarządzanie prawami do informacji Ustawienia zaznacz pole wyboru Ogranicz uprawnienia do tej biblioteki podczas pobierania. Określ wybraną nazwę i opis uprawnień, a opcjonalnie kliknij przycisk POKAŻ OPCJE , aby skonfigurować opcjonalne konfiguracje, a następnie kliknij przycisk OK.

Ponieważ ta konfiguracja opiera się na użytkownikach, a nie na administratorach, aby chronić swoje pliki w usłudze OneDrive, należy edukować użytkowników o korzyściach związanych z ochroną plików i sposobami ich wykonywania. Na przykład wyjaśnij, że gdy udostępniają dokument z usługi OneDrive, tylko osoby, które autoryzują, mogą uzyskać do niego dostęp z wszelkimi skonfigurowanymi ograniczeniami, nawet jeśli nazwa pliku zostanie zmieniona i skopiowana w innym miejscu.

Konfiguracja dla administratorów

Chociaż nie można skonfigurować usługi IRM dla usługi OneDrive użytkowników przy użyciu centrum administracyjnego programu SharePoint, można to zrobić przy użyciu programu Windows PowerShell. Aby włączyć usługę IRM dla tych bibliotek, wykonaj następujące kroki:

  1. Pobierz i zainstaluj zestaw SDK składników klienta programu SharePoint.

  2. Pobierz i zainstaluj powłokę zarządzania programu SharePoint.

  3. Skopiuj zawartość następującego skryptu i nadaj plikowi nazwę Set-IRMOnOneDriveForBusiness.ps1 na komputerze.

    **Zastrzeżenie**: ten przykładowy skrypt nie jest obsługiwany w żadnym standardowym programie pomocy technicznej ani usłudze firmy Microsoft. Ten przykładowy skrypt jest dostarczany jako bez gwarancji jakiegokolwiek rodzaju.

    # Requires Windows PowerShell version 3
    
    <#
      Description:
    
        Configures IRM policy settings for OneDrive and can also be used for SharePoint libraries and lists
    
     Script Installation Requirements:
    
       SharePoint Client Components SDK
       https://www.microsoft.com/download/details.aspx?id=42038
    
       SharePoint Management Shell
       https://www.microsoft.com/download/details.aspx?id=35588
    
    ======
    #>
    
    # URL will be in the format https://<tenant-name>-admin.sharepoint.com
    $sharepointAdminCenterUrl = "https://contoso-admin.sharepoint.com"
    
    $tenantAdmin = "admin@contoso.com"
    
    $webUrls = @("https://contoso-my.sharepoint.com/personal/user1_contoso_com",
                 "https://contoso-my.sharepoint.com/personal/user2_contoso_com",
                 "https://contoso-my.sharepoint.com/personal/user3_contoso_com")
    
    <# As an alternative to specifying the URLs as an array, you can import them from a CSV file (no header, single value per row).
       Then, use: $webUrls = Get-Content -Path "File_path_and_name.csv"
    
    #>
    
    $listTitle = "Documents"
    
    function Load-SharePointOnlineClientComponentAssemblies
    {
        [cmdletbinding()]
        param()
    
        process
        {
            # assembly location: C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI
            try
            {
                Write-Verbose "Loading Assembly: Microsoft.Office.Client.Policy, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
                [System.Reflection.Assembly]::Load("Microsoft.Office.Client.Policy, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") | Out-Null
    
                Write-Verbose "Loading Assembly: Microsoft.Office.Client.TranslationServices, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
                [System.Reflection.Assembly]::Load("Microsoft.Office.Client.TranslationServices, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") | Out-Null
    
                Write-Verbose "Loading Assembly: Microsoft.SharePoint.Client, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
                [System.Reflection.Assembly]::Load("Microsoft.SharePoint.Client, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") | Out-Null
    
                Write-Verbose "Loading Assembly: Microsoft.SharePoint.Client.DocumentManagement, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
                [System.Reflection.Assembly]::Load("Microsoft.SharePoint.Client.DocumentManagement, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") | Out-Null
    
                Write-Verbose "Loading Assembly: Microsoft.SharePoint.Client.Publishing, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
                [System.Reflection.Assembly]::Load("Microsoft.SharePoint.Client.Publishing, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") | Out-Null
    
                Write-Verbose "Loading Assembly: Microsoft.SharePoint.Client.Runtime, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
                [System.Reflection.Assembly]::Load("Microsoft.SharePoint.Client.Runtime, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") | Out-Null
    
                Write-Verbose "Loading Assembly: Microsoft.SharePoint.Client.Search.Applications, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
                [System.Reflection.Assembly]::Load("Microsoft.SharePoint.Client.Search.Applications, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") | Out-Null
    
                Write-Verbose "Loading Assembly: Microsoft.SharePoint.Client.Search, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
                [System.Reflection.Assembly]::Load("Microsoft.SharePoint.Client.Search, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") | Out-Null
    
                Write-Verbose "Loading Assembly: Microsoft.SharePoint.Client.Taxonomy, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
                [System.Reflection.Assembly]::Load("Microsoft.SharePoint.Client.Taxonomy, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") | Out-Null
    
                Write-Verbose "Loading Assembly: Microsoft.SharePoint.Client.UserProfiles, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
                [System.Reflection.Assembly]::Load("Microsoft.SharePoint.Client.UserProfiles, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") | Out-Null
    
                return $true
            }
            catch
            {
                if($_.Exception.Message -match "Could not load file or assembly")
                {
                    Write-Error -Message "Unable to load the SharePoint Server 2013 Client Components.`nDownload Location: https://www.microsoft.com/download/details.aspx?id=42038"
                }
                else
                {
                    Write-Error -Exception $_.Exception
                }
                return $false
            }
        }
    }
    
    function Load-SharePointOnlineModule
    {
        [cmdletbinding()]
        param()
    
        process
        {
            do
            {
                # Installation location: C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell
                $spoModule = Get-Module -Name Microsoft.Online.SharePoint.PowerShell -ErrorAction SilentlyContinue
    
                if(-not $spoModule)
                {
                    try
                    {
                        Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
                        return $true
                    }
                    catch
                    {
                        if($_.Exception.Message -match "Could not load file or assembly")
                        {
                            Write-Error -Message "Unable to load the SharePoint Online Management Shell.`nDownload Location: https://www.microsoft.com/download/details.aspx?id=35588"
                        }
                        else
                        {
                            Write-Error -Exception $_.Exception
                        }
                        return $false
                    }
                }
                else
                {
                    return $true
                }
            }
            while(-not $spoModule)
        }
    }
    
    function Set-IrmConfiguration
    {
        [cmdletbinding()]
        param(
            [parameter(Mandatory=$true)][Microsoft.SharePoint.Client.List]$List,
            [parameter(Mandatory=$true)][string]$PolicyTitle,
            [parameter(Mandatory=$true)][string]$PolicyDescription,
            [parameter(Mandatory=$false)][switch]$IrmReject,
            [parameter(Mandatory=$false)][DateTime]$ProtectionExpirationDate,
            [parameter(Mandatory=$false)][switch]$DisableDocumentBrowserView,
            [parameter(Mandatory=$false)][switch]$AllowPrint,
            [parameter(Mandatory=$false)][switch]$AllowScript,
            [parameter(Mandatory=$false)][switch]$AllowWriteCopy,
            [parameter(Mandatory=$false)][int]$DocumentAccessExpireDays,
            [parameter(Mandatory=$false)][int]$LicenseCacheExpireDays,
            [parameter(Mandatory=$false)][string]$GroupName
        )
    
        process
        {
            Write-Verbose "Applying IRM Configuration on '$($List.Title)'"
    
            # reset the value to the default settings
            $list.InformationRightsManagementSettings.Reset()
    
            $list.IrmEnabled = $true
    
            # IRM Policy title and description
    
                $list.InformationRightsManagementSettings.PolicyTitle       = $PolicyTitle
                $list.InformationRightsManagementSettings.PolicyDescription = $PolicyDescription
    
            # Set additional IRM library settings
    
                # Do not allow users to upload documents that do not support IRM
                $list.IrmReject = $IrmReject.IsPresent
    
                $parsedDate = Get-Date
                if([DateTime]::TryParse($ProtectionExpirationDate, [ref]$parsedDate))
                {
                    # Stop restricting access to the library at <date>
                    $list.IrmExpire = $true
                    $list.InformationRightsManagementSettings.DocumentLibraryProtectionExpireDate = $ProtectionExpirationDate
                }
    
                # Prevent opening documents in the browser for this Document Library
                $list.InformationRightsManagementSettings.DisableDocumentBrowserView = $DisableDocumentBrowserView.IsPresent
    
            # Configure document access rights
    
                # Allow viewers to print
                $list.InformationRightsManagementSettings.AllowPrint = $AllowPrint.IsPresent
    
                # Allow viewers to run script and screen reader to function on downloaded documents
                $list.InformationRightsManagementSettings.AllowScript = $AllowScript.IsPresent
    
                # Allow viewers to write on a copy of the downloaded document
                $list.InformationRightsManagementSettings.AllowWriteCopy = $AllowWriteCopy.IsPresent
    
                if($DocumentAccessExpireDays)
                {
                    # After download, document access rights will expire after these number of days (1-365)
                    $list.InformationRightsManagementSettings.EnableDocumentAccessExpire = $true
                    $list.InformationRightsManagementSettings.DocumentAccessExpireDays   = $DocumentAccessExpireDays
                }
    
            # Set group protection and credentials interval
    
                if($LicenseCacheExpireDays)
                {
                    # Users must verify their credentials using this interval (days)
                    $list.InformationRightsManagementSettings.EnableLicenseCacheExpire = $true
                    $list.InformationRightsManagementSettings.LicenseCacheExpireDays   = $LicenseCacheExpireDays
                }
    
                if($GroupName)
                {
                    # Allow group protection. Default group:
                    $list.InformationRightsManagementSettings.EnableGroupProtection = $true
                    $list.InformationRightsManagementSettings.GroupName             = $GroupName
                }
        }
        end
        {
            if($list)
            {
                Write-Verbose "Committing IRM configuration settings on '$($list.Title)'"
                $list.InformationRightsManagementSettings.Update()
                $list.Update()
                $script:clientContext.Load($list)
                $script:clientContext.ExecuteQuery()
            }
        }
    }
    
    function Get-CredentialFromCredentialCache
    {
        [cmdletbinding()]
        param([string]$CredentialName)
    
        #if( Test-Path variable:\global:CredentialCache )
        if( Get-Variable O365TenantAdminCredentialCache -Scope Global -ErrorAction SilentlyContinue )
        {
            if($global:O365TenantAdminCredentialCache.ContainsKey($CredentialName))
            {
                Write-Verbose "Credential Cache Hit: $CredentialName"
                return $global:O365TenantAdminCredentialCache[$CredentialName]
            }
        }
        Write-Verbose "Credential Cache Miss: $CredentialName"
        return $null
    }
    
    function Add-CredentialToCredentialCache
    {
        [cmdletbinding()]
        param([System.Management.Automation.PSCredential]$Credential)
    
        if(-not (Get-Variable CredentialCache -Scope Global -ErrorAction SilentlyContinue))
        {
            Write-Verbose "Initializing the Credential Cache"
            $global:O365TenantAdminCredentialCache = @{}
        }
    
        Write-Verbose "Adding Credential to the Credential Cache"
        $global:O365TenantAdminCredentialCache[$Credential.UserName] = $Credential
    }
    
    # load the required assemblies and Windows PowerShell modules
    
        if(-not ((Load-SharePointOnlineClientComponentAssemblies) -and (Load-SharePointOnlineModule)) ) { return }
    
    # Add the credentials to the client context and SharePoint service connection
    
        # check for cached credentials to use
        $o365TenantAdminCredential = Get-CredentialFromCredentialCache -CredentialName $tenantAdmin
    
        if(-not $o365TenantAdminCredential)
        {
            # when credentials are not cached, prompt for the tenant admin credentials
            $o365TenantAdminCredential = Get-Credential -UserName $tenantAdmin -Message "Enter the password for the Microsoft 365 admin"
    
            if(-not $o365TenantAdminCredential -or -not $o365TenantAdminCredential.UserName -or $o365TenantAdminCredential.Password.Length -eq 0 )
            {
                Write-Error -Message "Could not validate the supplied tenant admin credentials"
                return
            }
    
            # add the credentials to the cache
            Add-CredentialToCredentialCache -Credential $o365TenantAdminCredential
        }
    
    # connect to Office365 first, required for SharePoint cmdlets to run
    
        Connect-SPOService -Url $sharepointAdminCenterUrl -Credential $o365TenantAdminCredential
    
    # enumerate each of the specified site URLs
    
        foreach($webUrl in $webUrls)
        {
            $grantedSiteCollectionAdmin = $false
    
            try
            {
                # establish the client context and set the credentials to connect to the site
                $script:clientContext = New-Object Microsoft.SharePoint.Client.ClientContext($webUrl)
                $script:clientContext.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($o365TenantAdminCredential.UserName, $o365TenantAdminCredential.Password)
    
                # initialize the site and web context
                $script:clientContext.Load($script:clientContext.Site)
                $script:clientContext.Load($script:clientContext.Web)
                $script:clientContext.ExecuteQuery()
    
                # load and ensure the tenant admin user account if present on the target SharePoint site
                $tenantAdminUser = $script:clientContext.Web.EnsureUser($o365TenantAdminCredential.UserName)
                $script:clientContext.Load($tenantAdminUser)
                $script:clientContext.ExecuteQuery()
    
                # check if the tenant admin is a site admin
                if( -not $tenantAdminUser.IsSiteAdmin )
                {
                    try
                    {
                        # grant the tenant admin temporary admin rights to the site collection
                        Set-SPOUser -Site $script:clientContext.Site.Url -LoginName $o365TenantAdminCredential.UserName -IsSiteCollectionAdmin $true | Out-Null
                        $grantedSiteCollectionAdmin = $true
                    }
                    catch
                    {
                        Write-Error $_.Exception
                        return
                    }
                }
    
                try
                {
                    # load the list orlibrary using CSOM
    
                    $list = $null
                    $list = $script:clientContext.Web.Lists.GetByTitle($listTitle)
                    $script:clientContext.Load($list)
                    $script:clientContext.ExecuteQuery()
    
                    # **************  ADMIN INSTRUCTIONS  **************
                    # If necessary, modify the following Set-IrmConfiguration parameters to match your required values
                    # The supplied options and values are for example only
                    # Example that shows the Set-IrmConfiguration command with all parameters: Set-IrmConfiguration -List $list -PolicyTitle "Protected Files" -PolicyDescription "This policy restricts access to authorized users" -IrmReject -ProtectionExpirationDate $(Get-Date).AddDays(180) -DisableDocumentBrowserView -AllowPrint -AllowScript -AllowWriteCopy -LicenseCacheExpireDays 25 -DocumentAccessExpireDays 90
    
                    Set-IrmConfiguration -List $list -PolicyTitle "Protected Files" -PolicyDescription "This policy restricts access to authorized users"  
                }
                catch
                {
                    Write-Error -Message "Error setting IRM configuration on site: $webUrl.`nError Details: $($_.Exception.ToString())"
                }
           }
           finally
           {
                if($grantedSiteCollectionAdmin)
                {
                    # remove the temporary admin rights to the site collection
                    Set-SPOUser -Site $script:clientContext.Site.Url -LoginName $o365TenantAdminCredential.UserName -IsSiteCollectionAdmin $false | Out-Null
                }
           }
        }
    
    Disconnect-SPOService -ErrorAction SilentlyContinue
    
  4. Przejrzyj skrypt i wprowadź następujące zmiany:

    1. $sharepointAdminCenterUrl Wyszukaj i zastąp przykładowy adres URL własnego centrum administracyjnego programu SharePoint.

      Ta wartość będzie znajdować się jako podstawowy adres URL po przejściu do centrum administracyjnego programu SharePoint i ma następujący format: https://< tenant_name-admin.sharepoint.com>

      Jeśli na przykład nazwa dzierżawy to "contoso", określ następujące elementy: https://contoso-admin.sharepoint.com

    2. $tenantAdmin Wyszukaj i zastąp przykładowa wartość własnym w pełni kwalifikowanym kontem administratora globalnego platformy Microsoft 365.

      Ta wartość jest taka sama jak używana do logowania się do Centrum administracyjne platformy Microsoft 365 co administrator globalny i ma następujący format: user_name@<nazwa domeny> dzierżawy.com

      Jeśli na przykład nazwa użytkownika administratora globalnego platformy Microsoft 365 to "admin" dla domeny dzierżawy "contoso.com", należy określić: admin@contoso.com

    3. $webUrls Wyszukaj i zastąp przykładowe wartości adresami URL internetowymi usługi OneDrive użytkowników, dodając lub usuwając dowolną liczbę wpisów.

      Alternatywnie zobacz komentarze w skrypcie dotyczące sposobu zamiany tej tablicy przez zaimportowanie elementu . Plik CSV zawierający wszystkie adresy URL, które należy skonfigurować. Udostępniliśmy inny przykładowy skrypt umożliwiający automatyczne wyszukiwanie i wyodrębnianie adresów URL w celu wypełnienia tego elementu . Plik CSV. Gdy wszystko będzie gotowe do wykonania, użyj dodatkowego skryptu , aby wyświetlić wszystkie adresy URL usługi OneDrive do elementu . Sekcja pliku CSV natychmiast po wykonaniu tych kroków.

      Internetowy adres URL usługi OneDrive użytkownika ma następujący format: https:// dostępna nazwa-my.sharepoint.com/personal/>< user_name>_nazwa>_<dzierżawy_com<

      Jeśli na przykład użytkownik w dzierżawie contoso ma nazwę użytkownika "rsimone", należy określić: https://contoso-my.sharepoint.com/personal/rsimone_contoso_com

    4. Ponieważ używamy skryptu do konfigurowania usługi OneDrive, nie zmieniaj wartości Dokumenty dla zmiennej $listTitle .

    5. Wyszukaj ciąg ADMIN INSTRUCTIONS. Jeśli nie wprowadzisz żadnych zmian w tej sekcji, usługa OneDrive użytkownika zostanie skonfigurowana dla usługi IRM z tytułem zasad "Chronione pliki" i opisem "Te zasady ograniczają dostęp do autoryzowanych użytkowników". Nie zostaną ustawione żadne inne opcje usługi IRM, które prawdopodobnie są odpowiednie dla większości środowisk. Można jednak zmienić sugerowany tytuł i opis zasad, a także dodać inne opcje usługi IRM, które są odpowiednie dla danego środowiska. Zobacz komentarz przykładowy skrypt, aby ułatwić konstruowanie własnego zestawu parametrów dla polecenia Set-IrmConfiguration.

  5. Zapisz skrypt i podpisz go. Jeśli skrypt nie zostanie podpisany (bezpieczniejszy), program Windows PowerShell musi być skonfigurowany na komputerze w celu uruchamiania niepodpisanych skryptów. W tym celu uruchom sesję programu Windows PowerShell z opcją Uruchom jako Administracja istrator i wpisz: Set-ExecutionPolicy Unrestricted. Jednak ta konfiguracja umożliwia uruchamianie wszystkich niepodpisanych skryptów (mniej bezpieczne).

    Aby uzyskać więcej informacji na temat podpisywania skryptów programu Windows PowerShell, zobacz about_Signing w bibliotece dokumentacji programu PowerShell.

  6. Uruchom skrypt i po wyświetleniu monitu podaj hasło dla konta administratora platformy Microsoft 365. Jeśli zmodyfikujesz skrypt i uruchomisz go w tej samej sesji programu Windows PowerShell, nie zostanie wyświetlony monit o podanie poświadczeń.

Napiwek

Możesz również użyć tego skryptu, aby skonfigurować usługę IRM dla biblioteki programu SharePoint. W przypadku tej konfiguracji prawdopodobnie zechcesz włączyć dodatkową opcję Nie zezwalaj użytkownikom na przekazywanie dokumentów, które nie obsługują usługi IRM, aby upewnić się, że biblioteka zawiera tylko chronione dokumenty. W tym celu dodaj -IrmReject parametr do polecenia Set-IrmConfiguration w skrycie.

Należy również zmodyfikować zmienną $webUrls (na przykład https://contoso.sharepoint.com) i $listTitle zmienną (na przykład $Reports).

Jeśli musisz wyłączyć usługę IRM dla bibliotek usługi OneDrive użytkownika, zobacz sekcję Skrypt wyłączania usługi IRM dla usługi OneDrive .

Dodatkowy skrypt umożliwiający wyprowadzenie wszystkich adresów URL usługi OneDrive do elementu . Plik CSV

W kroku 4c powyżej możesz użyć następującego skryptu programu Windows PowerShell, aby wyodrębnić adresy URL dla wszystkich bibliotek usługi OneDrive użytkowników, które można następnie sprawdzić, edytować w razie potrzeby, a następnie zaimportować do skryptu głównego.

Ten skrypt wymaga również zestawu SDK składników klienta programu SharePoint i powłoki zarządzania programu SharePoint. Postępuj zgodnie z tymi samymi instrukcjami, aby skopiować i wkleić go, zapisz plik lokalnie (na przykład "Report-OneDriveForBusinessSiteInfo.ps1"), zmodyfikuj $sharepointAdminCenterUrl wartości i $tenantAdmin tak jak poprzednio, a następnie uruchom skrypt.

**Zastrzeżenie**: ten przykładowy skrypt nie jest obsługiwany w żadnym standardowym programie pomocy technicznej ani usłudze firmy Microsoft. Ten przykładowy skrypt jest dostarczany jako bez gwarancji jakiegokolwiek rodzaju.

# Requires Windows PowerShell version 3

<#
  Description:

    Queries the search service of a Microsoft 365 tenant to retrieve all OneDrive sites.  
    Details of the discovered sites are written to a .CSV file (by default,"OneDriveForBusinessSiteInfo_<date>.csv").

 Script Installation Requirements:

   SharePoint Client Components SDK
   https://www.microsoft.com/download/details.aspx?id=42038

   SharePoint Management Shell
   https://www.microsoft.com/download/details.aspx?id=35588

======
#>

# URL will be in the format https://<tenant-name>-admin.sharepoint.com
$sharepointAdminCenterUrl = "https://contoso-admin.sharepoint.com"

$tenantAdmin = "admin@contoso.onmicrosoft.com"                           

$reportName = "OneDriveForBusinessSiteInfo_$((Get-Date).ToString("yyyy-MM-dd_hh.mm.ss")).csv"

$oneDriveForBusinessSiteUrls= @()
$resultsProcessed = 0

function Load-SharePointOnlineClientComponentAssemblies
{
    [cmdletbinding()]
    param()

    process
    {
        # assembly location: C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI
        try
        {
            Write-Verbose "Loading Assembly: Microsoft.Office.Client.Policy, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
            [System.Reflection.Assembly]::Load("Microsoft.Office.Client.Policy, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") | Out-Null

            Write-Verbose "Loading Assembly: Microsoft.Office.Client.TranslationServices, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
            [System.Reflection.Assembly]::Load("Microsoft.Office.Client.TranslationServices, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") | Out-Null

            Write-Verbose "Loading Assembly: Microsoft.SharePoint.Client, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
            [System.Reflection.Assembly]::Load("Microsoft.SharePoint.Client, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") | Out-Null

            Write-Verbose "Loading Assembly: Microsoft.SharePoint.Client.DocumentManagement, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
            [System.Reflection.Assembly]::Load("Microsoft.SharePoint.Client.DocumentManagement, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") | Out-Null

            Write-Verbose "Loading Assembly: Microsoft.SharePoint.Client.Publishing, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
            [System.Reflection.Assembly]::Load("Microsoft.SharePoint.Client.Publishing, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") | Out-Null

            Write-Verbose "Loading Assembly: Microsoft.SharePoint.Client.Runtime, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
            [System.Reflection.Assembly]::Load("Microsoft.SharePoint.Client.Runtime, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") | Out-Null

            Write-Verbose "Loading Assembly: Microsoft.SharePoint.Client.Search.Applications, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
            [System.Reflection.Assembly]::Load("Microsoft.SharePoint.Client.Search.Applications, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") | Out-Null

            Write-Verbose "Loading Assembly: Microsoft.SharePoint.Client.Search, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
            [System.Reflection.Assembly]::Load("Microsoft.SharePoint.Client.Search, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") | Out-Null

            Write-Verbose "Loading Assembly: Microsoft.SharePoint.Client.Taxonomy, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
            [System.Reflection.Assembly]::Load("Microsoft.SharePoint.Client.Taxonomy, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") | Out-Null

            Write-Verbose "Loading Assembly: Microsoft.SharePoint.Client.UserProfiles, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
            [System.Reflection.Assembly]::Load("Microsoft.SharePoint.Client.UserProfiles, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") | Out-Null

            return $true
        }
        catch
        {
            if($_.Exception.Message -match "Could not load file or assembly")
            {
                Write-Error -Message "Unable to load the SharePoint Server 2013 Client Components.`nDownload Location: https://www.microsoft.com/download/details.aspx?id=42038"
            }
            else
            {
                Write-Error -Exception $_.Exception
            }
            return $false
        }
    }
}

function Load-SharePointOnlineModule
{
    [cmdletbinding()]
    param()

    process
    {
        do
        {
            # Installation location: C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell
            $spoModule = Get-Module -Name Microsoft.Online.SharePoint.PowerShell -ErrorAction SilentlyContinue

            if(-not $spoModule)
            {
                try
                {
                    Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
                    return $true
                }
                catch
                {
                    if($_.Exception.Message -match "Could not load file or assembly")
                    {
                        Write-Error -Message "Unable to load the SharePoint Online Management Shell.`nDownload Location: https://www.microsoft.com/download/details.aspx?id=35588"
                    }
                    else
                    {
                        Write-Error -Exception $_.Exception
                    }
                    return $false
                }
            }
            else
            {
                return $true
            }
        }
        while(-not $spoModule)
    }
}

function Get-CredentialFromCredentialCache
{
    [cmdletbinding()]
    param([string]$CredentialName)

    #if( Test-Path variable:\global:CredentialCache )
    if( Get-Variable O365TenantAdminCredentialCache -Scope Global -ErrorAction SilentlyContinue )
    {
        if($global:O365TenantAdminCredentialCache.ContainsKey($CredentialName))
        {
            Write-Verbose "Credential Cache Hit: $CredentialName"
            return $global:O365TenantAdminCredentialCache[$CredentialName]
        }
    }
    Write-Verbose "Credential Cache Miss: $CredentialName"
    return $null
}

function Add-CredentialToCredentialCache
{
    [cmdletbinding()]
    param([System.Management.Automation.PSCredential]$Credential)

    if(-not (Get-Variable CredentialCache -Scope Global -ErrorAction SilentlyContinue))
    {
        Write-Verbose "Initializing the Credential Cache"
        $global:O365TenantAdminCredentialCache = @{}
    }

    Write-Verbose "Adding Credential to the Credential Cache"
    $global:O365TenantAdminCredentialCache[$Credential.UserName] = $Credential
}

# load the required assemblies and Windows PowerShell modules

    if(-not ((Load-SharePointOnlineClientComponentAssemblies) -and (Load-SharePointOnlineModule)) ) { return }

# Add the credentials to the client context and SharePoint service connection

    # check for cached credentials to use
    $o365TenantAdminCredential = Get-CredentialFromCredentialCache -CredentialName $tenantAdmin

    if(-not $o365TenantAdminCredential)
    {
        # when credentials are not cached, prompt for the tenant admin credentials
        $o365TenantAdminCredential = Get-Credential -UserName $tenantAdmin -Message "Enter the password for the Office 365 admin"

        if(-not $o365TenantAdminCredential -or -not $o365TenantAdminCredential.UserName -or $o365TenantAdminCredential.Password.Length -eq 0 )
        {
            Write-Error -Message "Could not validate the supplied tenant admin credentials"
            return
        }

        # add the credentials to the cache
        Add-CredentialToCredentialCache -Credential $o365TenantAdminCredential
    }

# establish the client context and set the credentials to connect to the site

    $clientContext = New-Object Microsoft.SharePoint.Client.ClientContext($sharepointAdminCenterUrl)
    $clientContext.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($o365TenantAdminCredential.UserName, $o365TenantAdminCredential.Password)

# run a query against the Microsoft 365 tenant search service to retrieve all OneDrive URLs

    do
    {
        # build the query object
	    $query = New-Object Microsoft.SharePoint.Client.Search.Query.KeywordQuery($clientContext)
	    $query.TrimDuplicates        = $false
	    $query.RowLimit              = 500
	    $query.QueryText             = "SPSiteUrl:'/personal/' AND contentclass:STS_Site"
	    $query.StartRow              = $resultsProcessed
	    $query.TotalRowsExactMinimum = 500000

        # run the query
	    $searchExecutor = New-Object Microsoft.SharePoint.Client.Search.Query.SearchExecutor($clientContext)
	    $queryResults = $searchExecutor.ExecuteQuery($query)
	    $clientContext.ExecuteQuery()

        # enumerate the search results and store the site URLs
        $queryResults.Value[0].ResultRows | % {
            $oneDriveForBusinessSiteUrls += $_.Path
            $resultsProcessed++
        }
    }
    while($resultsProcessed -lt $queryResults.Value.TotalRows)

$oneDriveForBusinessSiteUrls | Out-File -FilePath $reportName
Skrypt wyłączania usługi IRM dla usługi OneDrive

Użyj następującego przykładowego skryptu, jeśli musisz wyłączyć usługę IRM dla usługi OneDrive użytkowników.

Ten skrypt wymaga również zestawu SDK składników klienta programu SharePoint i powłoki zarządzania programu SharePoint. Skopiuj i wklej zawartość, zapisz plik lokalnie (na przykład "Disable-IRMOnOneDriveForBusiness.ps1"), a następnie zmodyfikuj $sharepointAdminCenterUrl wartości i $tenantAdmin . Ręcznie określ adresy URL usługi OneDrive lub użyj skryptu w poprzedniej sekcji, aby można je było zaimportować, a następnie uruchomić skrypt.

**Zastrzeżenie**: ten przykładowy skrypt nie jest obsługiwany w żadnym standardowym programie pomocy technicznej ani usłudze firmy Microsoft. Ten przykładowy skrypt jest dostarczany jako bez gwarancji jakiegokolwiek rodzaju.

# Requires Windows PowerShell version 3

<#
  Description:

    Disables IRM for OneDrive and can also be used for SharePoint libraries and lists

 Script Installation Requirements:

   SharePoint Client Components SDK
   https://www.microsoft.com/download/details.aspx?id=42038

   SharePoint Management Shell
   https://www.microsoft.com/download/details.aspx?id=35588

======
#>

$sharepointAdminCenterUrl = "https://contoso-admin.sharepoint.com"

$tenantAdmin = "admin@contoso.com"

$webUrls = @("https://contoso-my.sharepoint.com/personal/user1_contoso_com",
             "https://contoso-my.sharepoint.com/personal/user2_contoso_com",
             "https://contoso-my.sharepoint.com/personal/person3_contoso_com")

<# As an alternative to specifying the URLs as an array, you can import them from a CSV file (no header, single value per row).
   Then, use: $webUrls = Get-Content -Path "File_path_and_name.csv"

#>

$listTitle = "Documents"

function Load-SharePointOnlineClientComponentAssemblies
{
    [cmdletbinding()]
    param()

    process
    {
        # assembly location: C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI
        try
        {
            Write-Verbose "Loading Assembly: Microsoft.Office.Client.Policy, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
            [System.Reflection.Assembly]::Load("Microsoft.Office.Client.Policy, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") | Out-Null

            Write-Verbose "Loading Assembly: Microsoft.Office.Client.TranslationServices, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
            [System.Reflection.Assembly]::Load("Microsoft.Office.Client.TranslationServices, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") | Out-Null

            Write-Verbose "Loading Assembly: Microsoft.SharePoint.Client, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
            [System.Reflection.Assembly]::Load("Microsoft.SharePoint.Client, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") | Out-Null

            Write-Verbose "Loading Assembly: Microsoft.SharePoint.Client.DocumentManagement, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
            [System.Reflection.Assembly]::Load("Microsoft.SharePoint.Client.DocumentManagement, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") | Out-Null

            Write-Verbose "Loading Assembly: Microsoft.SharePoint.Client.Publishing, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
            [System.Reflection.Assembly]::Load("Microsoft.SharePoint.Client.Publishing, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") | Out-Null

            Write-Verbose "Loading Assembly: Microsoft.SharePoint.Client.Runtime, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
            [System.Reflection.Assembly]::Load("Microsoft.SharePoint.Client.Runtime, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") | Out-Null

            Write-Verbose "Loading Assembly: Microsoft.SharePoint.Client.Search.Applications, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
            [System.Reflection.Assembly]::Load("Microsoft.SharePoint.Client.Search.Applications, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") | Out-Null

            Write-Verbose "Loading Assembly: Microsoft.SharePoint.Client.Search, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
            [System.Reflection.Assembly]::Load("Microsoft.SharePoint.Client.Search, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") | Out-Null

            Write-Verbose "Loading Assembly: Microsoft.SharePoint.Client.Taxonomy, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
            [System.Reflection.Assembly]::Load("Microsoft.SharePoint.Client.Taxonomy, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") | Out-Null

            Write-Verbose "Loading Assembly: Microsoft.SharePoint.Client.UserProfiles, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
            [System.Reflection.Assembly]::Load("Microsoft.SharePoint.Client.UserProfiles, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") | Out-Null

            return $true
        }
        catch
        {
            if($_.Exception.Message -match "Could not load file or assembly")
            {
                Write-Error -Message "Unable to load the SharePoint Server 2013 Client Components.`nDownload Location: https://www.microsoft.com/download/details.aspx?id=42038"
            }
            else
            {
                Write-Error -Exception $_.Exception
            }
            return $false
        }
    }
}

function Load-SharePointOnlineModule
{
    [cmdletbinding()]
    param()

    process
    {
        do
        {
            # Installation location: C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell
            $spoModule = Get-Module -Name Microsoft.Online.SharePoint.PowerShell -ErrorAction SilentlyContinue

            if(-not $spoModule)
            {
                try
                {
                    Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
                    return $true
                }
                catch
                {
                    if($_.Exception.Message -match "Could not load file or assembly")
                    {
                        Write-Error -Message "Unable to load the SharePoint Online Management Shell.`nDownload Location: https://www.microsoft.com/download/details.aspx?id=35588"
                    }
                    else
                    {
                        Write-Error -Exception $_.Exception
                    }
                    return $false
                }
            }
            else
            {
                return $true
            }
        }
        while(-not $spoModule)
    }
}

function Remove-IrmConfiguration
{
    [cmdletbinding()]
    param(
        [parameter(Mandatory=$true)][Microsoft.SharePoint.Client.List]$List
    )

    process
    {
        Write-Verbose "Disabling IRM Configuration on '$($List.Title)'"

        $List.IrmEnabled = $false
        $List.IrmExpire  = $false
        $List.IrmReject  = $false
        $List.InformationRightsManagementSettings.Reset()
    }
    end
    {
        if($List)
        {
            Write-Verbose "Committing IRM configuration settings on '$($list.Title)'"
            $list.InformationRightsManagementSettings.Update()
            $list.Update()
            $script:clientContext.Load($list)
            $script:clientContext.ExecuteQuery()
        }
    }
}

function Get-CredentialFromCredentialCache
{
    [cmdletbinding()]
    param([string]$CredentialName)

    #if( Test-Path variable:\global:CredentialCache )
    if( Get-Variable O365TenantAdminCredentialCache -Scope Global -ErrorAction SilentlyContinue )
    {
        if($global:O365TenantAdminCredentialCache.ContainsKey($CredentialName))
        {
            Write-Verbose "Credential Cache Hit: $CredentialName"
            return $global:O365TenantAdminCredentialCache[$CredentialName]
        }
    }
    Write-Verbose "Credential Cache Miss: $CredentialName"
    return $null
}

function Add-CredentialToCredentialCache
{
    [cmdletbinding()]
    param([System.Management.Automation.PSCredential]$Credential)

    if(-not (Get-Variable CredentialCache -Scope Global -ErrorAction SilentlyContinue))
    {
        Write-Verbose "Initializing the Credential Cache"
        $global:O365TenantAdminCredentialCache = @{}
    }

    Write-Verbose "Adding Credential to the Credential Cache"
    $global:O365TenantAdminCredentialCache[$Credential.UserName] = $Credential
}

# load the required assemblies and Windows PowerShell modules

    if(-not ((Load-SharePointOnlineClientComponentAssemblies) -and (Load-SharePointOnlineModule)) ) { return }

# Add the credentials to the client context and SharePoint service connection

    # check for cached credentials to use
    $o365TenantAdminCredential = Get-CredentialFromCredentialCache -CredentialName $tenantAdmin

    if(-not $o365TenantAdminCredential)
    {
        # when credentials are not cached, prompt for the tenant admin credentials
        $o365TenantAdminCredential = Get-Credential -UserName $tenantAdmin -Message "Enter the password for the Office 365 admin"

        if(-not $o365TenantAdminCredential -or -not $o365TenantAdminCredential.UserName -or $o365TenantAdminCredential.Password.Length -eq 0 )
        {
            Write-Error -Message "Could not validate the supplied tenant admin credentials"
            return
        }

        # add the credentials to the cache
        Add-CredentialToCredentialCache -Credential $o365TenantAdminCredential
    }

# connect to Office365 first, required for SharePoint cmdlets to run

    Connect-SPOService -Url $sharepointAdminCenterUrl -Credential $o365TenantAdminCredential

# enumerate each of the specified site URLs

    foreach($webUrl in $webUrls)
    {
        $grantedSiteCollectionAdmin = $false

        try
        {
            # establish the client context and set the credentials to connect to the site
            $script:clientContext = New-Object Microsoft.SharePoint.Client.ClientContext($webUrl)
            $script:clientContext.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($o365TenantAdminCredential.UserName, $o365TenantAdminCredential.Password)

            # initialize the site and web context
            $script:clientContext.Load($script:clientContext.Site)
            $script:clientContext.Load($script:clientContext.Web)
            $script:clientContext.ExecuteQuery()

            # load and ensure the tenant admin user account if present on the target SharePoint site
            $tenantAdminUser = $script:clientContext.Web.EnsureUser($o365TenantAdminCredential.UserName)
            $script:clientContext.Load($tenantAdminUser)
            $script:clientContext.ExecuteQuery()

            # check if the tenant admin is a site admin
            if( -not $tenantAdminUser.IsSiteAdmin )
            {
                try
                {
                    # grant the tenant admin temporary admin rights to the site collection
                    Set-SPOUser -Site $script:clientContext.Site.Url -LoginName $o365TenantAdminCredential.UserName -IsSiteCollectionAdmin $true | Out-Null
                    $grantedSiteCollectionAdmin = $true
                }
                catch
                {
                    Write-Error $_.Exception
                    return
                }
            }

            try
            {
                # load the list orlibrary using CSOM

                $list = $null
                $list = $script:clientContext.Web.Lists.GetByTitle($listTitle)
                $script:clientContext.Load($list)
                $script:clientContext.ExecuteQuery()

               Remove-IrmConfiguration -List $list
            }
            catch
            {
                Write-Error -Message "Error setting IRM configuration on site: $webUrl.`nError Details: $($_.Exception.ToString())"
            }
       }
       finally
       {
            if($grantedSiteCollectionAdmin)
            {
                # remove the temporary admin rights to the site collection
                Set-SPOUser -Site $script:clientContext.Site.Url -LoginName $o365TenantAdminCredential.UserName -IsSiteCollectionAdmin $false | Out-Null
            }
       }
    }

Disconnect-SPOService -ErrorAction SilentlyContinue