简体   繁体   English

Output 所有 gpo 名称如 blabla 到文件

[英]Output all gpo where name like blabla to a file

I'm trying to create a script and a part of it should go to the domain, get all the GPO which names start with "MSAVS-" output that to a file and then in some other part of the script read it.我正在尝试创建一个脚本,它的一部分应该 go 到域,获取名称以“MSAVS-” output 开头的所有 GPO 到一个文件,然后在脚本的其他部分读取它。 problem is, when i do this code:问题是,当我执行此代码时:

Get-Gpo - all | Where-Object {$._DisplayName - like "MSAVS-*"} | Select-Object 
DisplayName | Output-File test.txt

I get the result like this:我得到这样的结果:

blank line空行

DisplayName显示名称

"-----------" “-----------”

blank line空行

MSAVS-blabla1 MSAVS-blabla1

MSAVS-blabla2 MSAVS-blabla2

MSAVS-blabla3 MSAVS-blabla3

etc.. ETC..

I dont want any blank lines, DisplayName and ------- lines I want to get only the names of the GPOs我不想要任何空行、DisplayName 和 ------- 行我只想获取 GPO 的名称

Thanks谢谢

Use Select-Object -ExpandProperty <String> for this:为此使用Select-Object -ExpandProperty <String>

Get-Gpo -All | Where-Object { $._DisplayName -like "MSAVS-*" } | Select-Object -ExpandPoperty "DisplayName" | Output-File test.txt

-ExpandProperty - Specifies a property to select, and indicates that an attempt should be made to expand that property: -ExpandProperty - 将属性指定为 select,并指示应尝试扩展该属性:

  • If the specified property is an array, each value of the array is included in the output.如果指定的属性是一个数组,则该数组的每个值都包含在 output 中。
  • If the specified property is an object, the objects properties are expanded for every InputObjec如果指定的属性是 object,则为每个 InputObjec 扩展对象属性

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM