Quantcast
Channel: VMware Communities : Discussion List - All Communities
Viewing all articles
Browse latest Browse all 193198

ps1 script read from txt

$
0
0

Hello there,

 

im experiencing first steps with scripting here.. I have a txt list of hosts, from which i need to run a command for each of them, to extract mac address of each virtual machine running.  I tried using the "GET-Content" or "foreach", however, its not going anywhere. I cant find proper way of "telling" the script to read the txt file for host IP.

Please help....

 

 

This is where i get so far...

 

#$VCServer = "x.x.x.x"
$VCUser = "user"
$VCPasswd = "passwd"
$File = "C:\API\list.txt"

 

Get-Content $File | foreach-Object
#foreach ($VCServer in $(cat C:\API\list.txt))

 

$VC = Connect-VIServer $File -User $VCUser -Password $VCPasswd
$Connection = @()
foreach($vm in get-networkadapter -vm "*"){
    $vm.Guest.Nics | %{
        $row = "" | Select macaddress, parent, parentid, uid, connectionstate
        $row.parent = $vm.parent
        $row.parentid = $vm.parentid
        $row.uid = $vm.uid
        $row.macaddress = $vm.MacAddress
        $row.connectionstate = $vm.connectionstate
        $Connection += $row
}}
$Connection | Export-Csv "C:\Temp\vmreport.csv" -NoTypeInformation -UseCulture


Viewing all articles
Browse latest Browse all 193198

Trending Articles



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