PowerCLI script for peripheral target HBA paths

I need to quickly check the guests in my groups, see all of them have the right number of targets, the devices and the HBA paths. I can see this information in vCenter. Not an easy task if you have 100 + guests. Someone at - it script PowerCLI for this info?

Before 4.1 PowerCLI builds it takes only a small adjustment.

$esx = Get-VMHost 

foreach($hba in (Get-VMHostHba -VMHost $esx -Type "FibreChannel")){
     $target = ((Get-View $hba.VMhost).Config.StorageDevice.ScsiTopology.Adapter | where {$_.Adapter -eq $hba.Key}).Target
     $luns = Get-ScsiLun -Hba $hba  -LunType "disk"
     $nrPaths = ($target | %{$_.Lun.Count} | Measure-Object -Sum).Sum

     Write-Host $hba.Device "Targets:" $target.Count "Devices:" $luns.Count "Paths:" $nrPaths
}

____________

Blog: LucD notes

Twitter: lucd22

Tags: VMware

Similar Questions

  • PowerCLI script for VMFS datastore list with ID NAA and latency?

    Hi all

    Can anyone here please share a script, or help me to change the PowerCLI to display the store name of VMFS data, capacity and NAA.ID and latency in the past 24 hours?

    So far I can only use the WHowe script below:

    $esxName = "PRODESXi10".

    SE PRODVCENTER01-connect-VIServer-Server "VM".

    New-VIProperty-name lunDatastoreName - ObjectType ScsiLun-Value {}

    Param ($LUN)

    $ds = $lun. VMHost.ExtensionData.Datastore | % {Get-view $_} | `

    where {$_.} Summary.Type - eq "VMFS" - and

    (_.Info.Vmfs.Extent $ |) where {$_.} DiskName - eq $lun. CanonicalName})}

    {if ($DS)}

    $ds. Name

    }

    } - Force | Out-Null

    Get-VMHost-name $esxName | Get-ScsiLun | Select CanonicalName, CapacityMB, lunDatastoreName

    Thanks in advance,

    But you easily add a timestamp.

    Get-Datastore.

    Select Name,

    @{N = "DateTime"; E = {Get-DateTime}},

    @{N = "CanonicalName"; E = {$_.ExtensionData.Info.Vmfs.Extent [0].} DiskName}},

    @{N = 'Latency'; E = {}

    $esx = @(get-View-Id $_.) ExtensionData.Host.Key | Get - VIObjectByVIView)

    $instance = $_.ExtensionData.Info.Vmfs.Uuid

    $stat = 'datastore.totalReadLatency.average ','datastore.totalWriteLatency.average '.

    $stats = get-Stat-entity $esx - Stat $stat - Realtime - MaxSamples 1 - Instance $instance

    ($stats |) Measure-object-property - average value. Select - ExpandProperty average) /($esx.) Count * 2)

    }}

  • PowerCLI script for datacenter clusters and is, ANDS vm guests in a CSV file.

    HI -.

    I need help to write a script powercli that collect information vcenter such as the list of each Datacenter and its clusters, hosts and vm in a CSV file.

    Thanks in advance!

    -Philippe.

    You can do something like this.

    But be aware that it will not report VMHost, Clusters and data centers that do not have any virtual computer in them.

    {foreach ($dc in Get-Data Center)

    foreach ($cluster Get-cluster-location $dc) {}

    foreach ($esx in Get-VMHost-location $cluster) {}

    Get-VM-location $esx |

    Select @{N = 'Center'; E = {$dc. Name}},

    @{N = "Cluster"; E = {$cluster. Name}},

    @{N = "$vmhost"; E = {$esx. Name}}, name

    }

    }

    }

  • PowerCLI script for the deployment of virtual machines via the model using customizations comments

    Hello... I hope someone can give me a script that will do the following:

    (1) provision VMs in vCenter template (I need 125 + VMs created in the next day or two)

    (2) use the existing customizations of comments in vCenter

    (3) let me enter data warehouses available to be created on the virtual machines.  Example: I want that VMs on warehouses of specific data as LUN2, LUN5, LUN6, LUN12, LUN1, etc...  However, the script must have the ability to know when a data store is near the threshold of capacity, say 90%, so it can use one of the other warehouses available, identified in the script... similar to storage profiles.  We still have to adopt profiles storage but plan to do so once upgraded us to v5.1 in the next month or two.  We hope that this will help us keep our replicated LUN more organized during the use of SRM and copy to remote groups, our team of storage's configuration on 3PAR.


    Additional information: I will use 2 styles... Windows XP and Win7.  Their respective sizes are 40 and 60 GB due to all applications for stable DR.  Data warehouses are ea 500 GB.

    Please let me know if additional information is necessary... Thank you!!!

    Charles

    No, unfortunately you cannot specify a folder like this.

    You'll have to do a

    $folder = get-file-name WinXP

    New-VM-$folder file...

    Remove the line of New - VM WhatIf switch if you really want to start creating virtual machines.

  • PowerCLI script for join ESXi hosts to Active Directory

    Is there a script that I can run to join the ESXi hosts Active Directory?  I have over 100 guests that I need to join AD and want to add it script instead of using the GUI VC.

    Thank you!

    Matt

    You can browse all of your servers, but you would need to make fully automated, is get the credentials somewhere.

    You have different passwords on all ESXi servers?

    In this case, you could do something like that

    $cred = get-Credential # prompt for user and password

    Get-VMHost | Set-VMHostADDomain -ADJoin:$true -Domain$domain-Credential $cred

    If you do not have the same account/password for all servers ESXi, you want probably asked for each host.

    You could possibly temporarily store in a file and read this file.

    $accounts = @ {}

    Import-Csv "C:\accounts.csv" | %{

    $accounts [$_.hostname] = $_.password

    }

    Get-VMHost | Set-VMHostADDomain -ADJoin:$true -Domain$domain-User root -Password $accounts[$_.Name]

    The CSV file contains 2 columns, called host name and the other called password.

    We read the CSV file and store the passwords in a hash table, where the host name is the key.

    We use the hash table to fetch the password of the Set-VMHostADDomain cmdlet tree.

  • PowerCLI script for DatastoreCluster, data warehouses and the size info, DataCenter, Clusters

    Hello - I am looking to remove the DatastoreClusters and then list data warehouses as well with their size (total size, used space, free space, put in service, uncommitted space) and the total number of virtual machines on this data store. I would also like to understand what data center and they are on clusters. Is this possible? I might want to limit what is displayed in data warehouses that are 13 percent of free space or less.

    Thank you

    LORRI

    Of course, try this way

    Get-Datastore.

    Select @{N = 'Center'; E={$_. Datacenter.Name}},

    @{N = "DSC"; E = {Get-DatastoreCluster - Datastore $_______ |} {{Select - ExpandProperty name}}.

    Name,CapacityGB,@{N='FreespaceGB'; E = {[math]: tour ($_.)} (FreespaceGB, 2)}},

    @{N = "ProvisionedSpaceGB"; E = {}

    [math]: Round (($_.)) ExtensionData.Summary.Capacity - $_. Extensiondata.Summary.FreeSpace + $_. ExtensionData.Summary.Uncommitted)/1GB,2)}}.

    @{N = "UnCommittedGB"; E = {[math]: tour ($_.)} ExtensionData.Summary.Uncommitted/1GB,2)}}.

    @{N = "VM"; E={$_. ExtensionData.VM.Count}} |

    Export Csv report.csv - NoTypeInformation - UseCulture

  • PowerCli script prompts for user input

    Hello

    Below powercli script prompt for user input. Don't know how to fix it. I don't want it calls for the release of the user, as I am the code as part of the largest script runinng. How can I run in silent mode? Any help would be very happy.

    function VMHostDiskDetails {}

    $DateVar = get-date - uformat "% Y-%m-%d_%I.%M.%S.%p".

    $VMHosts = get-VMHost # get all the VM host

    $Datastores = $VMHosts | Get-Datastore # get the info from the data store for all VMHosts

    $VMHostStorage = $VMHosts | ForEach-Object {#Then, for each VMHosts, download the VMHostName

    $VMHost = $_. Name

    $_ | Get-VMHostStorage | Select-Object - expandProperty FileSystemVolumeInfo | `

    {ForEach-Object

    $VMHostStorageName = $_. Name

    Add-Member - InputObject $_ - MemberType NoteProperty-name FreeSpaceMB-value ($Datastores |) Where-Object {$_.} Name - eq $VMHostStorageName}). FreeSpaceMB - PassThru | `

    Add-Member - MemberType NoteProperty-Name HostName-value $VMHost - PassThru

    Add-Member - MemberType NoteProperty-name TimeStamp-value $DateVar

    }

    }

    $VMHostStorage | Select the host name, name, mode, Type, capacity, FreeSpaceMB, path, TimeStamp | Export-Csv VMHostStorage.csv - notype

    }

    VMHostDiskDetails

    Thank you

    M

    The 2nd line Add-Member does not have the object on the pipeline.

    The 3rd line Add-Member had a parameter - PassThru.

    function VMHostDiskDetails {
    
         $DateVar = get-date -uformat "%Y-%m-%d_%I.%M.%S.%p"
    
         $VMHosts = Get-VMHost mmmstv004* # Get all the VM-Hosts
         $Datastores = $VMHosts | Get-Datastore # Get the Datastore info for all the VMHosts
    
         $VMHostStorage = $VMHosts | ForEach-Object { #Then, for each VMHosts, get the VMHostName
              $VMHost = $_.Name
    
              $_ | Get-VMHostStorage | Select-Object -expandProperty FileSystemVolumeInfo | `
    
              ForEach-Object {
                   $VMHostStorageName = $_.Name
                   Add-Member -InputObject $_ -MemberType NoteProperty -Name FreeSpaceMB -Value ($Datastores | Where-Object {$_.Name -eq $VMHostStorageName}).FreeSpaceMB -PassThru | `
                   Add-Member -MemberType NoteProperty -Name HostName -Value $VMHost -PassThru | `
                   Add-Member -MemberType NoteProperty -Name TimeStamp -Value $DateVar -PassThru
    
              }
         }
    
         $VMHostStorage | Select HostName,Name,AccessMode,Type,Capacity,FreeSpaceMB, Path, TimeStamp | Export-Csv VMHostStorage.csv -notype
    }
    
    VMHostDiskDetails
    

    ____________

    Blog: LucD notes

    Twitter: lucd22

  • PowerCli for information of HBA Firmware

    Dear Sir

    Kindly share a PowerCLI script to find a Version of Firmware HBA Fibre Channel, Version of the driver, BIOS version and version FCODE.

    Concerning

    Rajesh

    Based on this output, it seems that you need to replace the enic and the fnic with elxnet and qlnativefc.

  • Collection for the PowerCLI scripting requirements

    Someone at - it a good model that helps you organize information, gathering process when you go to the management or to a customer to get for scripts and automation requirements that they want to do?  Y at - it a Web page or a book that puts this kind of thing in a structured methodology or at least one practical how to guide?

    For example, what kinds of questions should I go to make sure that I understand any of my script is supposed to do and help the management or the customer understand what THEY want to do, and get a consensus agreement on the functional requirements for my powerCLI script?

    Your suggestions of entry, welcome masters strategies.

    This question is not really unique for PowerCLI scripting, but all scripts/programs, to write (for yourself or for a customer |).

    And of course, there are always the classic answer "it depends".

    If it is a small task that you write yourself, the requirements are pretty obvious.

    Most of the time, you have the requirements in your head, but it does not have to write in schematic form.

    When you write for a customer, by definition be more formal (I guess).

    An article I like, is the Introduction to gather our creative use cases and requirements published in the Code review.

    Take a look.

  • GUI for the PowerCLI scripting

    Someone knows a software or tool that generate the GUI for the PowerCLI scripting?

    There are a few, Sapien is free and it's called PrimalForms Community Edition.

  • Need a developer for the script: distribute symbols on a path and rotate

    Hi all

    I need an Illustrator script to distribute a collection of different symbols on a trace. The symbols must be distributed from the beginning at the end of the path and separated by a proportional space between them. In addition, each symbol should be turned pointing to an object "look."

    Please look at the picture as an attachment for more information.

    path.jpg

    Any help will be appreciated. I know that nobody is here to develop scripts for free so let's talk

    @carlostelemaco

    I am happy.

    But the script "Divide (length)" works for each segment.

    So it is not usable for the purpose which divides all the way having different lengths of segments.

    I wrote a script to process 1 and 2.

    However, it is a little rough implementation for now.

    Please try this.

    http://shspage.com/aijs/af_distributeOnThePath.zip

    @W_J_T, @pixxxel schubser, @CarlosCanto

    Thank you. Let's have fun with the script!

  • PowerCLI script to migrate virtual machines to the new vCenter environment

    Hello world

    in the next few weeks, we need about migrate 700 VMs (Windows/Linux) server to a new environment (new vCenter, new hosts, but VMs will remain on same data warehouses). VMs will be migrated not in one batch, but rather from time to time (which, however, can understand the need to migrate some 10s of virtual machines at the same time).

    Cluster names and folder structure will be identical to the old and the new vCenters. As host in the new vCenter names differ from those in the old vCenter, thought to provide a table of 'translation', which tells the script to save a given VM on host B (new vCenter) when having been registered in order to host a (old vCenter) and so on.

    I thought writing a PowerCLI script which, broadly speaking, can accomplish the following steps:

    • Connect to vCenterOld and vCenterNew
    • Correspondence table of host to read from a file (see step "register VM vCenterNew below)

    Then, in a loop:

    • Ask VM name
    • Get the settings of the virtual machine: Datastore/path, network/Portgroup, HA restart priority, host, folder, note
    • View the parameters and the VM name and request confirmation migrate the virtual machine
    • Turn off VM (closed OS gracefully, but force power off if power status is still not equal 'off' after a time given)
    • To unsubscribe from VM vCenterOld (removal of inventory)
    • Registry of the VM to the data store vCenterNew (assumptions: same folder as vCenterOld, host names are different, but for each source in vCenterOld host a host of destination in vCenterNew for you join the virtual machine to can be provided, that is, CSV)
    • The value of VM portgroup (same name as in vCenterOld)
    • Set VM HA restart priority
    • PowerON VM
    • Wait / check the VM (for example, ping) connectivity / continue immediately if the virtual machine is accessible or after a certain time if the virtual machine is still inaccessible
    • Confirm that the virtual machine has been migrated successfully, OR ask the user to check the connectivity of the virtual machine

    Now to my questions:

    • Is anyone know about an existing script that does something similar or contains parts that can be useful to compile a script like this?
    • How can vCenter two connections at the same time been managed within a PowerCLI script - or doesn't work at all and a connect/disconnect to/from the two vCenters must be completed for each virtual computer?

    Many thanks for any help.

    The following seems to work for me

    $vm = Get-VM -Name MyVM$nic = Get-NetworkAdapter -VM $vm $vdPG = $nic | select -ExpandProperty NetworkName
    
    Get-VDPortgroup -Name $vdPG
    
  • I want to move virtual machines to a folder called Linux name, but we have several file of the same name in our Datacenter, please give me PowerCLI Script to move exactly

    I want to move virtual machines to a folder called Linux name, but we have several file of the same name in our Datacenter, please give me PowerCLI Script to move exactly.

    I tried to use for the function FolderByPath below, but don't know how to use it and have worked. Please help me in this.

    Function Get-FolderByPath {}

    < #.

    . Records of recovery SYNOPSIS by giving a path

    . DESCRIPTION the function will retrieve a record by its

    path. The path can contain any type of leave (folder or)

    Data Center).

    . Author NOTES: Luc relaxing

    . Path PARAMETER

    The path to the folder.

    This is a required parameter.

    . Path PARAMETER

    The path to the folder.

    This is a required parameter.

    . PARAMETER separator

    The character used to separate the leaves in the

    path. The default value is ' / '.

    . EXAMPLE OF

    PS > Get-FolderByPath-path ' Datacenter/Folder1/Folder2 ".

    . EXAMPLE OF

    PS > Get-FolderByPath-path "Folder1 > Folder2"-separator ' > '

    # >

    (param

    [CmdletBinding()]

    [parameter (Mandatory = $true)]

    [System.String []] ${Path}.

    [tank] ${delimiter} = ' / '.

    )

    {in process

    If (((Get-PowerCLIConfiguration).)) DefaultVIServerMode - eq "Multiple") {}

    $vcs = $defaultVIServers

    }

    else {}

    $vcs = $defaultVIServers [0]

    }

    {foreach ($vc to $vcs)

    {foreach ($strPath in $Path)

    $root = get-file-name of the server data $vc centers

    $strPath.Split ($Separator) | %{

    $root = get-inventory-name $_-location $root - server $vc - NoRecursion

    If ((Get-stocks-localisation $root-NoRecursion |)) Select--ExpandProperty name)-contains "vm") {}

    $root = get-inventory-name "vm" - location $root - server $vc - NoRecursion

    }

    }

    $root | where {$_-is [VMware.VimAutomation.ViCore.Impl.V1.Inventory.FolderImpl]}|% {}}

    Get-file-name $_. Name - location $root. Parent - Server $vc

    }

    }

    }

    }

    }

    You can try to retrieve the object file by steps as well.

    Something like this for example

    $folder = get-data center-name 'LTX01-G8 | Get-file-name "LTX-servers | Get-file-name "LTX servers 0000 - 0299. Get-file-name Linux

    I guess the first qualification in your path was the data center.

  • PowerCli Script to change the VM Options?

    Is it possible to use PowerCli to change the options for a virtual computer?  Specifically, I would like a PowerCli script to select control of boxes on a virtual machine under Options-> VMware Tools-> advanced settings until the VMware Tools are upgraded during the feeding cycle and the time is sync would be.

    Thank you

    JD

    Here's what we use if you want to pull from a text file.

    $vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
    $vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo
    #$vmConfigSpec.Tools.ToolsUpgradePolicy = "manual"
    $vmConfigSpec.Tools.ToolsUpgradePolicy = "UpgradeAtPowerCycle"
    
    Get-Content -Path "C:\names.txt" | %{
        (get-vm -Name $_).Extensiondata.ReconfigVM($vmConfigSpec)
    }
    
  • Problems with PowerCLI script variables

    Hello

    I hope that someone in the community can tell me where I was wrong in the script below. I have a few other PowerCLI scripts that work in a way similar to this work and these, but this one has a problem. The script is intended to collect information on a number of ESX objects in an array of arrays, $reportfinal, which can then be written to a CSV file that will have the column names for the objects, and each line will yield the values for RDM related objects for each virtual computer. The problem is that, rather than add the results to the table of $reportfinal, the results are crushed, and worse still, the values repeat themselves (for example the size of the various disks is reported as the same value).

    $report = @)

    $reportfinal = @)

    $VMs = get-VMHost | Get - VM | Get-View

    $rowcoll = "" | Select the virtual machine, VMController, SCSIBusShare, SCSIBusNumber, SCSIUnitNo, DeviceLabel, SCSISummary, DeviceFilename, DeviceCapKB, DeviceDiskMode, DeviceDiskUUID

    {ForEach ($VM to $VMs)

    #Clear table report for each virtual computer

    $report = @)

    Foreach ($SCSI_Controller in ($VM. Config.Hardware.Device | where {$_.} (({DeviceInfo.Label - like "SCSI *"})) {}

    $rowcoll. VM = $VM. Name

    $rowcoll. VMController = $SCSI_Controller.DeviceInfo.Label

    {Foreach ($Disk_Key to $SCSI_Controller.Device)}

    Foreach ($Disk_Device in ($VM. Config.Hardware.Device | where {$_.key - eq $Disk_Key})) {}

    $rowcoll. SCSIBusShare = $SCSI_Controller.SharedBus

    $rowcoll. SCSIBusNumber = $SCSI_Controller.BusNumber

    $rowcoll. SCSIUnitNo = $Disk_Device.UnitNumber

    $rowcoll. DeviceLabel = $Disk_Device.DeviceInfo.Label

    $rowcoll. SCSISummary = $SCSI_Controller.DeviceInfo.Summary

    $rowcoll. DeviceFilename = $Disk_Device.Backing.Filename

    $rowcoll. DeviceCapKB = $Disk_Device.CapacityInKB

    $rowcoll. DeviceDiskMode = $Disk_Device.Backing.DiskMode

    $rowcoll. DeviceDiskUUID = $Disk_Device.Backing.UUID

    }

    }

    }

    #Append the next line of the report data collection

    $report += $rowcoll

    #Append the next report to the final report data collection

    $reportfinal += $report

    }

    $reportfinal | Export-Csv-path D:\temp\SAP_Report_Disks_RDM_Mappings.csv - NoTypeInformation

    Note: Some parts of the script came another announcement on this forum about a script to display the ROW information for the list of virtual machines.

    See you soon,.

    Ed

    My mistake, I deleted the line wrong $report.

    Try this one

    $reportfinal = @()
    
    $VMs = Get-View -ViewType VirtualMachine
    
    foreach ($VM in $VMs) {
    
         #Clear report array for each VM
    
         foreach ($SCSI_Controller in ($VM.Config.Hardware.Device | where {$_.DeviceInfo.Label -like "SCSI*" } )) {
    
              foreach ($Disk_Key in $SCSI_Controller.Device) {
                   foreach ($Disk_Device in ($VM.Config.Hardware.Device | where {$_.key -eq $Disk_Key } )) {
                        $rowcoll = "" | select VM, VMController, SCSIBusShare, SCSIBusNumber, SCSIUnitNo, DeviceLabel, SCSISummary, DeviceFilename, DeviceCapKB, DeviceDiskMode,DeviceDiskUUID
                      $rowcoll.VM = $VM.Name
                      $rowcoll.VMController = $SCSI_Controller.DeviceInfo.Label
                        $rowcoll.SCSIBusShare = $SCSI_Controller.SharedBus
                        $rowcoll.SCSIBusNumber = $SCSI_Controller.BusNumber
                        $rowcoll.SCSIUnitNo = $Disk_Device.UnitNumber
                        $rowcoll.DeviceLabel = $Disk_Device.DeviceInfo.Label
                        $rowcoll.SCSISummary = $SCSI_Controller.DeviceInfo.Summary
                        $rowcoll.DeviceFilename = $Disk_Device.Backing.Filename
                        $rowcoll.DeviceCapKB = $Disk_Device.CapacityInKB
                        $rowcoll.DeviceDiskMode = $Disk_Device.Backing.DiskMode
                        $rowcoll.DeviceDiskUUID = $Disk_Device.Backing.UUID
                        $reportfinal += $rowcoll
                   }
              }
         }
    
    }
    
    $reportfinal | Export-Csv -path C:\SAP_Report_Disks_RDM_Mappings.csv -NoTypeInformation
    

Maybe you are looking for