Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Friday, June 6, 2014 1:48 AM
I am using following command to generate text file of all Windows servers that are powered on
Get-Vm where {$_.guest -match 'windows'} | where {$_.PowerState -eq 'PoweredOn'} | Out-File D:\Scripts\SL.txt
This generates list with following information :
Name PowerState Num CPUs Memory (MB)
What I really want is to generate list with name ONLY and and omit PowerState Num CPU's Memory.
Yasar
All replies (7)
Friday, June 6, 2014 3:59 AM ✅Answered
Okay, that's doable too. You just need to use -ExpandProperty:
Get-VM |
Where {$_.Guest -match 'windows'} |
Where {$_.PowerState -eq 'PoweredOn'} |
Select -ExpandProperty Name |
Out-File D:\Scripts\SL.txt
Don't retire TechNet! - (Don't give up yet - 12,950+ strong and growing)
Friday, June 6, 2014 4:28 AM ✅Answered
You can adjust the where clause for that. This should work, but I can't test this though:
Get-VM |
Where { $_.Guest -like '*Windows*' -and $_.Guest -notlike '*XP*' -and $_.Guest -notlike '*7*' } |
Where {$_.PowerState -eq 'PoweredOn'} |
Select -ExpandProperty Name |
Out-File D:\Scripts\SL.txt
Don't retire TechNet! - (Don't give up yet - 12,950+ strong and growing)
Friday, June 6, 2014 2:59 AM
Hi,
You can pipe through select-object before out-file to return only the property you're interested in:
Get-VM |
Where {$_.Guest -match 'windows'} |
Where {$_.PowerState -eq 'PoweredOn'} |
Select Name |
Out-File D:\Scripts\SL.txt
Don't retire TechNet! - (Don't give up yet - 12,950+ strong and growing)
Friday, June 6, 2014 3:49 AM
Thanks Mike
That works too only I want to avoid the heading itself being included in the text file, in other words :
Name < Exclude
< Exclude
VM1
VM2
VM3
I did find that Get-Vm | where {$_.guest -match 'windows'} | where {$_.PowerState -eq 'PoweredOn'} | Format-Wide -Column 1 | Out-File D:\Test\SL.txt will also do similar which is great learning PS as I go but how to exclude this not sure. Reason : I am running script to read sl.txt which is list of my VM, and then query drive space and email HTML report. If I have other parts then script run but has some errors
Yasar
Friday, June 6, 2014 4:03 AM
Fantastic thank you very much, any chance I can exclude VM with guest OS that are Xp and Win7 ?
Yasar
Friday, June 6, 2014 4:38 AM
Terrific thanks for help ! getting to understand logic now much better slowly but surely :)
Yasar
Friday, June 6, 2014 4:43 AM
Cheers, you're very welcome.
Don't retire TechNet! - (Don't give up yet - 12,950+ strong and growing)