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: