ConvertTo-ShortPath.ps1
<#PSScriptInfo
.DESCRIPTION Converts each element of a file object path to the 8.3 path and return the short path string. .VERSION 1.0 .GUID 6f926344-d186-4470-ab96-cea272bd5848 .AUTHOR Thomas Malkewitz @dotps1 .TAGS 8.3 .RELEASENOTES Intial Release. #> [OutputType([String])] Param ( [Parameter( ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true )] [Alias( 'FullName' )] [ValidateNotNull()] [String[]] $Path = $pwd ) Begin { $fso = New-Object -ComObject Scripting.FileSystemObject } Process { for ($i = 0; $i -lt $Path.Length; $i++) { try { if (($item = Get-Item -Path $Path[$i] -ErrorAction Stop).PSIsContainer) { $fso.GetFolder($item.FullName).ShortPath } else { $fso.GetFile($item.FullName).ShortPath } } catch { Write-Error -Message $_.ToString() } } } End { [Void][System.Runtime.InteropServices.Marshal]::ReleaseComObject($fso) Remove-Variable -Name fso } |