[英]How can I sort and display groups when using dsquery in powershell?
I am using this line of code in powershell and it works but it displays too much. 我在powershell中使用这一行代码,它可以工作,但显示太多。 I am trying to find and display where the group that contains "Avecto" in the name. 我正在尝试查找并显示名称中包含“ Avecto”的组的位置。
dsquery user -samid MyUSerName| dsget user -memberof | dsget group -samid
Is there anyway to add that on this script statement? 无论如何,要在此脚本语句上添加它吗?
Use the where
keyword in PS (shorthanded here as ?
) 在PS中使用where
关键字(此处缩写为?
)
dsquery user -samid MyUSerName| dsget user -memberof | dsget group -samid | ? {$_ -match 'avecto'}
So it would read where each item in the pipeline matches the string 'Avecto' 因此它将读取管道中每个项目与字符串“ Avecto”匹配的位置
You could store the data into a variable and manipulate further, as just a simple Object array will be returned if more than one result, otherwise in a single result it will just be a string 您可以将数据存储到变量中并进行进一步操作,因为如果有多个结果,则仅返回一个简单的Object数组;否则,在单个结果中,它将只是一个字符串
Hope that helps 希望能有所帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.