How do I show a directory listing in 8.3 notation in PowerShell?
You can use WMI:
Get-ChildItem | ForEach-Object{
$class = if($_.PSIsContainer) {"Win32_Directory"} else {"CIM_DataFile"}
Get-WMIObject $class -Filter "Name = '$($_.FullName -replace '\\','\\')'" | Select-Object -ExpandProperty EightDotThreeFileName
}
Or the Scripting.FileSystemObject com object:
$fso = New-Object -ComObject Scripting.FileSystemObject
Get-ChildItem | ForEach-Object{
if($_.PSIsContainer)
{
$fso.GetFolder($_.FullName).ShortPath
}
else
{
$fso.GetFile($_.FullName).ShortPath
}
}
If you install the PSCX module you have the Get-ShortPath
cmdlet and you can do:
dir | Get-ShortPath
or
dir | Get-ShortPath | select -expa shortpath
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With