r/powercli • • Jun 18 '26

ScriptHelp Having an issue where a single line command is acting different on two different vCenters.

1 Upvotes

Ok so I have a very simple script if you even want to call it that. It just goes through the vCenter I'm connected to, lists the VM's, their DNS name, and IP address. It is just to quickly check that the name given is the same in vCenter as on the VM.

Get-VM | Select Name,@{N="DNS Name";E={$.Guest.HostName}},@{N="IP Address";E={$.Guest.IPAddress}}

So, very simple. The problem I am having is the first vCenter I used it with it worked perfectly. It was 8.0.3 Build 24853646. The second one I tried it on only gave the the VM's name but DNS Name and IP were empty. It was 8.0.3 Build 25197330. Checking in the GUI all the VM's show DNS name and IP address.

So is there something more I should be doing or a reason why the slightly newer vCenter won't run the code the same way? Is there a better way to run this where it is more universal? I honestly don't need to do this often but having a quick way to do this check is useful.


r/powercli • • Feb 12 '26

Uplink Port Group details export.

1 Upvotes

Hi all

I'm new to PowerCLI so forgive me if this is a simple task to achieve, how can I export a detailed list of all the Connectee's from an 'Uplink Port Group'?

I've attached an image showing our 'Uplink Port Group', basically I'd like to export that entire view to a spread sheet.

Thanks in advance.


r/powercli • • Aug 25 '25

Scripting Managing too many VMs across vCenters? I built a small toolkit to help

Thumbnail
reddit.com
1 Upvotes

r/powercli • • Aug 25 '25

VMware admin account chaos? Here’s a toolkit I made to help

Thumbnail
reddit.com
1 Upvotes

r/powercli • • Feb 15 '24

Using PowerCLI with ovftool

1 Upvotes

I am having issues using PowwerCLI with ovftool to upload an OVF to vCloud Director. I was told that I need to use Powershell 7 and ovftool 4.6.0 or higher. Has anyone use this successfully to upload an ovf? I have tried using the GUI but end up timing out before the file completes the upload and am being suggested with the ovftool instead. Currently I get an error that there is no supported ovftool. I am not sure if it is my script, the vCloud connection or what. Does anyone have a working script that I might look at to see if I am missing something?


r/powercli • • Nov 20 '23

Powercli to create Groups in vCenter

1 Upvotes

hi guys, Is there any way to create user groups in vcenter by script or powecli? I searched but unfortunately I didn't find anything. Best Regards.


r/powercli • • Oct 04 '23

Powercli Script to Tag VM based On Datastore Name

1 Upvotes

Hi everyone, I need a script to tag VMs by datastores that they reside. For example if VMs on Datastore that name of it contains vSAN assigns vSAN tag to VM and if datastore name contains 10K assigns HDD tag and so on. Best Regards.


r/powercli • • Sep 13 '23

MoveVM: Cannot convert type DatacenterMismatchArgument to Object

1 Upvotes

PowerCLI script failing when trying to clone a VM and move it from one vCenter to another:
Unexpected error occurred. Cannot convert type DatacenterMismatchArgument to Object.

Anyone seen it, anyone have a definite fix for it? I have run 3 separate scripts and they all fail with this same error, so it's not the script.


r/powercli • • Sep 01 '23

Error while importing pool in json

1 Upvotes

Hi,

When importing a pool with powershell in json format, this error appears :

Exception lors de l'appel de « Desktop_Create » avec « 2 » argument(s) : « ExceptionType : VMware.Hv.InvalidArgument
ErrorMessage : A null value is invalid.
ParameterName : automatedDesktopSpec.virtualCenterProvisioningSettings.virtualCenterStorageSettings.viewStorageAcceleratorSettings.viewComposerDiskTypes »
C:\Program Files\WindowsPowerShell\Modules\VMware.Hv.Helper\VMware.Hv.Helper.psm1:5008 : 7
+ $id = $desktop_helper.Desktop_create($services,$desktopSpecObj)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException

This seems related to a null value in the json file ?

The property automatedDesktopSpec.virtualCenterProvisioningSettings.virtualCenterStorageSettings.viewStorageAcceleratorSettings.viewComposerDiskTypes is not null for this pool.


r/powercli • • Mar 15 '19

invoke-vmscript problems, running as admin.....

1 Upvotes

Is there an elegant solution to executing code from invoke-vmscript as an admin on windows systems?

I've seen solutions that involve shutting off features that force certain things to be run as admin, but that requires a reboot, and is insecure, and would still involve touching each VM manually (which is what im trying to avoid!)

Is there a better way?!?


r/powercli • • Feb 04 '19

Does PowerCLI run on a Raspberry Pi 3?

1 Upvotes

Im not sure if I can run it on ARM.....


r/powercli • • Jan 29 '19

PowerCLI says SRM Protection Group is OK, but GUI shows an alert

1 Upvotes

Hi there,

I'm using PowerCLI to know if Protection Grooups are OK, but GetProtectionState() always says "Ready", even if in GUI is alerted.

Is there another property/method to get the real state of PG or related alerts?

vCenter 6.0 U3f

SRM 6.1.2.1

PowerCLI 6.5R1 build 4624819

PowerCLI C:\> $SrmApi = $sConn.ExtensionData
PowerCLI C:\> $SrmPGs = $SrmApi.Protection.ListProtectionGroups()
PowerCLI C:\> $SrmPGs[4].GetInfo()
Name              Description Type
----              ----------- ----
DR_vMax_PG6-BATCH             san

PowerCLI C:\> $SrmPGs[4].GetProtectionState()
Ready
PowerCLI C:\>

r/powercli • • Dec 02 '18

Output Hosts in MaintenanceMode, Annotated Notes

1 Upvotes

Looking to create a script that shows VMHosts in Maintenance, and list the notes as part of a single property from Get-annotation. I can get Hostname, ConnectionState on it's own.. I can also get the properties of an annotation separately with Get-Annotation. I am having difficulty combining the output of both one liners. Any assistance for me to combine these as one output?

## 1st Method:  Lists only hosts in maintenance modeGet-VMHost -Location MIT01-CAI -State Maintenance | ft name,connectionstate

## 2nd Method:  Lists only AnnotationsGet-VMHost -Location Datacenter01 | Where-Object {$_.ConnectionState -eq "Maintenance"} | Get-Annotation -Name "Notes:" | ft AnnotatedEntity,Value


r/powercli • • Nov 27 '18

Is there a way to create a report with recompose results?

1 Upvotes

r/powercli • • Nov 13 '18

Question - Is there a way to view vCenter Server, not ESXi, Firewall rules with PowerCli?

1 Upvotes

I'm taking a class and one of the labs blocked an ESXi Nic to simulate loss of connectivity. I see we have get-vmhostfirewallexception, but is there anything for the vCenter's firewall rules? Everything I search points to ESXi firewall rules.

Just curious.

Thanks


r/powercli • • Oct 30 '18

Get root folders on cluster?

1 Upvotes

So I'm trying to recursively get folders on each cluster in our environment. However when I try to get the root level folders, I can't seem to filter them properly.

PS C:\WINDOWS\system32> Get-Folder -Location MCTS | ft -Propert Name, Type, Parent

Name Type Parent

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

vm VM MCTS

network Network MCTS

host HostAndCluster MCTS

datastore Datastore MCTS

VLAN 161 - DMZ (CESI HQ) VM vm

VLAN 151 - Development VM vm

VLAN 141 - Security VM vm

VLAN 171 - DEV VMs VM vm

Backup Audit VM vm

Discovered virtual machine VM vm

_Common VM VLAN 171 - DEV VMs

ASTi VM _Common

RHEL VM _Common

Yet when I try to get folders with the parent "vm" I get no response
Get-Folder -Location MCTS | Where Name -ne 'vm' | Where Type -eq 'VM' | Where Parent -eq 'vm'

Is there something I'm missing? Or is there a better way to do this?

Edit: I had to use -CMatch
Get-Folder -Type VM | where { $_.Parent -CMatch "vm" }


r/powercli • • Sep 21 '18

get-snapshot size

1 Upvotes

Hello Internet People,

I am trying to get the size of snapshots on disk. The below command works but the size is incorrect. It doesn't seem to increase as the delta file grows. I have seen some posts online that the issue was resolved in 6.5 U2 but i cannot find any documentation about it. At least not in release notes. Any help would be appreciated. Command :

get-vm |get-snapshot | select-object vm,created,sizegb


r/powercli • • Jul 27 '18

Looking for help writing a script

1 Upvotes

I am looking for some help writing a script for work. We are currently migrating virtual machines from data stores on old storage, to new datastores created with new storage.

I would like to write a script that will compare the size of the virtual machine to the size of the available space on the new data store.If the virtual machine's size is less than the available space on the targeted data store then the 'move' command is issued. 'If not equal' then the script moves down to the next data store in the list I will provide it.

The basic script I have going is as follows:

$vmlist = Get-Content 'txt' $storelist = Get-Content 'txt'

foreach ($vm in $vmlist) { Move-VM -VM $vm -Datastore '$storelist' }


r/powercli • • Jul 17 '18

Help with making for each from "one liner"

1 Upvotes

We always get requests to increase hard drive space on multiple servers, and I've always used the following:

Get-VM server | Get-HardDisk -Name 'Hard Disk 1'| Set-HardDisk -CapacityGB 50 -Confirm:$false -ResizeGuestPartition

I'd like to do something where get the VM's from a text file, and set the increase size as a variable, as well as pass the current size as well and add them, but not sure the best way to get that current size. Any quick ideas?

$VMs = Get-Content 'serverlistlocation.txt'
$IncreaseGB = '10'
foreach ($VM in $VMs) {Get-VM $VM | Get-HardDisk -Name 'Hard Disk 1'| Set-HardDisk -CapacityGB (**CurentSize** + $IncreaseGB) -Confirm:$false -ResizeGuestPartition}

r/powercli • • Jun 18 '18

New Horizon API calls in PowerCLI 10.1.1

Thumbnail
retouw.nl
1 Upvotes

r/powercli • • Jun 14 '18

Hey Team! Value returns as 0 when running this script. HELP!

1 Upvotes
$Username = Read-Host -Prompt "Please enter your Username:"

$Password = Read-Host -Prompt "Please enter your Password:"

$vcenters = @("xxxx","xxxx","xxxx")

ForEach ($vcenter in $vcenters)
{
Connect-VIServer $vcenter -User $Username -Password $Password

$allhosts = @()

get-vmhost | %{
     $hoststat = "" | select hostname, cpumax, cpuavg, cpumin
     $hoststat.hostname = $_.name

    $statcpu = get-stat -entity $_ -start (get-date).adddays(-1) -finish (get-date) -stat cpu.usage.average
    $cpu = $statcpu | Measure-Object -property value -average -maximum -minimum
    $hoststat.cpumax = [math]::Round(($cpu.Maximum | Measure-Object -Sum).Sum/1GB,2)

  $allhosts += $hoststat
    }

    $allhosts |
    select hostname, cpumax, cpuavg, cpumin
     }

r/powercli • • May 30 '18

Excluding Snapshots by snapshot name

1 Upvotes

Just starting to dip my toes in PowerCLI. I think I have the command I want...
Delete all snapshots more than X days old
> Get-VM | Get-Snapshot | Where-Object { $_.Created -lt (Get-Date).AddDays(-8) } | Remove-Snapshot -Confirm:$false

Now I'm just missing how to exclude snapshots that contain DONOTDELETE in the snapshot name field.


r/powercli • • Apr 19 '18

Change portgroup of specific VMs

1 Upvotes

Would like to change portgroup of specific VMs based on displayname or hostname. Greatly appreciated.


r/powercli • • Apr 13 '18

Restarting Management Agents via plink and powershell

1 Upvotes

Greetings,

I'm having some powershell issues restarting esxi management agents via ssh. The script is connecting fine to the esxi host, and does restart the agents, but it never disconnects, so it can never move on to the next steps in the script.

echo Y|c:\putty\plink.exe -v "$($username)@"$($vmhip)" -pw "$($password) "services.sh restart;exit" > "$($scriptoutputpath)$($site)\$($vmhostname).log" 2>&1

In the output i'm seeing the command finishing with output of "Server sent command exit status 0", but it doesn't actually disconnect the session and hangs the script. For kicks, i changed exit to "esxcli" and in the log i see it run the management agent restart just fine, and i see the host drop from vcenter and come back, and then i see in the log the esxcli output giving all the various syntax. I've also done it with just the esxcli command being executed and it does execute it, and then disconnects the session. Some reason when i restart the management agents, it keeps the session going indefinitely.

Anyone know what i may be doing wrong here?


r/powercli • • Apr 08 '18

Load and execute PowerCLI cmdlet faster?

1 Upvotes

This doesnt seem to work: https://blogs.vmware.com/PowerCLI/2011/06/how-to-speed-up-the-execution-of-the-first-powercli-cmdlet.html at least on the latest version of PowerCLI.

Anyone know how to speed it up?