スクリプトを使用して、電子情報開示 (Standard) ケースの保留にユーザーを追加する

セキュリティ & コンプライアンス PowerShell には、電子情報開示ケースの作成と管理に関連する時間のかかるタスクを自動化できるコマンドレットが用意されています。 現在、Microsoft Purview コンプライアンス ポータルで Microsoft Purview eDiscovery (Standard) ケースを使用して多数のカストディアン コンテンツの場所を保留に配置するには、時間と準備が必要です。 たとえば、保留を作成する前に、保留にする各OneDrive for Business サイトの URL を収集する必要があります。 次に、保留にするユーザーごとに、メールボックスとそのOneDrive for Business サイトを保留に追加する必要があります。 この記事のスクリプトを使用して、このプロセスを自動化できます。

このスクリプトでは、organizationの個人用サイト ドメインの名前 (URL https://contoso-my.sharepoint.comなど)、contoso既存の電子情報開示ケースの名前、ケースに関連付けられている新しい保留リストの名前、保留にするユーザーのメール アドレスの一覧、クエリ ベースの保留を作成する場合に使用する検索クエリを入力するように求められます。 次に、スクリプトは、リスト内の各ユーザーのOneDrive for Business サイトの URL を取得し、新しい保留を作成し、リスト内の各ユーザーのメールボックスとOneDrive for Business サイトを保留に追加します。 このスクリプトでは、新しい保留に関する情報を含むログ ファイルも生成されます。

これを実現する手順を次に示します。

手順 1: SharePoint Online 管理シェルをインストールする手順 2: ユーザーの一覧を生成する 手順 3: スクリプトを実行して保留を作成し、ユーザーを追加する

ヒント

E5 のお客様でない場合は、90 日間の Microsoft Purview ソリューション試用版を使用して、Purview の追加機能が組織のデータ セキュリティとコンプライアンスのニーズの管理にどのように役立つかを確認してください。 Microsoft Purview コンプライアンス ポータルのトライアル ハブで今すぐ開始してください。 サインアップと試用期間の詳細については、こちらをご覧ください。

ユーザーを保留に追加する前に

  • 手順 3 でスクリプトを実行するには、コンプライアンス ポータルの電子情報開示マネージャー役割グループのメンバーであり、SharePoint Online 管理者である必要があります。 詳細については、「Office 365 セキュリティ & コンプライアンス センターで電子情報開示のアクセス許可を割り当てる」を参照してください。
  • コンプライアンス ポータルの電子情報開示ケースに関連付けられている保留リストには、最大 1,000 個のメールボックスと 100 個のサイトを追加できます。 保留にするすべてのユーザーにOneDrive for Business サイトがあると仮定すると、この記事のスクリプトを使用して、最大 100 人のユーザーを保留に追加できます。
  • 手順 2 で作成したユーザーの一覧と手順 3 のスクリプトを同じフォルダーに保存してください。 これでスクリプトの実行が容易になります。
  • スクリプトは、既存のケースに関連付けられている新しい保留リストにユーザーの一覧を追加します。 スクリプトを実行する前に、保留を関連付けるケースが作成されていることを確認してください。
  • この記事のスクリプトでは、Security & Compliance PowerShell と SharePoint Online Management Shell に接続するときの最新の認証がサポートされています。 Microsoft 365 または Microsoft 365 GCC organizationの場合は、そのままスクリプトを使用できます。 ドイツorganization Office 365、Microsoft 365 GCC High organization、または Microsoft 365 DoD organizationの場合は、スクリプトを編集して正常に実行する必要があります。 具体的には、行Connect-IPPSSessionを編集し、ConnectionUri パラメーターと AzureADAuthorizationEndpointUri パラメーター (およびorganizationの種類に適した値) を使用して、Security & Compliance PowerShell に接続する必要があります。 詳細については、「 セキュリティへの接続 & コンプライアンス PowerShell」の例を参照してください。
  • このスクリプトは、Security & Compliance PowerShell と SharePoint Online Management Shell から自動的に切断されます。
  • スクリプトには、最小限のエラー処理が含まれています。 その主な目的は、各ユーザーのメールボックスとOneDrive for Businessサイトをすばやく簡単に保留にすることです。
  • このトピックで提供されるサンプル スクリプトは、Microsoft 標準サポート プログラムまたはサービスではサポートされていません。 サンプル スクリプトは現状のまま提供され、いかなる保証も伴いません。 さらに、Microsoft は、商品性、特定目的への適合性を含む一切の黙示の保証をいたしかねます。 本サンプル スクリプトおよびドキュメントの使用または性能に起因するすべてのリスクは、お客様が負うものとします。 サンプル スクリプトおよびドキュメントを使用したこと、または使用できなかったことに伴って生じるいかなる損害 (業務利益の損失、業務の中断、業務情報の損失、金銭上の損失、その他一切の損害) についても、Microsoft、Microsoft に帰属する作者、スクリプトの作成、製造、または納入に関与したその他のすべての人員は、いかなる場合も責めを負わないものとします。

手順 1: SharePoint Online 管理シェルをインストールする

最初の手順は、SharePoint Online 管理シェルがローカル コンピューターにまだインストールされていない場合にインストールすることです。 この手順ではシェルを使用する必要はありませんが、手順 3 で実行するスクリプトで必要な前提条件が含まれているため、シェルをインストールする必要があります。 これらの前提条件により、スクリプトは SharePoint Online と通信して、OneDrive for Business サイトの URL を取得できます。

[SharePoint Online 管理シェル環境のセットアップ] に移動し、手順 1 と手順 2 を実行して SharePoint Online 管理シェルをローカル コンピューターにインストールします。

手順 2: ユーザーの一覧を生成する

手順 3 のスクリプトは、電子情報開示ケースに関連付けられた保留を作成し、ユーザーのリストのメールボックスとOneDrive for Businessサイトを保留に追加します。 テキスト ファイルにメール アドレスを入力するか、PowerShell でコマンドを実行してメール アドレスの一覧を取得し、ファイルに保存できます (手順 3 でスクリプトを保存するフォルダーと同じフォルダーにあります)。

organization内のすべてのユーザーの電子メール アドレスの一覧を取得し、HoldUsers.txt という名前のテキスト ファイルに保存するExchange Online PowerShell コマンドを次に示します。

Get-Mailbox -ResultSize unlimited -Filter { RecipientTypeDetails -eq 'UserMailbox'} | Select-Object PrimarySmtpAddress > HoldUsers.txt

このコマンドを実行した後、テキスト ファイルを開き、 PrimarySmtpAddressプロパティ名 を含むヘッダーを削除します。 次に、手順 3 で作成する保留に追加するユーザーのメール アドレスを除くすべてのメール アドレスを削除します。 電子メール アドレスの一覧の前後に空白の行がないことを確認します。

手順 3: スクリプトを実行して保留を作成し、ユーザーを追加する

この手順でスクリプトを実行すると、次の情報の入力が求められます。 スクリプトを実行する前に、この情報を準備しておいてください。

  • ユーザー資格情報: このスクリプトでは、資格情報を使用して Security & Compliance PowerShell に接続します。 また、これらの資格情報を使用して SharePoint Online にアクセスし、ユーザーの一覧のOneDrive for Business URL を取得します。

  • SharePoint ドメインの名前: スクリプトでは、 SharePoint 管理センターに接続できるように、この名前を入力するように求められます。 また、organizationの OneDrive URL のドメイン名も使用します。 たとえば、管理センターの URL が で https://contoso-admin.sharepoint.com 、OneDrive の URL が である場合は https://contoso-my.sharepoint.com、スクリプトからドメイン名の入力を求められたときに「」と入力 contoso します。

  • ケースの名前: 既存のケースの名前。 スクリプトによって、このケースに関連付けられた新しい保留が作成されます。

  • 保留の名前: スクリプトが作成し、指定したケースに関連付けるホールドの名前。

  • クエリ ベースのホールドの検索クエリ: クエリベースの保留を作成して、指定した検索条件を満たすコンテンツのみが保留されるようにすることができます。 すべてのコンテンツを保留にするには、検索クエリの入力を求められたら Enter キーを押します。

  • 保留をオンにするかどうか: スクリプトの作成後に保留を有効にすることも、スクリプトを有効にせずに保留を作成することもできます。 スクリプトで保留をオンにしていない場合は、コンプライアンス ポータルで後で有効にするか、次の PowerShell コマンドを実行して有効にすることができます。

    Set-CaseHoldPolicy -Identity <name of the hold> -Enabled $true
    
    Set-CaseHoldRule -Identity <name of the hold> -Disabled $false
    
  • ユーザーのリストを含むテキスト ファイルの 名前 - 保留に追加するユーザーのリストを含む手順 2 のテキスト ファイルの名前。 このファイルがスクリプトと同じフォルダーにある場合は、ファイルの名前 (たとえば、HoldUsers.txt) を入力します。 テキスト ファイルが別のフォルダーにある場合は、ファイルの完全なパス名を入力します。

スクリプトが求める情報を収集したら、最後にスクリプトを実行して新しい保留を作成し、それにユーザーを追加します。

  1. ファイル名サフィックス .ps1を使用して、次のテキストを Windows PowerShell スクリプト ファイルに保存します。 たとえば、「 AddUsersToHold.ps1 」のように入力します。

    #script begin
    " "
    write-host "***********************************************"
    write-host "   Security & Compliance PowerShell  " -foregroundColor yellow -backgroundcolor darkgreen
    write-host "   eDiscovery (Standard) cases - Add users to a hold   " -foregroundColor yellow -backgroundcolor darkgreen
    write-host "***********************************************"
    " "
    # Connect to Security & Compliance PowerShell using modern authentication
    if (!$SccSession)
    {
      Import-Module ExchangeOnlineManagement
      Connect-IPPSSession
    }
    
    # Get the organization's domain name. We use this to create the SharePoint admin URL and root URL for OneDrive for Business.
    ""
    $mySiteDomain = Read-Host "Enter the domain name for your SharePoint organization. We use this name to connect to SharePoint admin center and for the OneDrive URLs in your organization. For example, 'contoso' in 'https://contoso-admin.sharepoint.com' and 'https://contoso-my.sharepoint.com'"
    ""
    
    # Connect to PnP Online using modern authentication
    Import-Module PnP.PowerShell
    Connect-PnPOnline -Url https://$mySiteDomain-admin.sharepoint.com -UseWebLogin
    
    # Load the SharePoint assemblies from the SharePoint Online Management Shell
    # To install, go to https://go.microsoft.com/fwlink/p/?LinkId=255251
    if (!$SharePointClient -or !$SPRuntime -or !$SPUserProfile)
    {
        $SharePointClient = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
        $SPRuntime = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")
        $SPUserProfile = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.UserProfiles")
        if (!$SharePointClient)
        {
            Write-Error "The SharePoint Online Management Shell isn't installed. Please install it from: https://go.microsoft.com/fwlink/p/?LinkId=255251 and then re-run this script."
            return;
        }
    }
    
    # Get other required information
    do{
    $casename = Read-Host "Enter the name of the case"
    $caseexists = (get-compliancecase -identity "$casename" -erroraction SilentlyContinue).isvalid
    if($caseexists -ne 'True')
    {""
    write-host "A case named '$casename' doesn't exist. Please specify the name of an existing case, or create a new case and then re-run the script." -foregroundColor Yellow
    ""}
    }While($caseexists -ne 'True')
    ""
    do{
    $holdName = Read-Host "Enter the name of the new hold"
    $holdexists=(get-caseholdpolicy -identity "$holdname" -case "$casename" -erroraction SilentlyContinue).isvalid
    if($holdexists -eq 'True')
    {""
    write-host "A hold named '$holdname' already exists. Please specify a new hold name." -foregroundColor Yellow
    ""}
    }While($holdexists -eq 'True')
    ""
    $holdQuery = Read-Host "Enter a search query to create a query-based hold, or press Enter to hold all content"
    ""
    $holdstatus = read-host "Do you want the hold enabled after it's created? (Yes/No)"
    do{
    ""
    $inputfile = read-host "Enter the name of the text file that contains the email addresses of the users to add to the hold"
    ""
    $fileexists = test-path -path $inputfile
    if($fileexists -ne 'True'){write-host "$inputfile doesn't exist. Please enter a valid file name." -foregroundcolor Yellow}
    }while($fileexists -ne 'True')
    #Import the list of addresses from the txt file.  Trim any excess spaces and make sure all addresses
        #in the list are unique.
      [array]$emailAddresses = Get-Content $inputfile -ErrorAction SilentlyContinue | where {$_.trim() -ne ""}  | foreach{ $_.Trim() }
      [int]$dupl = $emailAddresses.count
      [array]$emailAddresses = $emailAddresses | select-object -unique
      $dupl -= $emailAddresses.count
    #Validate email addresses so the hold creation does not run in to an error.
    if($emailaddresses.count -gt 0){
    write-host ($emailAddresses).count "addresses were found in the text file. There were $dupl duplicate entries in the file." -foregroundColor Yellow
    ""
    Write-host "Validating the email addresses. Please wait..." -foregroundColor Yellow
    ""
    $finallist =@()
    foreach($emailAddress in $emailAddresses)
    {
    if((get-recipient $emailaddress -erroraction SilentlyContinue).isvalid -eq 'True')
    {$finallist += $emailaddress}
    else {"Unable to find the user $emailaddress"
    [array]$excludedlist += $emailaddress}
    }
    ""
    #Find user's OneDrive account URL using email address
    Write-Host "Getting the URL for each user's OneDrive for Business site." -foregroundColor Yellow
    ""
    $AdminUrl = "https://$mySiteDomain-admin.sharepoint.com"
    $mySiteUrlRoot = "https://$mySiteDomain-my.sharepoint.com"
    $urls = @()
    foreach($emailAddress in $finallist)
    {
    try
    {
    $url=Get-PnPUserProfileProperty -Account $emailAddress | Select PersonalUrl
    $urls += $url.PersonalUrl
           Write-Host "- $emailAddress => $url"
           [array]$ODadded += $url.PersonalUrl
           }catch {
     Write-Warning "Could not locate OneDrive for $emailAddress"
     [array]$ODExluded += $emailAddress
     Continue }
    }
    $urls | FL
    if(($finallist.count -gt 0) -or ($urls.count -gt 0)){
    ""
    Write-Host "Creating the hold named $holdname. Please wait..." -foregroundColor Yellow
    if(($holdstatus -eq "Y") -or ($holdstatus -eq  "y") -or ($holdstatus -eq "yes") -or ($holdstatus -eq "YES")){
    New-CaseHoldPolicy -Name "$holdName" -Case "$casename" -ExchangeLocation $finallist -SharePointLocation $urls -Enabled $True | out-null
    New-CaseHoldRule -Name "$holdName" -Policy "$holdname" -ContentMatchQuery $holdQuery | out-null
    }
    else{
    New-CaseHoldPolicy -Name "$holdName" -Case "$casename" -ExchangeLocation $finallist -SharePointLocation $urls -Enabled $false | out-null
    New-CaseHoldRule -Name "$holdName" -Policy "$holdname" -ContentMatchQuery $holdQuery -disabled $false | out-null
    }
    ""
    }
    else {"No valid locations were identified. Therefore, the hold wasn't created."}
    #write log files (if needed)
    $newhold=Get-CaseHoldPolicy -Identity "$holdname" -Case "$casename" -erroraction SilentlyContinue
    $newholdrule=Get-CaseHoldRule -Identity "$holdName" -erroraction SilentlyContinue
    if(($ODAdded.count -gt 0) -or ($ODExluded.count -gt 0) -or ($finallist.count -gt 0) -or ($excludedlist.count -gt 0) -or ($newhold.isvalid -eq 'True') -or ($newholdrule.isvalid -eq 'True'))
    {
    Write-Host "Generating output files..." -foregroundColor Yellow
    if($ODAdded.count -gt 0){
    "OneDrive Locations" | add-content .\LocationsOnHold.txt
    "==================" | add-content .\LocationsOnHold.txt
    $newhold.SharePointLocation.name | add-content .\LocationsOnHold.txt}
    if($ODExluded.count -gt 0){
    "Users without OneDrive locations" | add-content .\LocationsNotOnHold.txt
    "================================" | add-content .\LocationsNotOnHold.txt
    $ODExluded | add-content .\LocationsNotOnHold.txt}
    if($finallist.count -gt 0){
    " " | add-content .\LocationsOnHold.txt
    "Exchange Locations" | add-content .\LocationsOnHold.txt
    "==================" | add-content .\LocationsOnHold.txt
    $newhold.ExchangeLocation.name | add-content .\LocationsOnHold.txt}
    if($excludedlist.count -gt 0){
    " "| add-content .\LocationsNotOnHold.txt
    "Mailboxes not added to the hold" | add-content .\LocationsNotOnHold.txt
    "===============================" | add-content .\LocationsNotOnHold.txt
    $excludedlist | add-content .\LocationsNotOnHold.txt}
    $FormatEnumerationLimit=-1
    if($newhold.isvalid -eq 'True'){$newhold|fl >.\GetCaseHoldPolicy.txt}
    if($newholdrule.isvalid -eq 'True'){$newholdrule|Fl >.\GetCaseHoldRule.txt}
    }
    }
    else {"The hold wasn't created because no valid entries were found in the text file."}
    ""
    #Disconnect from SCC PowerShell and PnPOnline
    
    Write-host "Disconnecting from SCC PowerShell and PnP Online" -foregroundColor Yellow
    Get-PSSession | Remove-PSSession
    Disconnect-PnPOnline
    
    Write-host "Script complete!" -foregroundColor Yellow
    ""
    #script end
    
  2. ローカル コンピューターで、Windows PowerShellを開き、スクリプトを保存したフォルダーに移動します。

  3. スクリプトを実行します。例えば:

    .\AddUsersToHold.ps1
    
  4. スクリプトで求める情報を入力します。

    このスクリプトは、Security & Compliance PowerShell に接続し、電子情報開示ケースに新しい保留を作成し、一覧にユーザーのメールボックスとOneDrive for Businessを追加します。 コンプライアンス ポータルの 電子情報開示 ページでケースに移動して、新しい保留を表示できます。

スクリプトの実行が完了すると、次のログ ファイルが作成され、スクリプトが配置されているフォルダーに保存されます。

  • LocationsOnHold.txt:スクリプトが正常に保留にしたメールボックスとOneDrive for Business サイトの一覧が含まれます。
  • LocationsNotOnHold.txt:スクリプトが保留にしなかったメールボックスとOneDrive for Business サイトの一覧が含まれます。 ユーザーがメールボックスを持っていて、OneDrive for Businessサイトがない場合、ユーザーは保留にされなかったOneDrive for Businessサイトの一覧に含まれます。
  • GetCaseHoldPolicy.txt: 新しいホールドの Get-CaseHoldPolicy コマンドレットの出力が含まれます。このコマンドレットは、新しい保留を作成した後にスクリプトが実行されます。 このコマンドレットによって返される情報には、メールボックスとOneDrive for Businessサイトが保留にされたユーザーの一覧と、保留が有効か無効かが含まれます。
  • GetCaseHoldRule.txt: 新しいホールドの Get-CaseHoldRule コマンドレットの出力が含まれます。このコマンドレットは、新しい保留を作成した後にスクリプトが実行されます。 このコマンドレットによって返される情報には、スクリプトを使用してクエリ ベースのホールドを作成した場合の検索クエリが含まれます。