Skip to content

Instantly share code, notes, and snippets.

@MyITGuy
Created September 9, 2025 21:43
Show Gist options
  • Select an option

  • Save MyITGuy/423397741fbea4fa53eb0b7e5b183418 to your computer and use it in GitHub Desktop.

Select an option

Save MyITGuy/423397741fbea4fa53eb0b7e5b183418 to your computer and use it in GitHub Desktop.
function Get-WindowsTempExtensionSummary {
[CmdletBinding()]
param (
[Parameter(Mandatory = $false, Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[string[]]
$ComputerName = $env:COMPUTERNAME
)
begin {
$ScriptBlock = {
$OutputObject = Get-ChildItem -Path $env:windir\temp -Recurse -File | Group-Object -Property Extension | ForEach-Object {
$FilesSize = $_.Group | Measure-Object -Sum Length | Select-Object -ExpandProperty Sum
if ($FilesSize -ne 0) {
$FilesSize = $FilesSize /1GB
}
$ExtensionName = $_.Name
if ([System.String]::IsNullOrEmpty($ExtensionName) -eq $true) {
$ExtensionName = 'none'
}
[pscustomobject][ordered]@{
Extension = $ExtensionName
Size = [math]::Round($FilesSize, 2)
}
}
$OutputObject | Sort-Object -Property Size -Descending
}
}
process {
$InvokeCommandSplat = @{
ScriptBlock = $ScriptBlock
}
Invoke-Command @InvokeCommandSplat -ComputerName $ComputerName | Select-Object -Property * -ExcludeProperty RunspaceId
}
end {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment