Quantcast
Channel: VMware Communities : Discussion List - VMware PowerCLI
Viewing all 14549 articles
Browse latest View live

Powercli Script to Capture Cluster utilization

$
0
0

Hello All,

 

I'm having having difficulties to create a script that will give me the following:

Cluster CPU, Memory and vSAN Usage. Number of hosts, number of VMs

Needs to export as html and collect the information from multiple vcenter.

Would be something like

Total CPU, CPU Usage, CPU Free, Total RAM, RAM Usage, RAM Free, Total Capacity, Used Capacity, Free Capacity, N° Hosts, N°VMs

 

I have this, but i need it at the cluster level, i think is easier, but you know more than me :)

 

 

 

 
$Output =@();
$hosts = @();
 
Connect-VIServer$hosts -User "ey\a2139242-3" -Password "F3#~5ct7~kdYxNm"
 
$a = "<style>"
$a = $a + "BODY{background-color:white;}"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;padding: 1px;border-style: solid;border-color: black;background-color:PaleGoldenrod}"
$a = $a + "TD{border-width: 1px;padding: 1px;border-style: solid;border-color: black;background-color:white}"
$a = $a + "</style>"
 
Write-Host ("Getting Cluster Information from $hosts")
 
$vcenters| % {
$cluster =Get-cluster -Name *VSAN*
get-cluster$cluster | get-vmhost | % {
$vmhost =$_
$VMHostView = $VMHost | Get-View
$VMs = $VMHost | Get-VM#| ? { $_.PowerState -eq "PoweredOn" }
$TotalRAMGB = [math]::round($vmhost.MemoryTotalGB)
$TotalRAMUsageGB = [math]::round($vmhost.MemoryUsageGB)
$TotalRAMfreeGB = [math]::round($TotalRAMGB-$TotalRAMUsageGB)
$PercRAMUsed = [math]::round(($TotalRAMUsageGB/$TotalRAMGB)*100)
$TotalRAMReservedFree = [math]::round(($TotalRAMGB/100)*15)
$TotalRAMAvailable = [math]::round(($TotalRAMfreegb-$totalramreservedfree))
 
$temp = New-Object PSObject
$temp | Add-Member -pass NoteProperty "VMhost"$vmhost.Name
$temp | Add-Member -pass NoteProperty "ClusterName"$cluster.name
$temp |Add-Member -pass NoteProperty Sockets $VMHostView.Hardware.cpuinfo.NumCPUPackages
$temp |Add-Member -pass NoteProperty Cores $VMHostView.Hardware.cpuinfo.NumCPUCores
$temp |Add-Member -pass NoteProperty Threads $VMHostView.Hardware.cpuinfo.NumCPUThreads
$temp |Add-Member -pass NoteProperty VMCount (($VMs | measure-object).Count)
$temp |Add-Member -pass NoteProperty vCPU (0 + ($VMs | measure-object -Sum NumCPU).Sum)
$temp |Add-Member -pass NoteProperty vCPUperCore ((0 + ($VMs | measure-object -Sum NumCPU).Sum)/$VMHostView.Hardware.cpuinfo.NumCPUCores)
$temp |Add-Member -pass NoteProperty "RAMGB"$TotalRAMGB
$temp |Add-Member -pass NoteProperty "RAMUsageGB"$totalramusageGB
$temp |Add-Member -pass NoteProperty "RAMFreeGB"$totalramfreeGB
$temp |Add-Member -pass NoteProperty "RAMUsage%"$PercRAMused
$temp |Add-Member -pass NoteProperty "RAMReservedGB(15%)"$totalramreservedfree
$temp |Add-Member -pass NoteProperty "RAM Available for NEW VMs in GB"$totalramavailable
 
$Output+=$temp
}
}
 
$Output | ConvertTo-Html -Head $a | Out-File C:\Users\nicolas.porta\Desktop\xrails_hosts.htm -width 400
Disconnect-VIServer * -confirm:$false

 

Need help with patching via powercli

$
0
0

I am attempting to create a script for our L1 folks to run against individual clusters. In an attempt to make it as easy as possible on them I am trying to set it up so they just have to change 3 variables each time they run it to target the intended cluster.  I have included my script below. I am running into problems when I try to use $baseline. When using it I get the error below. The baseline exists as I am able to reference it directly using Get-Baseline -name "baseline name"

 

Get-Baseline Could not find any baselines named 'VMware.VumAutomation.Types.PatchBaselineImpl' on the server

 

 

### Variables ###

$cluster = Get-Cluster -Name "VUM Test Cluster"

$vmhosts = Get-VMHost -Name (get-content "c:\Temp\vmhosts.txt")

$baseline = Get-Baseline -Name "Test-PowerCLI" 

 

 

### Disabling HA on the Cluster.  ###

Set-Cluster -Cluster $cluster -HAEnabled:$false -Confirm:$false

 

 

foreach ($vmhost in $vmhosts) {

 

get-vmhost -Name $vmhost | Set-VMHost -State Maintenance -Confirm:$false

Get-Baseline -Name $baseline | Attach-Baseline -entity $vmhost -Confirm:$false

 

Scan-Inventory -Entity $vmhost

get-baseline -name $baseline | Remediate-Inventory -Entity $vmhost -Confirm:$false -erroraction Silentlycontinue

 

get-vmhost -name $vmhost | set-vmhost -state Connected -Confirm:$false

}

 

 

### Enabling HA on the Cluster.  ###

Set-Cluster -Cluster $cluster -HAEnabled:$true -Confirm:$false

Need Portgroup Information against each VM in for loop

$
0
0

Using the following script to capture a few basic details of list of servers, need to add DVS information can someone please have a look and help.

 

$vmList = Get-Content C:\server.txt

$(foreach ($vmName in $vmList) {Get-VM $vmName| Select-Object -Property Name,

@{Name=’Cluster’;Expression={$_.VMHost.Parent}},

@{N="Tools Status";E={$vm.ExtensionData.Guest.ToolsStatus}},

@{N="Network";E={$_.NetworkName}},

@{Name=”Datastore”;E={[string]::Join(‘,’,(Get-Datastore -Id $_.DatastoreIdList | Select -ExpandProperty Name))}}}

) | Export-Csv "C:\Work\Scripts\SRM\DRTEST2.csv" -NoTypeInformation

Update-VmfsDatastore

$
0
0

Has anyone seen this below error while trying to upgrade VMFS Datastore from version 5 to 6 using Update-VmfsDatastore cmdlet?

 

============================

2019-03-12T06:46:02 [Preflight Check] DS-TEMP is of VMFS 5 type

2019-03-12T06:46:03 [Preflight Check] checking Datastores capacity

2019-03-12T06:46:03 [Preflight Check] DS-TEMP having Capacity : 6291200 MB Greater or Equal than DS-Source capacity : 6291200 MB

Update-VmfsDatastore : Cannot validate argument on parameter 'Id'. The argument is null or empty. Provide an argument that is not null or empty, and

then try the command again.

At line:1 char:1

+ Update-VmfsDatastore -Datastore $source -TemporaryDatastore $temp -Ta ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidData: (:) [Update-VmfsDatastore], ParameterBindingValidationException

    + FullyQualifiedErrorId : ParameterArgumentValidationError,Update-VmfsDatastore

============================

Send Email After successful

$
0
0

Hi,

 

I would like to know, how to send a email if successful or unsuccessful after the script execution.

 

Please help

 

$dest = "\\backup\DR\$date"

$vmhosts = get-vmhost

 

Foreach ($vmhost in $vmhosts) {

Get-VMHostFirmware -VMHost $vmhost -BackupConfiguration -Destination $dest

}

Validate the Data store - No Running VM's

$
0
0

Hi All,

 

Can we validate before decommissioning or unmounting all VMFS 5.0  data store? We want to validate that no running or powered off VM's existing on the data store VMFS 5.0

We are migrating from VMFS 5.0 to VMFS 6.0 and there are tons of data store, hence want to avoid the manual check.

 

Thanks

vmk

some vms not showing with networks

$
0
0

   I'm using this script

 

 

$vms=Get-VM

$vmList=@()

foreach($vm in $vms)

{

   

    $networks= $vm | Get-VirtualPortGroup

    $hasNasInterface=$false;

    foreach($network in $networks)

    {

        if($network.Name -eq "VLAN 298 - NAS" -or $network.Name -eq "VLAN 298 - NAS")

        {

 

            $hasNasInterface=$true;

            $break;    

        }

    }

    if(!$hasNasInterface)

    {

       

        $networks= $vm | Get-VirtualPortGroup

      

        if($networks.Length -lt 1)

        {

            Write-Host $vm.Name

        }

        $vmList+=$vm

 

    }

   

}

 

 

$vmList |Export-csv C:\users\sjesse\desktop\no_nas_int.csv

 

 

I'm trying to find out what vms that aren't on our 298 network, and about 5-10 are showing with no networks, but in the interface they are. Is there something I'm missing

How to speed up script? Search VM and virtual networks by VM IP

$
0
0

Hello,

I made a script that polls vCenter for following parameters: list of IP addresses, clusters, list of virtual networks.

In a test environment, script runs very quickly, but in a productive environment, script takes 15-20 minutes to complete. Maybe I use wrong methods, is it possible to speed up the work of this script?

Write-host "Enter first three octets of IP address, for example: 192.168.69"

$a1 = Read-Host
$b1 = "*" + $a1 + "*"

$c1 = get-vm
$c1 | where {$_.Guest.IPAddress -like $b1} | Select Name, @{N="IP";E={@($_.Guest.IPAddress)}}, @{N=’Cluster’;E={$_.VMHost.Parent}}, @{N='Network';E={(get-view $c1.extensiondata.network).name}}


historical Performance utilization Report for CPU Memory Disk and Network

$
0
0

I want to prepare quarterly or monthly or specific date to date performance report from webclient JPG file. Is there any script available for Webclient data? 

If No, then please share normal script for historical specific date to specific date performance report script.

Need help to get the List of VM – Hosts which are part of affinity rules using Power cli ?

$
0
0

Need help to get the List of VM – Hosts which are part of affinity rules  using Power cli  ?

Export Compliance Reports

$
0
0

We are looking to get a report of missing patches and such from our hosts. I found this document from bbambalova, and wanted to see if anyone could assist me with it. From what I can tell, right now this script will run against ALL hosts found via the $vmHosts = Get-VMHost variable. We want to be able to run this against a specific set of hosts or even select clusters only; not the entire environment. I have tested with the following:

 

$vmHosts = Get-Content "C:\esxihosts.txt"

 

Within that text file, I have a few hostnames that I'd like to run the report against. When I run the script (ExportCompliance.ps1 $vmHOsts "C:\Reports\"), I get the following error:

 

Cannot process argument transformation on parameter 'inventoryItems'. Cannot convert the "esx1.host.com" value of type "system.String" to type "VMware.VimAutomation.ViCore.Types.V1.Inventory.InventoryItem[]".

 

Is there any way I can set this up to run as I'd like? Or is there a better way to go about accomplishing my goal? Thank you.

Need help fine tuning the storage path status script

$
0
0

Can somone please help with fine tuning the script to get the below details?

Output should have the pathstatus of all the LUNs (including RDMs, extent & not allocated LUNs) with below columns

 

"Date","ESXi_hostname","Name", "PathState"

 

Column "Name" should contain the data shown below (highlighted in yellow)

LUN.PNG

Column "PathState" - can be "Active/Standy/dead"

 

I got the below script from somewhere in the internet which used to work fine when running vCenter 6.0. Now that we have upgraded to 6.5, the script isn't provinding the Column "name" correctly.

 

For example, the Column "Name" instead of giving out as below: (please see attached - need the field Name circled in RED)

"vmhba1:C0:T1:L1,fc.200000107b1da97c:100000109a1da97c-fc.524a437f706ae713:524a437f706ae713-naa.624a8350b3e643afaf40452201171121"

 

it just give me this

"vmhba1:C0:T1:L1"

 

Please help me in correcting the script

 

i'm using PowerCLI 11

powercli.png

 

Script:

 

$hostList = 'D:\Scripts\HBA\PathStatus\ESXiHostList.txt'

$outputfile = 'D:\Scripts\HBA\PathStatus\Output\PathStatus.csv'

$vmhosts = Get-Content -Path $hostList

$allhostinfo = @()

$date = Get-Date -format "dd-MMM-yyyy HH:mm:ss"

foreach($vmhost in $vmhosts){

$hostinfo = ((Get-View(Get-VMHost $vmhost)).config.storagedevice.multipathinfo.Lun).Path | Select @{N="Date";E={$date}}, @{N="VMHost";E={$vmhost}}, Name, PathState, State

$allhostinfo += $hostinfo

}

$allhostinfo | Export-Csv $outputfile -noTypeInformation

Trouble getting full output from script sourced on this forum - Obtaining vNIC, MAC, IP and Network name

$
0
0

I am using a script I found here, and trying to get PowerCLI to output a CSV of all VMs in an instance to ensure when these VMs are manually cloned and presented in another instance (don't ask, long story, bad planning) for a DR test, that we can confirm the NICs come across as they were in the source, MAC and all.

Attached file is the script I am using, but I get the following;

VM, vNIC, IP, Portgroup, VLANId, VLAN, Type, SwitchType

testvwotxa202, Network adapter 1, 16.48.33.148,

Note, nothing for Portgroup, VLANid, VLAN, Type etc.

Any thoughts?

Get vCenter Site code and SSO information

$
0
0

Instead of SSHing into the VCSA to get the site code of vCenter, is it doable via PowerCLi?

PowerCLIを使用できるようにしたCentos7からvCenterServerに接続できない

$
0
0

PowerCLIを使用できるようにしたCentos7から"Connect-VIServer"コマンドを使用すると下記のエラーが発生して

vCenterServerに接続できません。

どうすれば接続できるでしょうか。

 

PS /root> Connect-VIServer -server 192.168.0.2

 

 

Specify Credential

Please specify server credential

User: administrator@vsphere.local

Password for user administrator@vsphere.local: ****************

 

 

Connect-VIServer : No such device or address

At line:1 char:1

+ Connect-VIServer -server 192.168.0.2

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ CategoryInfo          : NotSpecified: (:) [Connect-VIServer], CommunicationException

+ FullyQualifiedErrorId : System.ServiceModel.CommunicationException,VMware.VimAutomation.ViCore.Cmdlets.Commands.ConnectVIServer

 

 

PS /root>

 

 

※Centos7とvCenterServer間の疎通は取れています。

 

よろしくお願いいたします。


Configuring a VMware Tools Repository in vSphere 6.7U1

PowerCLI script to get Server utilization report in JPEG format from Webclient

$
0
0

PowerCLI script for fetching utilization report from wbclient JPEG format specific date to date.

CPU : Usage%

Disk: highest Latency

Memory : Active

Network: Data recieve rate  

VM-Folder Informations rekursive

$
0
0

Hello,

need the code to get the sum of VM properties like sizeGB, cpu´s etc. in all our "root"-vm Folders (recursive) with all the subfolders init.

 

Regards

 

guenter

Export vm tags and vm inventory details together

$
0
0

Hi experts,

 

We have a requirement to export the get-vm and all the tags associated to the vms into a single csv file. I managed to get the inventory dump using get-vm as below and it works,. However I am not able to export the vm tags information. Even if I run it manually it shows raw data and its not aligned. Can you please help us to get these information at once in a script ?

 

Get-VM | Select-object Name,@{N='vCenter';E={([system.uri]$_.ExtensionData.Client.ServiceUrl).Host}}, PowerState, Notes, Guest, NumCpu, CoresPerSocket, MemoryMB, MemoryGB, VMHostId, VMHost, Folder, Version, GuestId, UsedSpaceGB, ProvisionedSpaceGB | Export-Csv -path “c:\vc_inv.csv” –NoTypeInformation

 

Requirement:

all vm related information

all tags associated to the vms

 

Thanks a lot in advance

vms cpu requirment _powercli

$
0
0

Hi Luc,

 

can yu suggest something on following .

 

we are migrating vms from prod to DR.

in order to acomadatemigrated vms we calculating resource requirement .

i.e memory,cpu and storage .

while memory and storage is straight forward i want to know what calculations shud be done for cpu.

Viewing all 14549 articles
Browse latest View live


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