Quantcast
Channel: VMware Communities : All Content - VMware PowerCLI
Viewing all 16717 articles
Browse latest View live

Using PowerCLI to get VM Disk Stats

$
0
0

Firstly - this is really a message to LucD (who I know from previous assistance tends to prowl this forum )  , just figured I'd share it, as it's all usefull info and any insight LucD has will no doubt be usefull for all.

 

Hi LucD,
Firstly - thanks for a great selection of posts on Reporting vSphere from Powershell - Well worth the time and a worth read for anyone.
I'm certainly not any good at PowerShell - but I was able to understand and make some changes for my benefit - so I figured I'd share my results and ask a couple of questions.
With your script as a basis - I've been able to come up with the following that SHOULD allow me to review ALL VMs in VC one at a time collect virtual disk stats for the VMs various disks, (IOPS, Throuput & Latency) I'm using VC 4.1 and and the storage is NFS attached, I believe these stats are OK but would appreciate your insight on this.
I'm quite pleased with the script - but it needs more testing on a valid site, rather than my small test area, but I'm sure from a 'PS' perspective there is more efficiency to be gained.
Firstly - is there any way of getting all the stats at once - rather than doing 6 calls per VM? (I'm also sure the '+=' one stat the the next can not be ideal)
Also - is there a way can control the output to the CSV, it seems to put colums in any order it likes and layout does not seem to be related to the group object command? Can this be controlled so I can have the 'value' and 'unit' entries next to each other?
Any insight and assistance would be appreciated, and I hope others will give it a test and let me know if it works for them too.
Thanks again for the inspiration and insight that got me this far
Tony.
ESX 4.1, VC 4,1, PShell 2.0, PowerCLI 4.1.1
# Main Variables
$sVCentre = "VC IP"
$sVCUser = "administrator@domain"
$sVCPwd = "password"
$strVMWildCard = "*"
$strCSVName = "Stats-AvgVMDiskWriteStatsWorkingday"
$strCSVLocation = "c:\"
# define the start and finish times for a working day.
$today9am = (Get-Date -Hour 9 -Minute 0 -Second 0)
$today5pm = (Get-Date -Hour 17 -Minute 0 -Second 0)
$intStartDay = -1
$intEndDay = -1
## Begin Script
#Connect to VC
Connect-VIServer $sVCentre -User $sVCUser -Password $sVCPwd -ea silentlycontinue
$arrVMs = Get-VM | where-object {$_.Name -like $strVMWildCard}
foreach ($strVM in $arrVMs)
{
Write-Host "Getting Stats for : " $strVM.Name
Write-Host " - collating Write latency Stats"
$stats += Get-Stat -Entity $strVM -Stat virtualDisk.totalWriteLatency.average -Start $today9am.AddDays($intStartDay) -Finish $today5pm.AddDays($intEndDay)
Write-Host " - collating Read latency Stats"
$stats += Get-Stat -Entity $strVM -Stat virtualDisk.totalReadLatency.average -Start $today9am.AddDays($intStartDay) -Finish $today5pm.AddDays($intEndDay)
Write-Host " - collating Read IOPS Stats"
$stats += Get-Stat -Entity $strVM -Stat virtualDisk.numberReadAveraged.average -Start $today9am.AddDays($intStartDay) -Finish $today5pm.AddDays($intEndDay)
Write-Host " - collating Write IOPS Stats"
$stats += Get-Stat -Entity $strVM -Stat virtualDisk.numberWriteAveraged.average -Start $today9am.AddDays($intStartDay) -Finish $today5pm.AddDays($intEndDay)
Write-Host " - collating Read Throughput Stats"
$stats += Get-Stat -Entity $strVM -Stat virtualDisk.read.average -Start $today9am.AddDays($intStartDay) -Finish $today5pm.AddDays($intEndDay)
Write-Host " - collating Write Throughput Stats"
$stats += Get-Stat -Entity $strVM -Stat virtualDisk.write.average -Start $today9am.AddDays($intStartDay) -Finish $today5pm.AddDays($intEndDay)
Write-Host $stats.length
# group the data and collate the stats into averages for the day.
}$groups = $stats | Group-Object -Property {$_.Entity, $_.MetricId, $_.Instance}
$report = $groups | % {
New-Object PSObject -Property @{
Description = $_.Group[0].Description
Entity = $_.Group[0].Entity
EntityId = $_.Group[0].EntityId
Instance = $_.Group[0].Instance
MetricId = $_.Group[0].MetricId
Timestamp = $_.Group[0].Timestamp.Date.AddHours($_.Group[0].Timestamp.Hour)
Unit = $_.Group[0].Unit
Value = [math]::Round(($_.Group | Measure-Object -Property Value -Average).Average, 2)
}
}
#Exporting the report to a CSV file.
$strCSVSuffix = (get-date).toString('yyyyMMddhhmm')
$strCSVFile = $strCSVLocation + $strCSVName + "_" + $strCSVSuffix + ".csv"
$report | Export-Csv $strCSVfile -NoTypeInformation -UseCulture

vMotion TCP/IP Stack- Created by Powercli

$
0
0

Hi all,

 

Has anyone successfully automated the creation of the vMotion TCP/IP Stack on each host and then the creation of the vMotion VMK utilizing the newly created stack.

 

Regards

Cliff

script to get powerstate and toolstatus

$
0
0

I'm created a script and I'm having trouble getting the Powerstate it spits out nothing, if I take away Get-View I can get the powerstate.

 

Excuse my ignorance but I'm just starting to dive into powershell

 

get-cluster -Name <clustername> | Get-VM | Get-View | Select-Object @{Name="Hostname";e={$_.Name}}, @{Name="VMware Tools"; e={$_.Guest.ToolsStatus}}, @{Name="Powerstate";e={$_.PowerState}}

Exporting information on all hosted VM's

$
0
0

So I've managed to get 75% of what I'm looking to extract from vCenter and export it to a CSV file. I'm trying to get some more information which will help me maintain the vCenter environment I am working on. I guess the first problem I'll address is what is the best way to pull down the IPv4 address only? Right now I'm getting both IPv4 and IPv6. When I log into the vCenter server via PowerCli and then run this command:

 

 

     Get-VM | Select Name, @{N="IP addr";E={[string]::Join(',',$_.Guest.IPAddress)}}, NumCpu, MemoryGB, Notes, PowerState | Export-Csv -path "c:\temp" -NoTypeInformation

 

I'm getting a CSV file with a number of data points, and it all looks good other than the IPv4 issue. I tried just adding Host or NetworkAdapters to the data points to get, but it didn't work. Am I going about this the wrong way, or is there a better way to get these data points?

 

 

Thanks!

Get-VDport missing data

$
0
0

I am having an odd experience with Get-VDPort. I am doing the following:

 

Get-VDSwitch | Get-VDPort -Uplink | where proxyhost -match "$($ESXHost.name)"

 

This is in a loop of many esx hosts.

 

This should produce all the uplinks in each vdswitch however I am missing uplinks. When i do this command on a specific vdswitch everything comes back as expected.

 

Anyone else experiencing this issue? or is this a known bug?

Script to Generate IOPS Report

$
0
0

Hello,

     I've been looking around for a script but I cant seem to find what i'm looking for. I would like something that would survey all VM's across all clusters and datastores (everything) And would generate a CSV report that show the IOPS usage per VM's.

 

I just want to be able to evaluate which VM's in particular are taxing our storage arrays.

 

Any help or pointers in the right direction would be appreciated.

 

Thanks!

How can cpu/mem.usage.average be greater than 100%?

$
0
0

Hello,

 

I am using Get-Stat cpu.usage.average and mem.usage.average to check VM usage. I am pulling info at 2 hr intervals.

It is my understanding that each of these measurements should be a maximum of 100 for each VM-host (summing % of each client). or in my case 500 as I have 5 identical VM-hosts.

 

But, as I sum each column I get 600-700 - hos is this possible?

 

Thanks-

 

Script:

$DaysBack = 14 #Number of days back to collect performance counters.

$PeakTimeStart = 8 #hour of the day in 24 hour format

$PeakTimeEnd = 20 #hour of the day in 24 hour format

$rdy_interval = 7200 #interval of rdy time values aggregation/averaging in seconds. This value should be changed according to your vcenter statistics settings.

#FUNCTIONS

function Connect-Vcenter {

    param(

        $vcenter

    )

    #Load snap-in

    if (-not (Get-PSSnapin -Name VMware.VimAutomation.Core)) {

        Add-PSSnapin VMware.VimAutomation.Core

    }

    #Connect to vCenter

    if ($global:DefaultVIServers.Count -lt 1) {

        Connect-VIServer $vcenter

    }

}

function Get-VMCPUAverage {

    param (

        $VM

    )

    $Start = (get-date).AddDays(-$DaysBack)

    $Finish = get-date

    

    $stats = get-vm $VM | get-stat -MaxSamples "1000" -Start $Start -Finish $Finish -Stat "cpu.usage.average" | `

    ? { ($_.TimeStamp).Hour -gt $PeakTimeStart -and ($_.TimeStamp).Hour -lt $PeakTimeEnd }

    $aggr_stats = $stats | Measure-Object -Property Value -Average

    $avg = $aggr_stats.Average

    return $avg

}

function Get-VMCpuRDY {

    param (

        $VM

    )

    $Start = (get-date).AddDays(-$DaysBack)

    $Finish = get-date

    

    $stats = get-vm $VM | Get-Stat -MaxSamples "1000" -Start $Start -Finish $Finish -Stat Cpu.Ready.Summation | `

    ? { ($_.TimeStamp).Hour -gt $PeakTimeStart -and ($_.TimeStamp).Hour -lt $PeakTimeEnd -and $_.Instance -eq ""}  

    $aggr_stats = $stats | Measure-Object -Property Value -Average 

    $rdy = [Math]::Round(((($aggr_stats.Average)/1000)/$rdy_interval) * 100,1)

    return $rdy

}

#SCRIPT MAIN

#clear

#Load the VMWare module and connect to vCenter

Connect-Vcenter -vcenter $vcenter

$AvgCPUValues = @() #Create array to hold the CPU usage and CPU ready values

Get-Cluster $ClusterName | Get-VM | ? {$_.PowerState -eq "PoweredOn"} | % { #loop through all powered on VMs in the cluster

    $AvgCPUValue = "" | Select "VM","CpuAvg","CpuRdy" #create a custom object with these properties.

    $AvgCPUValue.VM = $_.Name

    $AvgCPUValue.CpuAvg = "{0:N2}" -f $(Get-VMCPUAverage -VM $_) #Get VM CPU usage and round to two decimals

    $AvgCPUValue.CpuRdy = Get-VMCpuRDY -VM $_

    $AvgCPUValues += $AvgCPUValue

}

$AvgCPUValues | Export-Csv $CSV -NoTypeInformation -Force

Missing all of my metrics

$
0
0

I'm connected to a vCenter server and this is what I see when checking the metrics I have available:

$aaa = Get-Stat -Entity SomeVM

#when running this I get an error saying metric counter 'disk.usage.average' doesn't exist

$aaa | group -property metricid

#I only see these metrics:

cpu.usage.average

cpu.usagemhz.average

mem.usage.average

net.usage.average

sys.uptime.latest


Get-VIPermission of all Hosts

$
0
0

Hi guys

 

Please help to modify script below to export all user & group role, permission & propagation.

 

get-cluster | get-vmhost | where=object {$_.connectionstate -eq "Connected"} | get-vipermission | export-csv -path c:\output\vipermission.csv

 

thanks.

Issue with Importing VM from vsphere into Vapp

$
0
0

I've the issue with importing vm from vsphere into existing vapp in vcloud director (8.0)

the following message error when i use import-civapp ...


Import-CIVApp, the vSphere server with UUID ...... is not found on this cloud Instance.

 

And yet I am sure that the vCenter I use is good

 

Any Idea ?

 

 

 

 

Code:

Connect-VIserver ....
Connect-CIServer ...
$vm=Get-VM test

Get-CIVapp $vappName | Import-CIVApp $vm

System Swap file check through powershell

$
0
0

Do we have any script for checking Esxi System swap ?

New-Harddisk - WARNING: Parameter 'VM' is obsolete. Passing multiple values to this parameter is obsolete.

$
0
0

How can a mandatory parameter be obsolete?

Answer types

How to get the href for an object returned from 'search-cloud'

$
0
0

I am currently running the following search-cloud to get Org VDC Network.

$network = Search-Cloud -QueryType OrgVdcNetwork -Name 'my_network_name'

I then want to get the href of this object. But, this is not visible in the object returned:

PS C:\powershell\VCDProduction\GenericScripts> $a
 
 
Name               : Customer_90533-V550-Mortgag_DEV_UAT-M2VLN25342003
DefaultGateway     : 172.23.25.254
Netmask            : 255.255.255.0
Dns1               :
Dns2               :
DnsSuffix          :
LinkType           : 0
ConnectedTo        : Customer_90533-V550-Mortgag_DEV_UAT-M2VLN25342003
Vdc                : urn:vcloud:vdc:ae96fdb6-b2df-4884-911f-c19e24953b4f
IsBusy             : False
IsShared           : True
VdcName            : M2VDC25342013
IsIpScopeInherited : True
Href               :
Id                 : urn:vcloud:network:f55f6db0-e099-45d5-88eb-8192e00e9618
Type               :
AnyAttr            : {taskStatus, taskOperation, task, taskDetails}
Link               :
Metadata           :
PropertyList       : {[Name, Customer_90533-V550-Mortgag_DEV_UAT-M2VLN25342003], [DefaultGateway, 172.23.25.254],
                     [Netmask, 255.255.255.0], [Dns1,  ]...}
Uid                : /CIServer=custdccreator:system@10.135.2.33:443/CISearchResult=18de8709-af31-4c2a-90b7-4596c43457c2
                     /
Client             : /CIServer=custdccreator:system@10.135.2.33:443/

PS C:\powershell\VCDProduction\GenericScripts> $a


Name               : my_network_name
DefaultGateway     : 192.168.1.254
Netmask            : 255.255.255.0
Dns1               :
Dns2               :
DnsSuffix          :
LinkType           : 0
ConnectedTo        : my_network_name
Vdc                : urn:vcloud:vdc:ae96fdb6-b2df-4884-911f-c19e24953b4f
IsBusy             : False
IsShared           : True
VdcName            : my_vdc_name
IsIpScopeInherited : True
Href               :
Id                 : urn:vcloud:network:f55f6db0-e099-45d5-88eb-8192e00e9618
Type               :
AnyAttr            : {taskStatus, taskOperation, task, taskDetails}
Link               :
Metadata           :
PropertyList       : {[Name, my_network_name], [DefaultGateway, 192.168.1.254],
                     [Netmask, 255.255.255.0], [Dns1,  ]...}
Uid                : /CIServer=custdccreator:system@x.x.x.x:443/CISearchResult=18de8709-af31-4c2a-90b7-4596c43457c2
                     /
Client             : /CIServer=custdccreator:system@x.x.x.x:443/

Getting Previous vCenter Tasks

$
0
0

So I am just having an issue finding where the previous tasks are stored

 

Get-task only does tasks in the recent pane, and get-vievent only seems to cover the Events portion of the Tasks/Events tab in vCenter.

 

I just can't find where that big list of Past tasks is located...

 

Any help would be aprpeciated...

 

Thanks!


Get License Name from host

$
0
0

Hi,

 

I apologise if this has been asked previously.  I did a search and couldn't find anything.

 

I have a script that loops though a number of IP addresses and connects to each host one at a time to retrieve information (not all hosts belong to a vCenter)

I'm trying to get license details.

 

In the script I can do:

$lm = Get-View -Id 'LicenseManager-ha-license-manager'

 

I can then do

PowerCLI C:\PSScripts> $lm

Source                   :

SourceAvailable          : False

Diagnostics              :

FeatureInfo              : {}

LicensedEdition          :

Licenses                 : {VMware vSphere 5 Essentials}

LicenseAssignmentManager :

Evaluation               : VMware.Vim.LicenseManagerEvaluationInfo

LinkedView               :

MoRef                    : LicenseManager-ha-license-manager

Client                   : VMware.Vim.VimClientImpl

 

and

PowerCLI C:\PSScripts> $lm.Licenses

 

LicenseKey      : JJ214-44LDN-6894D-0UE06-CTA45

EditionKey      : esxExpress.vram

Name            : VMware vSphere 5 Essentials

Total           : 66

Used            : 2

CostUnit        : cpuPackage

Properties      : {ProductName, ProductVersion, feature, feature...}

Labels          :

DynamicType     :

DynamicProperty :

 

But I can't do

$lm.Licenses.Name

I get no data back.


I can do:

PowerCLI C:\PSScripts> $lm.Licenses | select Name

 

Name

----

VMware vSphere 5 Essentials

 

but how do I then put "VMware vSphere 5 Essentials" into a variable?

 

I hope that makes sense?

 

Thanks

 

Joe

ESXcli 5.5 UNMAP and PowerCLI script?

$
0
0

Has anyone been able to get powercli to run the esxcli command for unamp

esxcli storage vmfs unmap -l Datastore name -n unit

 

any example would be appreciated

What is the best way to track the status of a VM host vMotion and confirm whether the status is completed?

$
0
0

I have a PowerCLI script which vMotions a set of VM's from one cluster to another, done asynchronously.  Now I need to run a post check to confirm the vMotion tasks were successful.    Using Get-Task, I can see the status of vMotion tasks change to "completed" and cross reference the Id back to the VM name.  The main downside to Get-Task is the objects expire after 10 minutes.  In my use case this really shouldn't be an issue as I'm vMotioning at most 15-20 VM's and the Get-Task history should contain all the information I need.

 

But I would prefer to not rely on that condition if possible.  I was looking at Get-VIEvent as an alternative, but it appears the state object property is always locked in "queued" state even long after the job has completed.  Is there way to get "completed" status from Get-VIEvent or another other cmdlets?

Host NIC driver levels

$
0
0

Does anyone have a PowerCLI script for pulling NIC driver levels form host(s)?

Set VM name with current date POWER CLI -Multiple machines -How to Remove brackets in the array results

$
0
0

As you can see in the results PowerShell adds @{ signs.  Is there way to remove that from the results and display the result just like the below.?

 

 

get-view -viewtype virtualmachin | Where-Object { $_.Name -like "*BKP"} | Select name  |

 

    ForEach-Object {

 

              set-vm -VM $_.Name -Name "$_.name $($dateformat )" -Confirm:$false

 

}

 

Result = @{Name=abcd-BKP}.Name 22-03-2016


Expected result = abcd-BKP 22-03-2016


please advice

 

Thanks

Anoop

Viewing all 16717 articles
Browse latest View live


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