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

Datastore and VMHost vs Cluster

$
0
0

I have a request right now to build a GUI around a working PowerCLI script that creates a new VM based on fields entered by a tech. The GUI looks like this:

 

As this will be done by "associate" techs who may not have the access or experience to troubleshoot issues very deeply, I am trying to both simplify the GUI and ensure the script has necessary error checking. One item that I am mulling over is the host/datastore. Rather than having 4 fields (Host, Cluster, Datastore, Datastore Cluster) I would just like to have two, and do the worrying on the back end. In the script I have been playing about with a couple of different ways to do this - an if statement didn't seem to work the way I wanted so I settled on a Try/Catch like so:

 

    try {        Get-DatastoreCluster -Name C-CAD-1 -ErrorAction Stop    }catch [Exception] {        Get-Datastore -Name C-CAD-1    }    try {        Get-Cluster -Name mas-vms01.dartcontainer.com -ErrorAction Stop    }catch [Exception] {        Get-VMHost mas-vms01.dartcontainer.com    }

 

My question is, is this the best way to do it? Am I setting myself up for headaches down the road? Any thoughts/suggestions would be welcome.


performance report

$
0
0

I'm a newbie with powercli and my boss is asking me to generate an hourly report on cpu average, memory average, disk i/o, and network i/o.  Just picked up a book VMWare vSphere PowerCLI Reference but I'm overwhelmed with all the information.  Wondering if there is a similar script from anyone out there that I can use or tailor according to my need.

 

Thanks

Steve

How to Disable / Enable a VM's Network Adapter DirectPath I/O Parameter

$
0
0

Hi!

 

 

There are examples on the internet on how to get this setting, like

 

(Get-VM -Name "a-vm-name" | Get-NetworkAdapter).ExtensionData.UptCompatibilityEnabled

 

but there is none on how to set it. I know I could use Onyx but my vCenter has overtaken it (6.0 --> 6.5). Maybe I can get a quicker answer here...

 

 

 

Thanks

Gregor

migrate VMs 6.0->6.5 same storage / different sso

$
0
0

Hello,

 

we currently have 5x vcenters 6.0 based on windows connected to same external PSC.

we create 5x independent vcsa 6.5 each with access to same datastore cluster as its 6.0 counterpart.

The vds has been exported from each vcenter 6.0 and imported in the vcsa 6.5

The underlying network has no changes and same vmkernels are available to 6.0 / 6.5 environments (vmotion/nfs/..)

 

So ideally now it would be enough a simple (?) "Move-VM" command to move a VM from vcenterA to vcenterB which should take care about VM folder structure/name (BluePath) and reattach all vnics to destination vds (which has same portgroup name already there).

 

Web show tons of different approaches but none seems to avoid data storage motion and folder name preservation.

If they do ... then I just miss the proper one.

 

Any suggestion/tip is welcome.

 

Thank you!

Get-SpbmStoragePolicy error "Object reference not set to an instance of an object"

$
0
0

I recently stumbled across an issue in which attempting to run the PowerCLI command Get-SpbmStoragePolicy resulted in the error "Object reference not set to an instance of an object."  After a fair amount of digging around, I ran into Kruddy's comment on an issue with Get-SpbmStoragePolicy taking quite a long time to run with zero results.  Kruddy suggested checking for tags with no category set as this would cause unexpected behavior when attempting to use commands referencing tags.  After checking for tags such as these using the command given Get-Tag | Where {$_.Category -eq $null}, I found several in this very state (SRM orphaned tags).  After removing these, the Get-SpbmStoragePolicy command and other associated storage policy commands started working without any further issue.

 

Link to referenced comment - Re: Get-SpbmStoragepolicy and vCenter 6.5

Command used - Get-Tag | Where {$_.Category -eq $null}

 

I hope this helps with anyone having a similar issue.

Get-SpbmStoragepolicy and vCenter 6.5

$
0
0

We have migrated a couple of our vCenters to VCSA 6.5.

I can't seem to retrieve the storage policies with Get-SpbmStoragePolicy from these vCenters. The cmdlet takes *forever*. After 15 minutes with no output I have just closed the window.. The same command against a vCenter 6.0 U2 works like it should.

 

Here's my PowerCLI version:

 

PS C:\> Get-PowerCLIVersion

PowerCLI Version
----------------
   VMware PowerCLI 6.5.1 build 5377412
---------------
Component Versions
---------------
   VMware Cis Core PowerCLI Component 6.5 build 5374323
   VMware VimAutomation Core PowerCLI Component 6.5 build 5374329
   VMware Storage PowerCLI Component 6.5 build 5374001

 

 

Has anyone seen the same?

how to Interrogate VMs in sub folders locations

$
0
0

Hi Fellow VM Admins

 

I have got a question regarding a PowerShell script which was developed by one of our previous VM admins who was a bit of script guru who managed to create a script which we use as part of disaster recovery process.

 

Unfortunately my knowledge with PowerShell scripts is limited and I could do with some help.

 

In summary  we use this script as part of our DR recovery process to clone our volumes from our NetApp array using the NetApp flexclone method to bring our VMs online within minutes however the performance of that array is poor so we want to utilize another array which has higher performing disks. We use this PowerShell script to effectively interrogate a particular VM folder and it will literally process any VMs located on a particular storage which starts with the name 'snap' and if it identifies this, it will the move to another storage array in a sequential order.

 

As part of one of the variables defined we use $VM_LOCATION so the script knows which folder to look in to interrogate but ideally I need to amend this slightly so that it can interrogate sub folders within that main folder.

 

I attach the script in txt format.

 

Is this possible? Is anyone able to help me?

I have tried to look for a variable which would meet this need but I cant seem to find one.

 

Any help on this would be most appreciated.


Many Thanks

VMware Folder Resource Report

$
0
0

I am looking for a way to get a resource report for a set of VMs. Things like CPUs assigned, RAM assigned, HDD assigned, & HDD used, but I want to be able to point it at a VM folder so it will dynamically grow as the group does.  Looking for any ideas on how to do this.

 

Thanks,

Andy


Way to script VMware tools status option

$
0
0

When a new VM is created, or a VM is registered to a vCenter for the first time, the VMware Tools status will display "not running, not installed". The "not running" part is obvious if it's powered off. But the "not installed" portion refers to vCenter's "memory" of the version of tools installed on the system. Normally, it will pick this up when the VM first boots and it observes VMtools is running, or when VMtools is installed it picks up the version and type (guest-managed or "official"). If a VM is powered off and this status says "not installed", then it will fail to be customized with a spec throwing the error message "customization of the guest operating system is not supported in this configuration".

 

Would it be possible to tell vCenter this information? Is there an API for this? I'm trying to avoid having to automate a power-on/power-off cycle just to get vCenter to pick this info up. Any help is appreciated here.

PowerCLI script to compare items in array to condition

$
0
0

So I am working on a script that will kick off SCCM updates for newly built VMs. The issue I am running into is that each required update is put into an array with a property called evaluationstate. I only want the script to continue after all updates in the array have an evalstate of either 8 or 13 (success or fail). Not sure how I would accomplish that. Any help would be appreciated

Fixing the PowerCLI VM to pull some data from Get-View ?

$
0
0

People,

 

Can anyone here please assist me in fixing the script below so that it can display the vNIC type (VMXnet3 or e1000), Proper IPaddressing that is not 169.254 for some multi NICs VMand also VM Port Group ?

 

Get-View -ViewType VirtualMachine -SearchRoot (get-cluster '*PROD*').id -Filter @{'Summary.Guest.ToolsVersionStatus'='guestToolsNeedUpgrade'} |
Select Name,  @{N="IP";E={$_.Summary.Guest.IpAddress}},  @{N='Guest OS';E={$_.Config.GuestFullName}},  @{N='VM Notes';E={$_.Summary.Config.Annotation}},  @{N="vNIC Type";E={((Get-VM $_.Name).NetworkAdapters).Type}},  @{N="PortGroup";E={((Get-VM $_.Name).NetworkAdapters).NetworkName}},  @{N='Tools Version';E={$_.Config.Tools.ToolsVersion}},  @{N='Tools Status';E={$_.Summary.Guest.ToolsVersionStatus}} |  Export-Csv -Path C:\VM-vNIC.csv -NoTypeInformation -UseCulture

 

This is my PowerCLI configuration:

 

PowerCLI Version

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

   VMware PowerCLI 6.5 Release 1 build 4624819

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

Component Versions

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

   VMware Cis Core PowerCLI Component 6.5 build 4624453

   VMware VimAutomation Core PowerCLI Component 6.5 build 4624450

   VMware HA PowerCLI Component 6.0 build 4525225

   VMware Licensing PowerCLI Component 6.5 build 4624822

   VMware Storage PowerCLI Component 6.5 build 4624820

   VMware Vds PowerCLI Component 6.5 build 4624695

 

Thanks in advance.

how to retrieve HBA and NIC driver,firmware version using powercli

$
0
0

Hello every!

 

If have a simple powcli script to retrieve ESXi host  HBA (RAID controller, FC HBA conntroller)  and NIC driver,firmware version. (we want to compare installed device version and HCL compatlibility) Our environment is larger and complex.We have 4.0,5.0,5.5, 6.0 VC and ESXi version ,  and server brand is also variety,  IBM ,HP ,Sugon,Inspur,etc.

 

 

Look forward your kindly help. Thanks in advance.

FullFormattedMessage changing from "*Create virtual machine snapshot*" to "Task: VirtualMachine.createSnapshot"

$
0
0

One of my scripts stopped working and it turned out the FullFormattedMessage has changed for the snapshot events and I was wondering what could have caused this behavior?

 

My requirement was to produce a report that includes the user who created the snapshot and so I did, and it worked fine for a few months. To my knowledge we have not done any vCenter upgrades and/or DB work.

 

I was wondering why the report started coming back blank and it turned out FullFormattedMessage no longer contains the string I am looking for. I am using something like this:

PowerCLI C:\> $snapshots = Get-Snapshot -VM pnlvsprXXXX

PowerCLI C:\> Get-VIEvent -Start ($snapshots.Created).addminutes(-5) -Finish ($snapshots.Created).addminutes(5) -Entity $Snapshots.vm.name -Types info -maxsamples 20 | Where-Object {($_.FullFormattedMessage -like "*Create virtual machine snapshot*")}

PowerCLI C:\>

the above doesn't match anything

 

If I look at the event itself it now contains something else as FullFormattedMessage: "Task: VirtualMachine.createSnapshot". Also there is a slight discrepancy between the time stamp of the Get-VIEvent 07:59:47 and the time stamp 07:59:48 reported by the next snippet below:

Info                 : VMware.Vim.TaskInfo

Key                  : 14054888

ChainId              : 14054888

CreatedTime          : 16/05/2017 07:59:47

UserName             : XXXX\admin_XXXXX

Datacenter           : VMware.Vim.DatacenterEventArgument

ComputeResource      : VMware.Vim.ComputeResourceEventArgument

Host                 : VMware.Vim.HostEventArgument

Vm                   : VMware.Vim.VmEventArgument

Ds                   :

Net                  :

Dvs                  :

FullFormattedMessage : Task: VirtualMachine.createSnapshot

ChangeTag            :

 

PowerCLI C:\> Get-Snapshot -VM pnlvsprXXXX | Select VM,Name,@{Label="Size";Expression={"{0:N2} GB" -f ($_.SizeGB)}},Created | Sort-Object Created -descending

VM                  Name                Size                Created

pnlvsprXXXX         CHGXXXXXX-JD       10.61 GB            16/05/2017 07:59:48

 

To go around this I have amended the clause like this using "-or" but am still perplexed as to why the sudden change

Where-Object {($_.FullFormattedMessage -like "*Create virtual machine snapshot*") -or ($_.FullFormattedMessage -like "*VirtualMachine.createSnapshot*")}

 

PowerCLI C:\> Get-VIEvent -Start ($snapshots.Created).addminutes(-5) -Finish ($snapshots.Created).addminutes(5) -Entity $Snapshots.vm.name -Types info -maxsamples 20 | Where-Object {($_.FullFormattedMessage -like "*Create virtual machine snapshot*") -or ($_.FullFormattedMessage -like "*VirtualMachine.createSnapshot*")}

Info                 : VMware.Vim.TaskInfo

Key                  : 14054888

ChainId              : 14054888

CreatedTime          : 16/05/2017 07:59:47

UserName             : XXXX\admin_XXXXX

Datacenter           : VMware.Vim.DatacenterEventArgument

ComputeResource      : VMware.Vim.ComputeResourceEventArgument

Host                 : VMware.Vim.HostEventArgument

Vm                   : VMware.Vim.VmEventArgument

Ds                   :

Net                  :

Dvs                  :

FullFormattedMessage : Task: VirtualMachine.createSnapshot

ChangeTag            :

 

Thanks in advance for sharing you knowledge and experiences around this!

 

George

Get VSAN Datastore Default Storage Policy

$
0
0

Hi guys,

 

Has anyone been able to get the default storage policy assigned to a VSAN datastore via powercli?

Keeping a VIServer Session Open or Inter-script Communication

$
0
0

I have been working on wrapping a working PowerCLI script with a GUI so the work of bulk VM creation can be handed off to another group of people. The script and what I have run into thus far can be seen here: Datastore and VMHost vs Cluster

 

Both the GUI and original script are working, I am just trying to marry the two with the least amount of overhead. The issue I am currently working through is the GUI script returns the information on the VMs to be created in an array table, like so:

 

My concern is around the best means to pass this array to the PowerCLI script, so that I am not recreating the Connect-VIServer connection (to multiple servers) multiple times. I am just curious if exporting the table to a csv is my best/only option. Can an entire array be passed to the script on calling? Is any level of inter-script communication supported as in other languages, or is there a supported method for opening the connection in one script and then running another script within the scope of that connection?

 

If I am overthinking it, please feel free to say so


How to create a VMDirectPath IO (Paththrough) device by using PowerCLI

$
0
0

Hi all,

 

I would like to create a VMDirectPath IO (Paththrough) device by using CLI.

Could you please provide me the command to achieve this through PowerCLI?

 

Thank you

MaaTaa

ESXi host QueryEvents alternative EventHistoryCollector questions

$
0
0

I am not in a vcenter environment, we only have one esxi host.

I am trying to "adjust" the VCheck script to run cleanly on a ESXi host (it is wrote for a vcenter environment.)

I am working on the below error...

The Vcheck plugin script is 14 VMs restarted due to Guest OS Error

 

Exception calling "QueryEvents" with "1" argument(s): "The requested operation is not implemented by the server."

 

Below is the VCheck code...

$EventFilterSpec = New-Object VMware.Vim.EventFilterSpec

$EventFilterSpec.Category = "info"

$EventFilterSpec.Time = New-Object VMware.Vim.EventFilterSpecByTime

$EventFilterSpec.Time.beginTime = (get-date).adddays(-$HAVMresetold)

$EventFilterSpec.eventTypeId = "TaskEvent"

 

$HAVMresetlist = @((get-view (get-view ServiceInstance -Property Content.EventManager).Content.EventManager).QueryEvents($EventFilterSpec) | ?{$_.FullFormattedMessage -match "reset due to a guest OS error"} |select CreatedTime,FullFormattedMessage |sort CreatedTime -Descending)

 

I have researched and found the reason its failing is because of QueryEvents

The QueryEvents API is not supported on the ESX server. It would only work for the VC. Therefore instead of the QueryEvents API you might want to use the EventHistoryCollector for tracking the events using the help of EventFilterSpec data object and CreateCollectorForEvents method. Using these you would be able to query both the VC and ESX server.

 

I think I am going to have to create a CreateCollectorForEvents that runs continuously, and the adjust the vcheck script to use EventHistoryCollector & EventFilterSpec to check against the CreateCollectorForEvents?

 

I new to powercli and wanted to ask for help on this one.

To sum it up, the above vcheck script works on vcenter, I am trying to modify it to work on a ESXi host.

Can anyone offer powercli examples of using EventHistoryCollector in place of QueryEvents?

 

Thanks

Error adding more than one PCI Passthrough device to vm with add-PassThroughDevice

$
0
0

I have a Cisco B200M4 with 2 NVIDIA M60 GPU's and am trying to add  the four GPU's to a VM as PCI passthrough devices.

 

I am able to configure the GPU's in the host as Passthrough devices and I can add the GPU's to a vm through the fat client and web client. When I try to add all four to a vm two are added then the other two throw an error.  Add-PassthroughDevice The maximum number of PCI devices has been reached for VM.

 

I tried

$esx  = Get-VMHost -Name $MyHostName

$MyVM  = Get-VM -Name $MyVMName

$esx | get-passthroughdevice | Where {($_.State -eq "Active") -and ($_.Name -like "NVIDIATesla*")} | add-PassThroughDevice -VM $MyVM

 

and

 

$MyGPUs = $esx | get-passthroughdevice | Where {($_.State -eq "Active") -and ($_.Name -like "NVIDIATesla*")}

$MyGPUs | foreach{add-PassThroughDevice -VM $MyVM -PassthroughDevice $_ }

 

I also tried adding the third by itself after adding two. add-PassThroughDevice -VM $MyVM -PassthroughDevice $MyGPUs[2]

 

Thanks.

VM ping lantency was imporved after added the second virtual adapter

$
0
0

Hello,

We met a strange issue yesterday.

below is server info;

 

vSphere version: ESX4.0

 

VM OS :  SLES10 sp2

 

Virtual adapter type: VMXNET3

VMTools Status : Normal

vSwitch network binding policy :base orignal Virtual port route.

 

 

Symptom:

 

Our business found there have a delay in related vm after holiday.

we ping -t  those VMs hold by ESX. and found  several hundred ms package lantency each at one short term.

 

Action:

1) Reboot affect VM and issue was not resolved ( Our host and VM continue running nearly to four years!)

 

2) manual to cutover affect vm to another vmnic and issue was not resolved also.

 

3) added the second Virtual adapter in VM editor and ping package lantency was observably improved.( We found that affect vm  had  cutover to another vmnic when add second virtual adapter that trigger a physical network failover accompany to appear two timeout package)  

 

So my question is why I added  the second Virtual adapter and ping lantency was improved and why triiger a netowk cutover?

 

why happen  ping lantency? ( we verify  CPU,RAM and network utilization and network team feedback.  both haven't andy problem).

 

if have any other trigger  will cause VM netwok cutover in a network teaming?

PowerCli to pull RDM info

$
0
0

I use the following script to pull matrix from all my vCenter's. We have some RDM's that I want to capture in this as well... is it doable?

 

When I say capture... Im looking to pull the # of RDM's as well as total space being used by them.

 

 

"Total Datacenters: $(@(Get-Datacenter).Count)"
"Total Clusters: $(@(Get-Cluster).Count)"
"Total ESX Hosts: $(@(Get-VMHost).Count)"
"Total VM's: $(@(Get-VM).Count)"
"Total Templates: $(@(Get-Template).Count)"
"Total LUN Datastores: $(@(Get-Datastore).Count)"
$TotalDatastoresCapacityMB = 0
Get-Datastore | ForEach-Object { $TotalDatastoresCapacityMB += $_.CapacityMB }
$TotalDatastoresCapacityGb = $TotalDatastoresCapacityMB/1024
"Total Size of LUN Datastores in GB: $TotalDatastoresCapacityGb"
Viewing all 16717 articles
Browse latest View live


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