Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 240675

Easy one - dumping VM names to a text file

$
0
0

Hey folks, I am trying to write a script, one of the parts of it needs to get the names of all the VM's and write them to a text file.

However, I want nothing but the server names in the text file.

 

Here is what I have tried:

 

Get-VM | Select-Object Name | Out-File "C:\servers.txt"

 

This yields a text file as follows:


Name                                                                                                                                                                                                                                      
----                                                                                                                                                                                                                                      
SERVER1


SERVER 2

 

....and so on. Close, but the empty line between server names and the "Name ----"  lines need to go.

 

Next I tried

$VMs = Get-VM | Select-Object Name

Add-Content - Path "C:\servers.txt" $VMs

 

This yields a text file as follows:

 

@{Name=SERVER1}
@{Name=SERVER2}

 

..and so on.. I dont want the @{Name=}  parts

So I'm close but I just want each server name on one line and no other text or empty lines. Example of what I want is:

 

SERVER1

SERVER2

SERVER3

 

ect...ect...thoughts on how I can strip out the other things?


Viewing all articles
Browse latest Browse all 240675

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>