Quantcast
Channel: VMware Communities : All Content - All Communities
Viewing all articles
Browse latest Browse all 176561

Get-VM: VM with name 'xyz' was not found using the specified filter(s).

$
0
0

Good afternoon everyone!

I have a script that reads a csv with several hostnames, connects to vCenter and should get the hostname information, ip and PortGroup to generate a CSV external file.
It happens that many cases vm does not exist in vCenter and returns me the error below:

 

get-vm : 07/04/2016 14:41:58Get-VM    VM with name 'pxl1sso00008' was not found using the specified filter(s).   

No C:\Users\f3135606\Desktop\vmTeste1.ps1:25 caractere:31

+ foreach ($vmName in $vmList) {get-vm $vmName| Select Name, @{N="Network"; e={ $_ ...

+                           ~~~~~~~~~~~~~~
+ CategoryInfo      : ObjectNotFound: (:) [Get-VM], VimException
+ FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM



How would I do to get the information from an input file, see the vCenter and if this positive results write the file ignoring errors. Ideally, if not find the machine, just create a line in the output file with only the hostname with the rest blank.

Follow .ps1 file:



$vmlist = Get-Content C:\vmnames.csv

if (!(Get-PSSnapin -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue))
{
Add-PSSnapin VMware*
Set-PowerCLIConfiguration -DisplayDeprecationWarnings $false -DefaultVIServerMode multiple -InvalidCertificateAction Ignore -Scope Session -ProxyPolicy NoProxy -Confirm:$false | Out-Null 
[void](Get-PSSnapin VMWare.VimAutomation.Core -ErrorVariable getVmwareSnapinErr 2> $null)
if ($getVmwareSnapinErr.Count -gt 0) {    Add-PSSnapin VMware.VimAutomation.Core }
}   
$VCconn = Connect-VIServer $vCenter -User $vUsuario -Password $vPass > $null    
foreach ($vmName in $vmList) {get-vm $vmName| Select Name, @{N="Network"; e={ $_ | get-networkadapter|Select-Object @{N="Network";E={$_.NetworkName}}} }, @{N="IP Address";E={@($_.guest.IPAddress[0])}}|Export-Csv –path c:\scripts\vlans.csv –NoTypeInformation}

Viewing all articles
Browse latest Browse all 176561

Trending Articles



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