次の方法で共有


チュートリアル: バージョン ストレージ レポート ファイルで 'What-If' 分析を実行する

このチュートリアルでは、提供されたスクリプトと Excel の例を活用して、バージョン ストレージまたは影響を受けるユーザーに自動または手動の制限を適用することの影響を理解する方法について説明します。 以下のことを行う方法を説明します。

  • 自動制限の設定の影響分析を実行します。
  • 指定した日数より前の期限切れのバージョンの影響分析を実行します。
  • 指定されたカウント制限内にバージョンを格納する影響分析を実行します。

開始する前に

前のチュートリアルでは、バージョン ストレージ使用状況レポートを生成しました。 このチュートリアルでは、レポート生成ジョブが正常に完了し、レポートが完全に設定されていることを前提としています。
まず、レポート ファイルをローカル コンピューターにダウンロードします。 ファイルに目的の設定を適用し、影響を分析するには、次に示すスクリプトを使用します。

自動バージョン履歴制限の設定の影響分析を実行する

レポート ファイル C:\Report.csv自動有効期限ポリシーを適用する What-If レポート ファイルを生成するために適用できる PowerShell スクリプトの例を次に示します。 

# save this file as ScheduleUpdate_Auto.ps1 

param (
  [Parameter(Mandatory=$true)][string]$ImportPath,
  [Parameter(Mandatory=$true)][string]$ExportPath
)

$Schedule = Import-Csv -Path $ImportPath 
$Schedule | 
  ForEach-Object { 
    $_.TargetExpirationDate = $_.AutomaticPolicyExpirationDate
  } 
$Schedule | 
  Export-Csv -Path $ExportPath -UseQuotes AsNeeded -NoTypeInformation

注:

PowerShell 7 を使用してコマンドを実行します。 PowerShell 7 は、次の手順に従ってインストールできます。 Windows への PowerShell のインストール - PowerShell |Microsoft Learn

有効期限の自動化のスクリーンショット。

手動の有効期限制限の設定の影響分析を実行する

What-If レポート ファイルを生成する PowerShell スクリプトの例を次に示します。 レポート ファイル C:\Report.csvでは、期限切れ日数が 30 に設定された手動有効期限が適用されます。 

# save this file as ScheduleUpdate_ExpireAfter.ps1

param (
  [Parameter(Mandatory=$false)][string]$ImportPath,
  [Parameter(Mandatory=$false)][string]$ExportPath,
  [Parameter(Mandatory=$false)][double]$ExpireAfter
)

function StringToDateTime($Value) { return [string]::IsNullOrEmpty($Value) ? $null : [DateTime]::ParseExact($Value, "yyyy-MM-ddTHH:mm:ssK", $null) }
function DateTimeToString($Value) { return $null -eq $Value ? "" : $Value.ToString("yyyy-MM-ddTHH:mm:ssK") }  

$Schedule = Import-Csv -Path $ImportPath 
$Schedule | 
  ForEach-Object { 
    $SnapshotDate = StringToDateTime -Value $_.SnapshotDate
    $TargetExpirationDate = $SnapshotDate.AddDays($ExpireAfter)
    $_.TargetExpirationDate = DateTimeToString -Value $TargetExpirationDate
  } 
$Schedule | 
  Export-Csv -Path $ExportPath -UseQuotes AsNeeded -NoTypeInformation

注:

PowerShell 7 を使用してコマンドを実行します。 PowerShell 7 は、次の手順に従ってインストールできます。 Windows への PowerShell のインストール - PowerShell |Microsoft Learn。

手動の有効期限のスクリーンショット。

手動カウント制限の設定の影響分析を実行する

What-If レポート ファイルを生成する PowerShell スクリプトの例を次に示します。 レポート ファイルのC:\Report.csvでは、メジャー バージョンの制限が 50 に設定されている [カウント制限付きの手動] ポリシーが適用されます。

# save this file as ScheduleUpdate_Count.ps1

param (
  [Parameter(Mandatory=$true)][string]$ImportPath,
  [Parameter(Mandatory=$true)][string]$ExportPath,
  [Parameter(Mandatory=$true)][int]$MajorVersionLimit
)

$Report = Import-Csv -Path $ImportPath 

$PreviousWebId = [Guid]::Empty
$PreviousDocId = [Guid]::Empty
$PreviousWebUrl = [string]::Empty
$PreviousFileUrl = [string]::Empty
$PreviousModifiedByUserId = [string]::Empty
$PreviousModifiedByDisplayName = [string]::Empty

$FileToVersions = @{}

foreach ($Version in $Report)
{  
  $WebId = [string]::IsNullOrEmpty($Version."WebId.Compact") ? $PreviousWebId : [Guid]::Parse($Version."WebId.Compact")
  $DocId = [string]::IsNullOrEmpty($Version."DocId.Compact") ? $PreviousDocId : [Guid]::Parse($Version."DocId.Compact")
  $WebUrl = [string]::IsNullOrEmpty($Version."WebUrl.Compact") ? $PreviousWebUrl : $Version."WebUrl.Compact"
  $FileUrl = [string]::IsNullOrEmpty($Version."FileUrl.Compact") ? $PreviousFileUrl : $Version."FileUrl.Compact"
  $ModifiedByUserId = [string]::IsNullOrEmpty($Version."ModifiedBy_UserId.Compact") ? $PreviousModifiedByUserId : $Version."ModifiedBy_UserId.Compact"
  $ModifiedByDisplayName = [string]::IsNullOrEmpty($Version."ModifiedBy_DisplayName.Compact") ? $PreviousModifiedByDisplayName : $Version."ModifiedBy_DisplayName.Compact"

  $PreviousWebId = $WebId
  $PreviousDocId = $DocId
  $PreviousWebUrl = $WebUrl
  $PreviousFileUrl = $FileUrl
  $PreviousModifiedByUserId = $ModifiedByUserId
  $PreviousModifiedByDisplayName = $ModifiedByDisplayName

  if (($PreviousWebId -eq [Guid]::Empty) -or ($WebId -eq [Guid]::Empty) -or 
    ($PreviousDocId -eq [Guid]::Empty) -or ($DocId -eq [Guid]::Empty))
  {
    throw "Compact column error."
  }

  $Version."WebId.Compact" = $WebId
  $Version."DocId.Compact" = $DocId
  $Version."WebUrl.Compact" = $WebUrl
  $Version."FileUrl.Compact" = $FileUrl
  $Version."ModifiedBy_UserId.Compact" = $ModifiedByUserId
  $Version."ModifiedBy_DisplayName.Compact" = $ModifiedByDisplayName
   
  if ($null -eq $FileToVersions[$DocId]) 
  {
    $FileToVersions[$DocId] = [System.Collections.Generic.PriorityQueue[Object, Int32]]::new()
  }

  $VersionsQueue = $FileToVersions[$DocId]

  $VersionNumber = [Int32]::Parse($Version.MajorVersion) * 512 + [Int32]::Parse($Version.MinorVersion)
  $VersionsQueue.Enqueue($Version, -$VersionNumber)
}

$Schedule = [System.Collections.Generic.List[Object]]::new()

foreach ($FilesAndVersions in $FileToVersions.GetEnumerator())
{
  $VersionsQueue = $FilesAndVersions.Value
  $NumMajorVersionsSeen = 0
  while ($VersionsQueue.Count -gt 0)
  {
    $Version = $VersionsQueue.Dequeue()
    if ($NumMajorVersionsSeen -ge $MajorVersionLimit) {
      $Version.TargetExpirationDate = [DateTime]::new(2000, 1, 1).ToString("yyyy-MM-ddTHH:mm:ssK")
    }
     
    if ([int]::Parse($Version.MinorVersion) -eq 0) { $NumMajorVersionsSeen++ }

    $Schedule.Add($Version)
  }
}

$Schedule | 
  Export-Csv -Path $ExportPath -UseQuotes AsNeeded -NoTypeInformation

注:

PowerShell 7 を使用してコマンドを実行します。 PowerShell 7 は、次の手順に従ってインストールできます。 Windows への PowerShell のインストール - PowerShell |Microsoft Learn

count limits-b を含む手動のスクリーンショット。