Public/Get-KritTcmSnapshot.ps1
|
function Get-KritTcmSnapshot { <# .SYNOPSIS Get TCM snapshot job(s). List all when -JobId omitted, or fetch specific job. .EXAMPLE # All snapshot jobs in tenant Get-KritTcmSnapshot .EXAMPLE # Specific job + wait for completion $job = New-KritTcmSnapshot do { Start-Sleep 30; $status = Get-KritTcmSnapshot -JobId $job.Id; " Status: $($status.Status)" } while ($status.Status -notin 'completed','failed') #> [CmdletBinding()] param( [Parameter(ValueFromPipelineByPropertyName)][Alias('Id')][string]$JobId, [string]$Select = 'id,displayName,description,status,resources,resourceLocation,createdDateTime,completedDateTime,errorDetails,createdBy' ) process { $uri = if ($JobId) { "https://graph.microsoft.com/v1.0/admin/configurationManagement/configurationSnapshotJobs/$JobId" } else { 'https://graph.microsoft.com/v1.0/admin/configurationManagement/configurationSnapshotJobs' } if ($Select) { $uri = '{0}?$select={1}' -f $uri, ([uri]::EscapeDataString($Select)) } $r = Invoke-MgGraphRequest -Method GET -Uri $uri if ($JobId) { [PSCustomObject]@{ Id=$r.id; Status=$r.status; DisplayName=$r.displayName; Resources=$r.resources; Created=$r.createdDateTime; Completed=$r.completedDateTime; ResourceLocation=$r.resourceLocation; RawResponse=$r } } else { @($r.value | ForEach-Object { [PSCustomObject]@{ Id=$_.id; Status=$_.status; DisplayName=$_.displayName; Resources=$_.resources; Created=$_.createdDateTime; Completed=$_.completedDateTime; ResourceLocation=$_.resourceLocation } }) } } } |