Get-ChildItem equivalent of DIR /X
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