Last active
August 27, 2024 22:14
-
-
Save MyITGuy/5b48c2f25ef4f433769b64d26b99a45c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$CMContentUpdateServicesPackageInfo = Get-CMContentUpdateServicesPackageInfo | |
$CMContentUpdateServicesPackageInfo | Where-Object { $_.IsSuperseded -eq $true -and $_.IsDeployed -eq $false } | Select-Object -Property Path, FileName, FolderSizeFriendly, DateRevised |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-CMContentUpdateServicesPackageInfo { | |
[CmdletBinding()] | |
param( | |
[Parameter(Mandatory = $false, Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] | |
[ValidateScript({ Test-Path $_ -PathType 'Container' })] | |
[string] | |
$Path = (Get-ItemPropertyValue -Path HKLM:"\SOFTWARE\Microsoft\Update Services\Server\Setup" -Name 'ContentDir') | |
, | |
[Parameter(Mandatory = $false, Position = 1, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] | |
[string] | |
$SiteCode = ((Get-CimInstance -ClassName SMS_Authority -Namespace root\ccm).Name.Split(':')[1]) | |
) | |
function ConvertFrom-BytesToText { | |
[CmdLetBinding()] | |
param( | |
[Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] | |
[long] | |
$Length | |
) | |
switch ( [math]::Max($Length, 0) ) { | |
{ $_ -ge 1PB } { "$([math]::Round($Length / 1PB, 2)) PB"; break } | |
{ $_ -ge 1TB } { "$([math]::Round($Length / 1TB, 2)) TB"; break } | |
{ $_ -ge 1GB } { "$([math]::Round($Length / 1GB, 2)) GB"; break } | |
{ $_ -ge 1MB } { "$([math]::Round($Length / 1MB, 2)) MB"; break } | |
{ $_ -ge 1KB } { "$([math]::Round($Length / 1KB, 2)) KB"; break } | |
{ $_ -eq 1 } { "${Length} byte"; break } | |
{ $_ -lt 1KB } { "${Length} bytes" } | |
} | |
} | |
try { | |
$UpdateServicesPackagesDir = Join-Path -Path $Path -ChildPath 'UpdateServicesPackages' | |
Get-ChildItem -Path $UpdateServicesPackagesDir -Directory | ForEach-Object { | |
$UpdateServicesPackageFolder = $_ | |
$SMS_SoftwareUpdate = Get-CimInstance -Namespace "root/sms/site_${SiteCode}" -Query "select * from SMS_SoftwareUpdate where CI_UniqueID = '$($UpdateServicesPackageFolder.Name)'" | |
$SMS_SoftwareUpdate | Add-Member -MemberType NoteProperty -Name "Path" -Value ( $UpdateServicesPackageFolder.FullName ) | |
$SMS_SoftwareUpdate | Add-Member -MemberType NoteProperty -Name "SupersedingUpdate" -Value $null | |
$SMS_SoftwareUpdate | Add-Member -MemberType NoteProperty -Name "SupersedingIsDeployed" -Value $false | |
$SMS_SoftwareUpdate | Add-Member -MemberType NoteProperty -Name "SupersedingDateRevised" -Value $null | |
$SMS_SoftwareUpdate | Add-Member -MemberType NoteProperty -Name "SupersedingGroup" -Value $null | |
if ($SMS_SoftwareUpdate.IsSuperseded -eq $true) { | |
$Superseding_CI_ID = Get-CimInstance -Namespace "root/sms/site_${SiteCode}" -ClassName SMS_CIRelation -Filter "RelationType = 6 AND ToCIID = '$($SMS_SoftwareUpdate.CI_ID)'" | Select-Object -First 1 -ExpandProperty FromCIID | |
$SMS_SoftwareUpdate.SupersedingUpdate = Get-CimInstance -Namespace "root/sms/site_${SiteCode}" -ClassName SMS_SoftwareUpdate -Filter "CI_ID = '${Superseding_CI_ID}'" | |
$SMS_SoftwareUpdate.SupersedingIsDeployed = $SMS_SoftwareUpdate.SupersedingUpdate.IsDeployed | |
$SMS_SoftwareUpdate.SupersedingDateRevised = $SMS_SoftwareUpdate.SupersedingUpdate.DateRevised | |
$SMS_SoftwareUpdate.SupersedingGroup = $SMS_SoftwareUpdate.SupersedingUpdate.DateRevised.ToString('yyyyMM') | |
} | |
$FileName = Get-ChildItem -Path "$($UpdateServicesPackageFolder.FullName)\*\*.*" -File | Where-Object Name -notmatch 'PatchMyPC' | Select-Object -First 1 -ExpandProperty Name | |
$SMS_SoftwareUpdate | Add-Member -MemberType NoteProperty -Name "FileName" -Value $FileName | |
$FolderSizeBytes = Get-ChildItem -Path $UpdateServicesPackageFolder.FullName -File -Recurse -Force | Measure-Object -Sum Length | Select-Object -ExpandProperty Sum | |
$SMS_SoftwareUpdate | Add-Member -MemberType NoteProperty -Name "FolderSize" -Value $FolderSizeBytes | |
$SMS_SoftwareUpdate | Add-Member -MemberType NoteProperty -Name "FolderSizeFriendly" -Value ( ConvertFrom-BytesToText -Length $FolderSizeBytes ) -PassThru | |
} | |
} catch { | |
throw $_ | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$CMContentUpdateServicesPackageInfo = Get-CMContentUpdateServicesPackageInfo | |
$CMContentUpdateServicesPackageInfo | Out-GridView |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$CMContentUpdateServicesPackageInfo = Get-CMContentUpdateServicesPackageInfo | |
$Properties = @() | |
$CMContentUpdateServicesPackageInfo | Group-Object -Property SupersedingGroup | ForEach-Object { | |
$Item = $_ | |
$Group = $_ | Select-Object -ExpandProperty Group | |
$Properties += [PSCustomObject][ordered]@{ | |
Group = @($Item.Name, 'NotSuperseded') | Where-Object { $_ } | Select-Object -First 1 | |
Count = $Item.Count | |
Size = ConvertFrom-BytesToText -Length (($Group | Measure-Object -Sum FolderSize).Sum) | |
} | |
} | |
$Properties += [PSCustomObject][ordered]@{ Group = 'Total'; Count = (($CMContentUpdateServicesPackageInfo | Measure-Object).Count); Size = (ConvertFrom-BytesToText -Length (($CMContentUpdateServicesPackageInfo | Measure-Object -Sum FolderSize).Sum)) } | |
$Properties |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment