gpt4 book ai didi

powershell - 如何在PowerShell中查看 “alternatives”的属性?

转载 作者:行者123 更新时间:2023-12-03 01:22:52 26 4
gpt4 key购买 nike

使用

Get-ChildItem | Get-Member

我可以看到对象的方法和属性。但是我如何看到例如的不同可能值属性?我可以用
Get-ChildItem | Where-Object {$_.Attributes -ne "Directory"}

提取不是目录对象的对象,但是如何查看.Attributes的其他替代方法?

最佳答案

提供者属性PSIsContainer对于文件夹为true,对于文件为false,因此只能使用以下其中一项获取文件:

Get-ChildItem | Where-Object {$_.PSIsContainer -ne $true}

Get-ChildItem | Where-Object {!$_.PSIsContainer}

Get-ChildItem | Where-Object {-not $_.PSIsContainer}

至于Attributes属性,Get-Member的输出显示其类型名称(System.IO.FileAttributes),它是一个Enum对象:
PS> dir | gm attr*


TypeName: System.IO.DirectoryInfo

Name MemberType Definition
---- ---------- ----------
Attributes Property System.IO.FileAttributes Attributes {get;set;}

您可以通过以下方式获取其可能的值:
PS> [enum]::GetNames('System.IO.FileAttributes')
ReadOnly
Hidden
System
Directory
Archive
Device
Normal
Temporary
SparseFile
ReparsePoint
Compressed
Offline
NotContentIndexed
Encrypted

关于powershell - 如何在PowerShell中查看 “alternatives”的属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7633344/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com