Using Get-VMHost connected to an ESX vs. host connected to a VirtualCenter Server

Hello

The script here returns a list of paths storage dead but only works when you run against an ESX host. How can I adjust it to report on all ESX hosts, managed by a VirtualCenter Server?

$vc = Read-Host "enter the name or the IP address of your server VC."

SE connect-VIServer-Server $vc

Get-VMHost | Get-ScsiLun | Get-scsilunpath | Select Lunpath, Preferred SanID |

where {$_.} SanId - ine $null - and $_. State - eq 'Dead'}

Disconnect-VIServer-confirm: $false

I guess this is a loop in the sense of 'ForEach' ($VMhosts in Get-VMHost), but have been unable to come up with the appropriate syntax.

Any suggestions?

Thank you!

The following script will display the properties in the HTML file, as in the first script.

Shaped more away from the exit (separation of the column, frame, color...), you will need to use the HTML formatting.


$report = @()
Get-VMHost | Sort-Object -property Name | % {
     $server = $_
     ($_ | Get-View).config.storagedevice.multipathinfo.Lun | % {
          $preferred = $_.Policy.Prefer
          $_.Path | where {$_.PathState -eq "dead"} | % {
               $row = New-Object System.Object
               $row | Add-Member -memberType NoteProperty -name Server -value $server.Name
               $row | Add-Member -memberType NoteProperty -name LunPath -value $_.Name
               $row | Add-Member -memberType NoteProperty -name State -value $_.PathState
                      $IsPreferred = $false
               if($_.Name -eq $preferred){
                    $IsPreferred = $true
               }
               $row | Add-Member -memberType NoteProperty -name Preferred -value $IsPreferred
               $sanId = ""
               if($_.Transport.NodeWorldWideName -ne $null){
                    $sanId = "{0:x}" -f $_.Transport.NodeWorldWideName
                    for($i = $sanId.length-2 ;$i -ge 2; $i -= 2){$sanId = $sanId.insert($i,":")}
               }
               $row | Add-Member -memberType NoteProperty -name SanId -value $sanId
               $report += $row
          }

     }
}
$report | ConvertTo-Html -head "Dead Path's Found" | Out-File "C:\pathreport1.html"

Tags: VMware

Similar Questions

  • Get-vmhost | Connection status

    I am trying to delete all hosts in vc that have a status of "not responding".

    Get-vmhost * | WHERE-object {$_.} ConnectionState.Notresponding - eq "true"}

    but returns nothing

    Try

    Get-vmhost | WHERE-object {$_.} ConnectionState - eq "NotResponding"}

  • Get the LUN of the ESX host Info

    Hello:

    Is there a way to extract the info from the ESX host LUN?  I need (s) Lun sees number/ID to match the storage admin ID...

    Thank you very much!

    Of course, the easiest way is this

    $report = foreach($esx in Get-VMHost){
        foreach($hbaKey in ($esx.Extensiondata.Config.StorageDevice.ScsiTopology.Adapter | where {$_.Adapter -like "*FibreChannelHba*"})){
            if($hbaKey.Target){
                foreach($tgtKey in $hbaKey.Target){
                    foreach($lunKey in $tgtKey.Lun){
                        $hba = $esx.Extensiondata.Config.StorageDevice.HostBusAdapter | where {$_.Key -eq $hbaKey.Adapter}
                        $lun = $esx.Extensiondata.Config.StorageDevice.ScsiLun | where {$_.Key -eq $lunKey.ScsiLun}
                        Select-Object -InputObject $lun -Property @{N="Host";E={$esx.Name}},
                            @{N="HBA";E={$hba.Device}},
                            CanonicalName,DisplayName,@{N="LUN";E={$lunKey.Lun}}
                    }
                }
            }
        }
    }
    $report | Export-Csv "C:\lun-report.csv" -NoTypeInformation -UseCulture
    
  • Get-vmhost property

    If I run

    Get-data center | Get-VMHost | Select Name, Parent

    I've released as

    Name                                                       Parent
    ----                                                            ------

    SVR1.example.com Cluster 1

    SVR2.example.com Cluster 1

    SVR3.example.com Cluster 1

    SVR4.example.com host

    That's because my layout is as follows

    1 data centre

    -Group 1

    -svr1

    -svr2

    -svr3

    -svr4

    SVR4 is a stand-alone system in the data center.

    Running

    Get-data center | Get-VMHost |? { $_. Parent - eq 'host'}

    Returns nothing if I expect him back 'svr4 '.

    Get-data center | Get-VMHost |? { $_. Parent - only 'host'}

    Returns everything.

    Any ideas?

    Thanks in advance

    The Parent property points to a folder object, not a string with the name of the parent.

    If you do

    Get-data center | Get-VMHost |? { $_. Parent.Name - eq 'host'}

    You should see the result you expect.

    In the object of the file, there is a Name property (that has a string) that you can use in the where clause.

  • How to get ESX ip use get - vm-CLI

    I want to use the Get - vm command to get the ip of ESX, the sample is below, the but you can't find the EsxIP but the name of ESX, it may has a grammar error. Who can help me on this point, thank you

    I donot want to use the command get-vmhost, because it would be very slow

    Get-VM | Select Name,id, `
    @{Name=’ESXIP’;Expression={$_.VMHost | Select ($_.ExtensionData.Config.Network.Vnic | ? {$_.Device -eq "vmk0"}).Spec.Ip.IpAddress}}
    

    Hi, try this:

    Get-VM | Select Name, id, @{Name="IP"; Expression={$_.VMHost | Get-VMHostNetwork | Select -ExpandProperty VirtualNic |
    where {$_.PortGroupName  -match "pgManagement"} | Select IP}}
    

    Hope that this could be useful... pay attention to-match: substitute your correct portgroup

    Concerning

  • All of a sudden, after a update of firefox, I get "this connection is untrusted" for Facebook, no matter if I use http: or https:, WHY?

    All of a sudden, after a update of firefox, I get "this connection is untrusted" for Facebook, no matter if I use http: or https:, WHY? Here are all the details of the error message:

    This connection is Untrusted

    You asked Firefox to connect safely to facebook.com, but we cannot confirm that your connection is secure.

    Normally, when you try to connect safely, sites will present a reliable identification to prove that you're in the right place. However, the identity of this site cannot be verified.
    What should I do?

    If you normally connect to this site without problems, this error can mean that someone is trying to impersonate the identity of the site, and you should not continue.

    This site uses HTTP Strict Transport Security (HST) to specify that Firefox didn't connect safely. As a result, it is not possible to add an exception for this certificate.

    Facebook.com uses an invalid security certificate.

    The certificate is not trusted because the issuer certificate is unknown.

    (Error code: sec_error_unknown_issuer)

    (Also included a screenshot).

    COR - el said

    You can check the date and time and time zone in the clock on your computer: (double) click on the clock icon in the Windows taskbar.

    You can retrieve the certificate and check details such as WHO issued the certificates and the expiration dates of certificates.

    • Click on the link at the bottom of the error page: "I understand the risks".
    • Let Firefox recover the certificate: "Add Exception"-> "get certificate".
    • Click on the button "View" and inspect the certificate and the Coachman, who is the issuer.

    You can see more details like the intermediate certificates that are used in the Details tab.

    If you cannot inspect the certificate by "I understand the risks", then try this:

    Open the chrome URI by pasting or typing this URI in the address bar to open the window "Add the Security Exception" and to check the certificate:

    • chrome://pippki/content/exceptionDialog.XUL

    In the field location type and paste the URL of the Web site

    • retrieve the certificate via the button 'Get certificate '.
    • Click on the "view..." button. "to inspect the certificate in the certificate display

    Check which is the issuer of the certificate.

    You can get more details like the certificate chain in the Details tab of the certificate display.

  • I can't get my internet to open using my wireless connection, what should I check for?

    I can't get my internet to open using my wireless connection, what should I check for?

    Hi RosaSchiroo,

    1. are you able to access internet via wired connection?

    2. have you done any hardware changes or software on your computer before this problem?

    3. you receive an error message or code?

    You can follow this link and check if the problem persists.

    In the Windows wireless network connection problems

    Hope the helps of information.
    Please post back and we do know.

  • How to get the gif file hosted by using the Http connection?

    Hello

    I have an application that downloads animation gif from a server by using the http connection. Here is the code I use to download the image.

    try {
    
                httpConnection = (HttpConnection) Connector.open(url, Connector.READ_WRITE);            httpConnection.setRequestMethod(HttpConnection.GET);
    
                if (httpConnection.getResponseCode() == HttpConnection.HTTP_OK) {                DataInputStream dS = httpConnection.openDataInputStream();
    
                    byte[] data = new byte[dS.available()];                dS.read(data);
    
                    gifImage = (GIFEncodedImage) EncodedImage.createEncodedImage(data, 0,data.length);
    
                } else {                throw new Exception("ResponseCode:" + httpConnection.getResponseCode());            }        } catch (Exception e) {                        gifImage = null;            e.printStackTrace();        }
    

    the problem with this code is, when the gif file is 1175 bytes above, it does not load the gif.

    example:-If the gif on the server is 1500 bytes, this code retrieves only 1175 bytes.

    I think that the rest of the bytes are sent in a different package. But how to get them.

    can someone please provide a code for buffering the inputstream?

    any help is appreciated.

    Dieye

    Hmm, nobody seems to know how to do, it seems. Here's how I did it.

                httpConnection = (HttpConnection) Connector.open(url, Connector.READ_WRITE);
                httpConnection.setRequestMethod(HttpConnection.GET);
    
                int responseCode = httpConnection.getResponseCode();
                if (responseCode == HttpConnection.HTTP_OK) {
                    inputStream = httpConnection.openInputStream();
                    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    
                    byte[] buffer = new byte[256];
                    int len = 0, imageSize = 0;
    
                    while (-1 != (len = inputStream.read(buffer))) {
                        byteArrayOutputStream.write(buffer);
                        imageSize += len;
                    }
    
                    byteArrayOutputStream.flush();
                    byte[] imageData = byteArrayOutputStream.toByteArray();
                    byteArrayOutputStream.close();
    
                    gifImage = (GIFEncodedImage) EncodedImage.createEncodedImage(imageData, 0, imageSize);
    
  • I am using Acrobat Reader DC. I'm used to be able to open attachments to e-mail .pdf by double clicking on the attachment. Since there are a few days, it no longer works 't get an error message "Acrobat could not connect to a DDE server. However, I ca

    I am using Acrobat Reader DC. I used to be able to open .pdf attachments to an e-mail by clicking twice on the attachment. Since a few days it doesn't work like that.  I get a message error "Acrobat could not connect to a DDE server. I discovered a way around - I have to listen to samples and then double-click on before its opening. It's heavy. Can I avoid it? How can I just double click again?

    My BIG problem is with .pdf files already in my computer. Worse - these .pdf files open at all.

    @

    Please help me!

    Hi Eddie Otte,

    Please see this thread with a similar problem: I get the 'acrobat fail send a DDE command'

    Check if this helps you solve the problem.

    Kind regards

    Meenakshi

  • We have laptops in the field who use VPN to connect. How can I get these systems to update our DNS when they connect to the VPN?

    Our mobile sales are part of a domain but not connected to our network. Cached credentials are used to connect outside the office. Once they connect and view their desktops, they select the card from Verizon and use it to connect to our network via a VPN connection. These generally to enter an IP address but the router that connects and not from our DHCP server. This usually means that updates to our DNS servers are not always instantaneous (or update at all).

    When they are done for the day, they just closed the lid of the laptop and he starts in mode 'sleep'. The next day, they open the lid and no lgin is necessary, but they do not need to reconnect to the VPN through their cards from Verizon.  How can I configure my DNS to update more frequently or maybe these computers portable bécon a command "ipconfig/registerdns"?

    We have to connect to these systems in the field and it is almost impossible, unless we call the sales person and ask them their IP. We have more than 350 laptops in the field, then this makes it almost impossible to update all the.

    Hello

    Your question is more complex than what is generally answered in the Microsoft Answers forums. It is better suited for Windows XP on Technet. Please post your question in the Technet forums. You can follow the link to your question:

  • Using get-vicredentialstoreitem

    Hello

    Once more, my knowledge proved to be missed...

    I created a credential store that contains the passwords of local root for a number of guests. I can retrieve the credentials and connect to each host via CLI without any problem. I would do the same thing in a script, but it seems that I'm doing something wrong... As always, help would be greatly appreciated.

    This is the section that deals with the connections and credentials

    $hostESXlist = get-VMHost | where {$_.} ConnectionState - don't 'disconnected'} | where {($_ | get-vue).} Config.Product.ProductLineId - eq "embeddedESX"} | Tri-objet-name of the property

    {foreach ($row in $hostESXlist)

    $Creds = files get-VICredentialStoreItem-c:\scripts\credentials.xml

    $csvname is $customer + '_' + $row. '_' + Name + '.mef3', $date

    Remove-Item - Path $csvpath\$ csvname - force - confirm: $false

    If (!) () $vi.name - eq $row.name)) {}

    Write-Host "Please provide the logon credentials for ' $row. Name - foregroundcolor 'white '.

    $login is connect-VIServer-Server $row. Name - user root - password $Creds

    Si ( ! $?) {

    Write-Host - ForegroundColor red "Could not create file MEF $ ($row.name).»

    Write-Host - ForegroundColor red "($Error [0]) $".

    continue

    }

    }

    Here is the error:

    Cannot convert "System.Object []" to type 'System.String' required by the parameter "Password." Specified method is not supported.
    To: line: 53 char: 66
    + $login = connect-VIServer-Server $row. Name - user - root password < < < < $Creds

    See you soon

    I suspect you will need to use the Credential parameter rather than the user and password parameters.

    $login is connect-VIServer-Server $row. Name - Credential $Creds


  • get VMHost the advanced Configurations

    Hello

    Today, I tried to make a script that queries some advanced Configs of the Esx, but I don't know why I couldn't do a 'select-object value '.

    ##############################################

    $VMHosts = get-VMHost | Sort name | % {Get-view $_.} ID}

    $mycolHost = @)

    {foreach ($VMHost to $vmhosts)

    $myObjHostConf = "" | Select-Object VMHost, ServiceConsole, UseLunReset, UseDeviceReset, SchedNumReqOutstanding, Conflictretries, 'TCP '.

    Max heap', "TCP bunch", VMOverheadGrowthLimit

    $myObjHostConf.VMHost = $vmhost. Name

    ($myObjHostConf.ServiceConsole = : Round($vmhost.config.consoleReservation.ServiceConsoleReserved/1048576)

    $myObjHostConf.UseLunReset = get-VMHostAdvancedConfiguration - VMHost $vmhost. Name - name Disk.UseLunReset | Select-Object Value

    $myObjHostConf.UseDeviceReset = get-VMHostAdvancedConfiguration - VMHost $vmhost. Name - name Disk.UseDeviceReset | Select-Object Value

    $myObjHostConf.SchedNumReqOutstanding = get-VMHostAdvancedConfiguration - VMHost $vmhost. Name - name Disk.SchedNumReqOutstanding | Select-Object Value

    $myObjHostConf.Conflictretries = get-VMHostAdvancedConfiguration - VMHost $vmhost. Name - name Scsi.ConflictRetries | Select-Object Value

    $myObjHostConf. "" TCP bunch MAX "= get-VMHostAdvancedConfiguration - VMHost $vmhost. Name - name Net.TcpipHeapMax | Select-Object Value

    $myObjHostConf. "' Bunch TCP" = get-VMHostAdvancedConfiguration - VMHost $vmhost. Name - name Net.TcpipHeapSize | Select-Object Value

    $myObjHostConf.VMOverheadGrowthLimit = get-VMHostAdvancedConfiguration - VMHost $vmhost. Name - name Mem.VMOverheadGrowthLimit | Select-Object Value

    $mycolHost += $myObjHostConf

    }

    ####################################################################

    in this case, the select-object value are empty, the console works.

    If I search for 'values' I am more html @ output of {Values = System.Collections.Hashtable + ValueCollection}.

    but since the console I've specified configured the advanced settings

    What a mistake I made here? ;(

    thx a lot

    Max

    To retrieve the values of a hash, you must use the key as the index in the table table.

    Attached to your script has been fixed.

    Note that you do not have to call the cmdlet Get-VMHostAdvancedConfiguration every time, you can call it once and store the result in a variable.

    The script is attached from the SW forum has problems with hooks.

    ____________

    Blog: LucD notes

    Twitter: lucd22

  • Generate the CSV file to the virtual machine by using get-stat statistics

    Hi all

    I put my VC for taking samples every 5 minutes for 3 days.

    I would create a PowerCLI script that I can then run on an ad hoc basis to connect to my VC and to get the details for ALL of the virtual machines that are managed by this CR and fill in a CSV (c:\foo.csv):

    • Name of the virtual machine

    • The ESX VM host is currently sitting

    • total number of virtual processors assigned to VM

    • total memory allocated to the VM

    • memory active average used by the virtual machine in the 3 days using samples of 5 minutes

    • average mhz CPU used by VM spent 3 days using samples of 5 minutes

    I have attached a sample file XLS of CSV output should look like.

    If anyone can give me a code to achieve or get on well on my way, I would appreciate it a lot.

    Kind regards

    Alex

    OK, so what you want is something like this then?

    Get-VM | Where {$_.PowerState -eq "PoweredOn"} |
     Select Name, Host, NumCpu, MemoryMB,
               @{N="Cpu.UsageMhz.Average";E={[Math]::Round((($_ | Get-Stat -Stat cpu.usagemhz.average -Start (Get-Date).AddHours(-72) -IntervalMins 5 -MaxSamples (12) | Measure-Object Value -Average).Average),2)}},
               @{N="Mem.Usage.Average";E={[Math]::Round((($_ | Get-Stat -Stat mem.usage.average -Start (Get-Date).AddHours(-72) -IntervalMins 5 -MaxSamples (12) | Measure-Object Value -Average).Average),2)}}
    

    I think that the issue that you have with the missing stat might be to do with your logging levels in VC, if these are not set correctly it will not save these stats for this period of time.

    What do you get if you do a simple:

    get-vm "SingleVM" | Get-Stat -Stat cpu.usagemhz.average
    

    If you found this information useful, please consider the allocation of points for correct or helpful.

    Alan Renouf

    http://Virtu-al.NET

  • Get-vmhost and vmware server 2

    Hello

    I like to use the PowerGUI and VI Toolkit for vmware server 2. I can connect to the server, but where to get the information:

    C:\Program Files\VMware\Infrastructure\VIToolkitForWindows & gt; Get-VMHost

    Get-VMHost: specified Argument was out of the range of valid values.

    Parameter name: I

    On line: 1 char: 10

    Sneff Gabor

    VMware Server 2 is not in the list of platforms supported the VITK 1.5 Release Notes.

    Perhaps one of the VMware guys can develop on what can be done with the VITK and VMware Server 2?

  • Format-Table &amp; Get-VMHost properties...

    I'm missing something.  I worked on it on and off for the last two days and may not know what I'm doing wrong here.  My goal is to ultimately develop a script of checking my environment, using the VI Toolkit.

    $scReserved = @{label = 'Reserved'; Expression = {(Get-View-id (Get-vue $_).)} {{(ConfigManager.MemoryManager). ConsoleReservationInfo.ServiceConsoleReserved)}}

    Get-VMHost | FT name, $scReserved

    It does not work.

    I have a way to get this info by following these steps, even though I wish I could use Format-Table instead.  Why it does not work and what don't understand me in how to make these Expressions?

    However, this work is not a friendly game to be saved to a file or use the Format-Table.

    $hosts = get-VMHost | Get-View

    {foreach ($hostview in $hosts)

    $mem get-view-id $hostview. ConfigManager.MemoryManager

    $h = $hostview. Name + ', ' + $mem. ConsoleReservationInfo.ServiceConsoleReserved

    Write-Host $h

    }

    PowerShell me likes it.

    The curly braces and parentheses are not balanced

    This example will do what I think you were trying to do

    
    $scReserved = @{Label = "Reserved"; Alignment = "Left";
                 Expression={(Get-View -Id $_.ConfigManager.MemoryManager).ConsoleReservationInfo.ServiceConsoleReserved}}
    
    Get-VMHost  | Where-Object {$_.State -eq "Connected"} |
      Get-View |
      ft @{Label = "Name"; Expression = {$_.Name}; Width = 20}, $scReserved
    

    Note that I added a Where-Object cmdlet for the tip because you cannot get the value of memdory reserved for guests who are not connected.

    To show that the hash table is used for formatting objects, I added a few other keys (alignment, width) to the hash table.

Maybe you are looking for

  • I need help to install adobe flash for my G5 mac

    I need help to install adobe flash for my MAC OS X 10.4.11, I visited site and its telling me to upgrade my adobe flash, I really need help.

  • Download free realplayer

    not to fund my realplayer

  • Restore the default Start Menu

    Hello. I asked an unusual question that I didn't have an answer to and it intrigued me to search my curiosity got the best of me. So here goes. How to restore the default Start Menu on the start of OS Windows XP and earlier versions?  On the new oper

  • BlackBerry Smartphones how do you get Lotus Notes?

    I Lotus notes 7 to work and do not know how to get this on my storm? anyone has any ideas. I went through the installation program but his application a company password? Sorry very new to BB

  • BlackBerry Smartphones BBM 7

    I don't quite understand availability BBM 7 Voice Chat, what makes you unavailable? Can someone please clarify