PowerShell ScriptFind Largest (Or Smallest) Files In A Directory Or Drive With PowerShell

Here’s another quick tip for you. This is a simple script that sorts the largest files in a directory. We can take out the -Descending switch to change it to smallest.

# Get all files sorted by size.
Get-ChildItem -Path 'C:\SomeFolder' -Recurse -Force -File | Select-Object -Property FullName,@{Name='SizeGB';Expression={$_.Length / 1GB}},@{Name='SizeMB';Expression={$_.Length / 1MB}},@{Name='SizeKB';Expression={$_.Length / 1KB}} | Sort-Object { $_.SizeKB } -Descending | Out-GridView
Advertisements

PowerShell Script: Search and Delete Active Directory Users who have been inactive for 180 days

## Search Users that have been inactive for 180 days.
Search-ADAccount -AccountInactive -TimeSpan 180 | Select-Object Name, LastLogonDate, DistinguishedName, SamAccountName | Export-Csv C:\Temp\NoExpiration2016.csv

## Delete Users from the above script
Import-CSV C:\Temp\NoExpiration2016.csv | ForEach-Object {Remove-ADUser -Identity $SamAccountName -Confirm:$False}