以下命令:
Get-ChildItem | Get-Member
System.IO.DirectoryInfo表明 和上当然有很多属性System.IO.FileInfo。
但是,当以交互方式运行时,仅显示属性Mode、LastWriteTime、Length和。这些也是通过管道传输到或Name时显示的属性。Get-ChildItemFormat-TableOut-GridView
我的问题是,有没有办法以编程方式获取任何给定对象的这些默认属性的名称?即像这样:
Get-DefaultProperties @(Get-ChildItem)[0]
Run Code Online (Sandbox Code Playgroud)
应在数组中返回以下内容:Mode LastWriteTime Length Name
什么Get-Content真正输出,一个字符串或一个具有多个属性的对象?如果它是一个对象,哪个属性包含字符串,我可以修改该属性吗?该文件只有一行,所以我不必处理对象数组。
PS C:\Users\me> Get-Content input.txt 111 PS C:\Users\me> Get-Content input.txt | 选择对象 * PSPath : C:\Users\me\input.txt PSParentPath : C:\Users\me PSChildName : 输入 驱动器:C PSProvider : Microsoft.PowerShell.Core\FileSystem 读取计数:1 长度 : 3 PS C:\Users\me> (Get-Content input.txt).GetType() IsPublic IsSerial 名称 BaseType —————————————————— 真真字符串 System.Object
-replace 擦除除长度以外的所有额外属性:
PS C:\Users\me> (Get-Content input.txt) -replace 111, 222 | 选择对象 *
长度
------
3