简体   繁体   中英

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. 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-blabla2

MSAVS-blabla3

etc..

I dont want any blank lines, DisplayName and ------- lines I want to get only the names of the GPOs

Thanks

Use Select-Object -ExpandProperty <String> for this:

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:

  • If the specified property is an array, each value of the array is included in the output.
  • If the specified property is an object, the objects properties are expanded for every InputObjec

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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