Get-ChildItem 相当于 DIR/X [英] Get-ChildItem equivalent of DIR /X

查看:59
本文介绍了Get-ChildItem 相当于 DIR/X的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 PowerShell 中以 8.3 表示法显示目录列表?

How do I show a directory listing in 8.3 notation in PowerShell?

推荐答案

您可以使用 WMI:

Get-ChildItem | ForEach-Object{
    $class  = if($_.PSIsContainer) {"Win32_Directory"} else {"CIM_DataFile"}
    Get-WMIObject $class -Filter "Name = '$($_.FullName -replace '\\','\\')'" | Select-Object -ExpandProperty EightDotThreeFileName
}

或者 Scripting.FileSystemObject com 对象:

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
    }    
}

这篇关于Get-ChildItem 相当于 DIR/X的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆