Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何自定义PowerShell中FileInfo对象的默认显示?_Powershell_Powershell 3.0 - Fatal编程技术网

如何自定义PowerShell中FileInfo对象的默认显示?

如何自定义PowerShell中FileInfo对象的默认显示?,powershell,powershell-3.0,Powershell,Powershell 3.0,下面的脚本显示了当我试图从FileInfo的输出中抑制Mode属性时发生的情况。我只感兴趣的是如何做这个脚本广泛。我不希望每次获得文件列表时都必须指定格式。根据我有限的理解,第二个Get Item c:\Windows\notepad.exe调用不应具有Mode属性。我试图用一个进程对象来检查这一点,但这没有什么意义。我没有深入研究这种方法之前的xml文件内容,但它看起来甚至没有模式属性。我不知道它是从哪里来的。谢谢 脚本: (Get-TypeData -TypeName System.IO.F

下面的脚本显示了当我试图从FileInfo的输出中抑制Mode属性时发生的情况。我只感兴趣的是如何做这个脚本广泛。我不希望每次获得文件列表时都必须指定格式。根据我有限的理解,第二个Get Item c:\Windows\notepad.exe调用不应具有Mode属性。我试图用一个进程对象来检查这一点,但这没有什么意义。我没有深入研究这种方法之前的xml文件内容,但它看起来甚至没有模式属性。我不知道它是从哪里来的。谢谢

脚本:

(Get-TypeData -TypeName System.IO.FileInfo).DefaultDisplayPropertySet.ReferencedProperties

Get-Item c:\Windows\notepad.exe | ft

Update-TypeData -Force -TypeName System.IO.FileInfo -DefaultDisplayPropertySet LastWriteTime,FileSize,Name
Update-TypeData -Force -TypeName System.IO.DirectoryInfo -DefaultDisplayPropertySet LastWriteTime,FileSize,Name
Update-TypeData -Force -TypeName System.IO.FileSystemInfo -DefaultDisplayPropertySet LastWriteTime,FileSize,Name

(Get-TypeData -TypeName System.IO.FileInfo).DefaultDisplayPropertySet.ReferencedProperties
Get-Item c:\Windows\notepad.exe | ft
输出:

Mode
LastWriteTime
FileSize
Name


    Directory: C:\Windows


Mode                LastWriteTime     Length Name                                                                                                                                                                                                                                                                                                                                                                                        
----                -------------     ------ ----                                                                                                                                                                                                                                                                                                                                                                                        
-a---          7/9/2015  12:13 PM     221184 notepad.exe                                                                                                                                                                                                                                                                                                                                                                                 


LastWriteTime
FileSize
Name


    Directory: C:\Windows


Mode                LastWriteTime     Length Name                                                                                                                                                                                                                                                                                                                                                                                        
----                -------------     ------ ----                                                                                                                                                                                                                                                                                                                                                                                        
-a---          7/9/2015  12:13 PM     221184 notepad.exe                                                                                                                                                                                                                                                                                                                                                                                 

奇怪的是,使用
remove-typedata-system.io.fileinfo
会删除值,但不会删除列。我试图修改
$pshome
文件夹中的一些*.ps1xml文件,删除
[fileinfo]
类型的所有
模式
引用,但没有成功。理论上,您需要创建一个带有所需视图描述的新*.format.ps1.xml文件,然后使用Update-FormatData cmdlet导入此视图。但这对我也不起作用。在运行Update FormatData后查看可用格式视图定义的列表时,我看到的只是内置视图的重复列表。我无法使PowerShell导入我的自定义视图。不过,在某些情况下,它似乎起到了作用: