get-vmhost -name (esxhost.txt)
$domain = "domain.com"
any idea how to add the domain to the list in one line?
Is esxhost.txt a file with names in it?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
yes
host1
host2
etc...
ok got it
get-content esxhosts.txt | % { get-vmhost $_* }
another question,
I got a list of VMs that I am getting like this
get-vm -name (get-content vms.txt)
some are available while some are not.
How do I log the ones that are not available or not in vcenter inventory?
Something like this
try {
Get-VM -Name (Get-Content -Path vms.txt ) -ErrorAction Stop
}
catch {
$error[0].exception.tostring().Split("'")[1] | Out-File -FilePath .\vm-not-found.txt -Append
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
does the -ErrorAction stop stop the script at first error or should i use silentlycontinue?
No, that makes sure the Catch block is executed when the VM is not found
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
i is only logging 1 vm. where there are lots more
Indeed, the exception happens only once.
Then the only solution I see is to use a loop over the content of the TXT file
Get-Content -Path .\vms.txt |
ForEach-Object -Process {
try {
Get-VM -Name $_ -ErrorAction Stop
} catch {
$error[0].exception.tostring().Split("'")[1] | Out-File -FilePath .\vm-not-found.txt -Append
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference