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

VM Snapshot

$
0
0

Hi,

I am new for scripting.. I am trying to create script for Vm Snapshot for multiple VM.. But i need Snapshot should take vm name automatic and create snapshot like VM1_BEFOREPATCH , VM2_BEFOREPATCH and so on..

 

 

#VM Server List

$vmlist = Get-Content C:\Servers.txt

 

 

foreach($VM in $VMlist) {

    New-Snapshot -VM $vm -Name BEFOREPATCH- -description 'Patching'

}

 

 

Disconnect-VIServer -Confirm:$false


measuring_disk_latency_powercli

$
0
0

Hi Luc,

 

i was checking following script to calculate maxIOPS .

Get the maximum IOPS - LucD notes

 

could you tell me how to get following expresion

$metrics = "disk.numberwrite.summation","disk.numberread.summation"

 

can we have similar for disk latency?

 

 

Thanks in advance.

Help exporting results to CSV

$
0
0

Hi, Trying to export the AllowedIP list from an ESXi host to csv, the purpose for this is to later write a script which performs a comparison for compliance purposes. however I'm having issues exporting the results to csv, these are the commands below. I thought $rules.AllowedIPAddresses | Export-csv "C:\scripts\file.csv" would work but it doesn't

 

PS C:\Windows\system32> $esxcli = Get-EsxCli -VMHost 'vesxi01*'

 

PS C:\Windows\system32> $rules = $esxcli.network.firewall.ruleset.allowedip.list() | where ruleset -eq dhcp | Select AllowedIPAddresses

 

PS C:\Windows\system32> $rules

 

AllowedIPAddresses                                                

------------------                                                

{192.168.1.0/24, 10.43.200.0/21, 10.43.208.0/21, 10.43.224.0/19...}

 

PS C:\Windows\system32> $rules.AllowedIPAddresses

192.168.1.0/24

10.43.200.0/21

10.43.208.0/21

10.43.224.0/19

10.42.0.0/24

10.43.0.0/24

Script to Clone a VM with multiple disks attached from multiple datastores

$
0
0

Hi,

 

I had a VM which had disks attached from multiple datastores, say 8 datastores. I would like to have a PowerCLI script which clones the VM and have the clone of the VMDK's in its respective datastores like the Parent VM. i.e if the parent VM had 8 disks attched from 8 datastores,the cloned VM also should have 8 disks attached from 8 datastores. This can be achieved from vCenter UI after clicking on "Advanced" option for selecting Datastore. I would like have PowerCLI script for same.

 

Please help me in resolving this issue.

 

-Thanks,

Prasad S V

PowerCLI script to get DatastoreCluster, Datastores and the size info, DataCenter, Clusters

$
0
0

Hello - I am looking to pull the DatastoreClusters and then list the datastores as well with their size (total size, Used space, Free Space, Provisioned, Uncommitted space) and the total number of VM's on that datastore. I would also like to include what datacenter and clusters they are on. Is this possible? I would like to maybe limit what is shown to datastores that are 13% free space or less.

 

Thanks,

Lorri

$null when using ESXCLI -v2

$
0
0

I'm trying to leave a parameter unchanged when using esxcli v2 when I was using esxcli v1 I would just specify $null and that worked but with V2 It seem I have tp specify true or false and the issue with that I would get an error on the console.

 

Basically I want to disabled the ESX firewall.

With ESXCLI v1 it was easy $esxcli.network.firewall.set($null,$false)

 

With V2 I get this

$esxcli2.network.firewall.set.Invoke(@{defaultaction =$null; enabled ='true'})

Message: A specified parameter was not correct: argument[0];

 

OR

 

$esxcli2.network.firewall.set.Invoke(@{defaultaction =$false; enabled =$true})

Message: Default action already DROP;

InnerText: Default action already DROPEsxCLI.CLIFault.summary

Baseline Group

$
0
0

Hello all,

I saw an old topic from three years ago about the same question. Back then the answer was that Baseline Groups were not part of the powercli snappin.

I've downloaded the latest snappin for vShpere 5.5 and saw it's still not an feature? Is this something that will be implemented on short terms? 

Regards,

Erik

finding vm among diffent hosts and grow the system partion_powercli.

$
0
0

Hi Luc,

 

there was scenerio when vcenter was not accesible and we need to find specific vm (among diffenet hosts) also we need to increase the size of c drive of that vm.

 

 

 

following script was created  blue color will find the vm on esxi host   and red color code will increase the size of c drive to 225 from 200GB.

 

 

could you suggest following

1:anyeasy way to define array as fqdn are having same naming convention except numbers 01,02 etc.(something like $i ++)

2:though hardisk size is increased to 225 from 200 but does not extend the c partition inside guest(windows 2012) does vm needs to be powered down.

 

$guestCred =Get-Credential

 

$array =@("shccert01.shdc.chrysler.com","shccert02.shdc.chrysler.com")

foreach ($esxi in $array)

{

connect-viserver -server $esxi -user "root" -password "^TFCxdr5"

$vm=get-vm "shccertsrm01"

if($vm.vmhost.name  -eq $esxi)

{

write-host $vm "is running on" $esxi

 

 

}

}

 

$x=get-vm $vm

$harddisk=Get-HardDisk -vm $x | where {$_.Name -eq "hard disk 1"}

 

Set-HardDisk -HardDisk $harddisk -CapacityGB 225 -GuestCredential $guestCred

 

 

Thanks .


How do I use PowerCLI to determine the exact Linux kernel version of a VM?

$
0
0

Hi all,

 

How do I use PowerCLI to determine the exact Linux kernel version of a VM?

 

 

Thanks in advance!

 

-Chris

Power CLI : Average CPU and Memory Utilization

$
0
0

HI,


Can some body provide me PowerCLI Script to find out Average CPU and Memory Utilization percentage for an ESX Cluster (Containing multiple ESX Hosts)?

Note : Require Average CPU and memory Utilization for multiple ESX Hosts together in a Cluster.

Using a .txt file to exclude entries in a report

$
0
0

I am trying to use a text file to remove one-offs in a report I'm trying to generate with powerCLI... for example some random test luns connected to our hosts that don't need to show up in the list.  I can not get the txt file to work. Here is what I have now in a nutshell

 

$GetSCSIException = Get-Content "C:\scripts\Exclusion.txt"

$GetAllVMs = Get-VM

$GetAllVMs | Get-ScsiController | where {($_.type -notlike "ParaVirtual") -and ($_.bussharingmode -ne "Physical") -and ($_.parent -ne $GetSCSIException)}

 

 

The text file is just a list of a couple VM's:

 

 

VM-1

VM-2

VM-3

 

 

Any ideas?

Problem with foreach VM loop and extensiondata

$
0
0

Ill try to explain this so it makes sense because I'm baffled...

 

I'm creating a script that makes the OS reboot, then waits for vmtools to populate the OS data in extensiondata and then continues when there is a value in that field that isn't blank

 

Beyond that I'm telling the script to do 2 different things depending on the OS version running.

 

The problem is the $VM variable never populates the OS name by itself in the "while" loop, it always throws a blank return if i run $vm.ExtensionData.Guest.GuestFullName

 

if i stop the script and manually run the command $vm = get-vm -Name $vm it populates corrently without issue.

 

This portion of the script is Right after the OS comes back up from the reboot:

 

 

while($vm.ExtensionData.guest.GuestFullName -eq $null){

 

        Write-host "waiting for Guest OS to populate from vmtools..."

        start-sleep -s 3    

       $vm = get-vm -Name $vm

           }

    

 

 

        if($vm.ExtensionData.Guest.GuestFullName -like "*2012*"){

 

            Write-host "Test"

            }

 

 

        elseif($vm.ExtensionData.Guest.GuestFullName -like "*2008*"){

 

           Write-host "Test2"

            }

 

      else{

          Write-host "failed"

              }

 

 

I'm getting the "failed" every time.

 

 

Ill try to explain in more detail if anyone's willing to help

 

thanks!

Mulitpath validation script not giving the right output after upgrading the ESXi version from 5.5 to 6.0

$
0
0

Mulitpath validation script not giving the right output after upgrading the ESXi version from 5.5 to 6.0

 

On ESXi 5.5, it used to give the right results like which are paths are dead, active, standby. But, on ESXi 6.0, all the paths status showing as 'StandBy' only.

Can some one help in this regard....

Script to list vm io latency and the datastore the vm is on

$
0
0

Hello.  We have a vsphere 5.0 environment and we are experiencing some heavy io latency.  I have been looking for a powercli script that will get the io latency for each vm and get the datastore name it currently resides on.  We access our storage over fiber.  I'm trying to get a good overview of io latency in one nice view in a csv.  I found what might be a good base at https://communities.vmware.com/thread/304827?start=0&tstart=0 but I'm not quite sure how to get the datastore name into the array and I think it is written for nfs storage anyway.  Thanks in advance for any info\advice!

Scripted SRM - network mapping help

$
0
0

Hey guys,

 

Trying to script network selection for our DR site. Currently using below commands to map primary network name with DR network name. can someone suggest if there's a better way using these commands please.

 

# Update Network card for all VM's in cluster

Get-VM | Get-NetworkAdapter | ? {$_.NetworkName -eq "dvportgroup-19273" -or $_.NetworkName -eq "dvportgroup-21140" } |  Set-NetworkAdapter -NetworkName "ABC"

Get-VM | Get-NetworkAdapter | ? {$_.NetworkName -eq "dvportgroup-19274" -or $_.NetworkName -eq "dvportgroup-10114" } |  Set-NetworkAdapter -NetworkName "ABC_31"

Get-VM | Get-NetworkAdapter | ? {$_.NetworkName -eq "dvportgroup-241" -or $_.NetworkName -eq "dvportgroup-110125" } |  Set-NetworkAdapter -NetworkName "ABC_18"

About 10 additional networks needs to be mapped.

 

To clarify, got 16 networks on primary site across 2 VDS and they need to be  mapped to 10 port groups in DR site on a single VDS

Help greatly appreciated.

 

Cheers,


Get VM's with status toolsOK and HW Version not v11

$
0
0

Hello,

 

I'm not too great with combining where statements in powercli. Do I have to create variables and then perform my Get-VM action?

 

Here is what I have, and it doesn't work. I assume because the Where-Object doesn't allow an additional Where statement that isn't related to Where-Object?

 

Connect-VIServer -Server xx.xxx.xx.xxx

Get-VM | Where (Where-Object {($_.ExtensionData.Guest.ToolsStatus -eq "toolsOk")} -and (Where Version -NE "V11"))

 

Obviously it is wrong, can someone help me out? Is it even possible?

Script to get esxi syslog location across vCenter

$
0
0

Hi All,

Need to update esxi syslog location across my vCenters. Is there a script which can get me the existing syslog location of all the esxi host across my vCenters.

 

 

 

 

Thanks in Advance

Matching VM Disks to Windows Disk for SCSI Controller 1 (scripts online always work for controller 0)

$
0
0

Hi Folks

 

I am looking to get to the bottom to the bottom of matching VMWare hard disks to disks in Windows using WMI.

 

So far all scripts I have found work with SCSI Controller 0, but it fails when trying to get details on SCSI Controller 1 and for some reason the details in WMI - it always incorrectly reports it as controller 0 even when its not.

 

I found this article which is great, but surely there is a Windows WMI way to get this to compare?

 

echo( "hello wordl" ): Match virtual hard disks in Virtual Center with their disk labels in Windows 2008

 

The other thing I was wondering was based on the article above, is it possible to get the location of the VMX file and read its contents into a variable so that you can match the "scsi1.pciSlotNumber"value to the number reported in WMI?

 

I have scoured the net and this is the closest thing I can find to unpicking this issue.

 

Any help would be greatly appreciated

Getting a return code from Remove-Snapshot

$
0
0

My script includes a command to remove an existing snapshot.

My code looks like:

 

Remove-Snapshot -Snapshot $snapshot -Confirm:$false

 

It works fine but I need to check if the operation completed successfully.

I changed the code as:

 

$myexit =  Remove-Snapshot -Snapshot $snapshot -Confirm:$false

 

but I get no exit.

How can I ensure that the removal was sucessfull and (if possible) get a code for the possible error?

Regards

 

marius

Get-View in a nested loop

$
0
0

I have been looking at a script to pull in some information regarding templates. This was not written by me, but I am trying to get it working. The script has nested For loops in it, which seem to be fine with the majority of items I am pulling back. For information I am pulling out of Get-View, however, the results are not consistent. The code is below:

 

      $datacenters = Get-Datacenter        foreach($Datacenter in $Datacenters) {            $TemplateNames = Get-Template -Location $Datacenter                       foreach ($template in $TemplateNames) {                 $templateview = Get-View -id (Get-Template $template).Id                    write-host DataCenter ---- $Datacenter                 write-host Template Name ----  $Template.Name                 write-host OS Version  ---- $templateview.Summary.Config.GuestFullName                 pause                 write-host Template Notes  ---- $templateview.Summary.Config.Annotation                 write-host vCPU  ---- $Template.ExtensionData.Config.Hardware.NumCPU                 write-host Memory ----  $Template.ExtensionData.Config.Hardware.MemoryMB                     write-host Number of Hard Disks  ---- ($Template | Get-HardDisk | Measure-Object).Count                 write-host HD Name  ---- ($template|Get-HardDisk).Name                 write-host HD Size GB  ---- $template|Get-HardDisk|select -ExpandProperty CapacityGB                 write-host HD Format  ---- ($template|Get-HardDisk).storageformat                 write-host VM Hardware Version ----  ($templateview).config.version                 write-host VM Tools Version ----  $templateview.config.tools.toolsversion                 write-host VM Tools  ---- $template.ExtensionData.Guest.ToolsVersionStatus                 pause                }         }

 

For any item using the $templateview info, it duplicates the data returned:

OS Version ---- Microsoft Windows 7 (64-bit) Microsoft Windows 7 (64-bit) Microsoft Windows 7 (64-bit) Microsoft Windows 7 (64-bit) Microsoft W

indows 7 (64-bit) Microsoft Windows 7 (64-bit) Microsoft Windows 7 (64-bit) Microsoft Windows 7 (64-bit) Microsoft Windows 7 (64-bit) Microsoft

Windows 7 (64-bit) Microsoft Windows 7 (64-bit) Microsoft Windows 7 (64-bit) Microsoft Windows 7 (64-bit) Microsoft Windows 7 (64-bit) Microso

ft Windows 7 (64-bit) Microsoft Windows 7 (64-bit) Microsoft Windows 7 (64-bit) Microsoft Windows 7 (64-bit) Microsoft Windows 7 (64-bit) Micro

soft Windows 7 (64-bit) Microsoft Windows 7 (64-bit) Microsoft Windows 7 (64-bit) Microsoft Windows 7 (64-bit) Microsoft Windows 7 (64-bit) Mic

rosoft Windows 7 (64-bit) Microsoft Windows 7 (64-bit) Microsoft Windows 7 (64-bit) Microsoft Windows 7 (64-bit) Microsoft Windows 7 (64-bit) M

icrosoft Windows 7 (64-bit) Microsoft Windows 7 (64-bit) Microsoft Windows 7 (64-bit) Microsoft Windows 7 (64-bit)

 

VM Hardware Version ---- vmx-11 vmx-08 vmx-11 vmx-08 vmx-11 vmx-11 vmx-08 vmx-10 vmx-11 vmx-08 vmx-11 vmx-11 vmx-08 vmx-08 vmx-10 vmx-08 vmx-11

vmx-10 vmx-08 vmx-07 vmx-10 vmx-10 vmx-10 vmx-08 vmx-11 vmx-10 vmx-09 vmx-08 vmx-08 vmx-08 vmx-08 vmx-08 vmx-11

 

But only for the first loop. Subsequent iterations return the information as I would expect:

OS Version ---- Microsoft Windows Server 2008 R2 (64-bit)

VM Hardware Version ---- vmx-11

 

Any idea why this would be happening only the first loop? I don't see it being related to the OS, as a subsequent desktop template works fine as well.

Viewing all 16717 articles
Browse latest View live


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