Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # CMDLikeDir.ps1
- # Show Dir output like CMD in Powerhsell
- If ($args[0] -eq "") {Throw "Path is required."; Exit}
- $path = $args[0]
- $exist = Test-Path $path
- If (!$exist) {Throw "The directory does not exist."; Exit}
- $Files = 0
- $Dirs = 0
- $report = ""
- $Letter = "$($path.SubString(0,1))"
- $Vol = Get-WMIObject -Query "Select VolumeName From Win32_LogicalDisk Where Caption='$($Letter):'" | ForEach {$_.VolumeName}
- $Serial = Get-WMIObject -Query "Select VolumeSerialNumber From Win32_LogicalDisk Where Caption='$($Letter):'" | ForEach {$_.VolumeSerialNumber}
- $FreeSpace = Get-WMIObject -Query "Select FreeSpace From Win32_LogicalDisk Where Caption='$($Letter):'" | ForEach {$_.FreeSpace}
- $report += " Volume in drive $($Letter) is $($Vol)`n Volume Serial Number is $($Serial)`n`n Directory of $($path)`n`n"
- Get-ChildItem -Path $path | Sort-Object Name | ForEach {
- $IsDir = $_.Attributes | Select-String "Directory" -Quiet
- If ($IsDir) {$Dir = "`<DIR`>`t"; $Dirs += 1} Else {$Dir = "`t"; $Files += 1}
- $report += "$($_.LastWriteTime)`t$($Dir)$($_.Length)`t$($_.Name)`n"
- $Size += $_.Length
- }
- $report += "`t$($Files) File`(s`)`t$($Size) bytes`n`t$($Dirs) Dir`(s`)`t$($FreeSpace) bytes free`n`n"
- Write-Host $report
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement