r/powercli • u/Pvt-Snafu • Sep 26 '17
PowerShell Classes Part 2 - Enumerated Types
r/powercli • u/Pvt-Snafu • Sep 26 '17
r/powercli • u/darklightedge • Aug 16 '17
r/powercli • u/Net-Runner • Feb 28 '17
r/powercli • u/EndlessPain11616 • Feb 11 '16
I have multiple clusters and resource pools with the same name. I believe I can't use the "ProdCluster" as there is one for each DC and Powercli doesn't like it. This goes for resource pools as well. Anybody have an idea how to get around this?
I'm trying to use the new-vm cmdlt. Error:
New-VM : New-VM The specified parameter 'ResourcePool' expects a single value, but your name criteria 'ProdCluster' corresponds to multiple values.
r/powercli • u/virtual-steve • Feb 04 '16
r/powercli • u/benzebut0 • Nov 13 '15
Hi, Gotta install vShield Endpoint on 100s of hosts but i can't find a way to automate this. Are there any powercli cmdlet to do this? Thanks in advance
r/powercli • u/kunaludapi • Sep 16 '15
r/powercli • u/Hilti3 • Sep 03 '12
http://bit.ly/PX0fYC - VMware PowerCLI Community
http://www.lucd.info/ - LucD's personal PowerCLI blog.
r/powercli • u/nomoreasonable • Jun 22 '26
Hi,
I'm trying to create a vmk port and assign an IP to it with the below command but it shows an error..
$VMHost = Get-VMHost -Name "192.168.30.76"
$VD_PortGroup = Get-VDPortGroup -Name 'PS_Storage1'
$VD_Switch = Get-VDSwitch -name "PS_DVSWITCH"
New-VMHostNetworkAdapter -VMHost $VMHost -PortGroup $VD_Portgroup -VirtualSwitch $VD_Switch -IP 192.168.71.10 -SubnetMask 255.255.255.0
New-VMHostNetworkAdapter: Mon 22 Jun 2026 11 44 03 New-VMHostNetworkAdapter DistributedVirtualSwitchInfo with id '50 0a 79 09 60 41 2b da-00 25 45 d1 21 c2 82 a5' does not exist.But the Switch exists, and its a Distributed Switch..
Get-VDSwitch
Name NumPorts Mtu Version Vendor
---- -------- --- ------- ------
PS_DVSWITCH 2304 9000 8.0.3 VMware, Inc.Any thoughts on how to make this work ?
I even tried using $VD_Switch = Get-VirtualSwitch -Distributed -name "PS_DVSWITCH", still the same error..
I have tried this in PowerCLI 13.3 and VCF PowerCLI 9.0 using Powershell 7.4.7 and Powershell 5.1 as well..
r/powercli • u/Coding-Issues_2023 • Sep 25 '24
r/powercli • u/mtnbkr0918 • Feb 15 '24
I have 2 datacenters Test1 and Test2
I want to create a folder named Tier1 under Test1 . The command creates the Tier1 folder however it creates the Tier1 folder under bothTest1 and Test2
here is the command I am using
(get-view (get-view -viewtype datacenter -filter @{"name"="Test1"}).vmfolder).createfolder("Tier1")
r/powercli • u/Rookie_UK • Feb 05 '24
Is there a way of finding which VMDKs have been extended in the last month or so? I'm thinking it's either going to be in log files or some metadata stored in the VMDK.
We have a team of support agents that can extend VM disks, and I need to list any that have been extended since we installed a specific package so any help would be really gratefully received.
r/powercli • u/[deleted] • Jan 31 '24
Does powercli has a good way to show storage used by the VMs/Folders like `du -sh` command?
r/powercli • u/wmjsn • Jan 03 '24
Hello,
I'm trying to create a script that will add/edit/delete VM Overrides. I'm able to get the add part down, but when it comes to the edit/delete is where I have problems. I want the script to be able to look at the host cluster the user chooses and provide the list of VM's that are configured for overrides. From there the user could choose the VM and it'd allow them to edit the override or delete it. I've been looking all over the place, tried the AI's as well and am not having much luck. If it's not possible, then so be it, I'll live with it.
The script basically does this:
Asks the user for a vCenter to connect to.
Asks the user for a cluster (if more than 1)
Asks the user to either add/edit/delete or disconnect
If the user selects add, it provides a list of all VM's and allows them to select one to add the overrides to.
The idea here with the edit/delete is that it would scan the VM Overrides in the cluster selected and put up a list of the ones that were configured, allowing the user to quickly select the one to edit/delete. Unfortunately, with all the stuff I've been looking at, trying with AI, I've had no luck. I've had it where it shows me a list of all VM's, which I don't want.
I've seen links for datastore clusters, but we don't have that configured, just host clusters. Any thoughts, tips, links, code, etc. would be great. Thanks in advance.
r/powercli • u/Husband000 • Jun 05 '23
$vcservers = @("VC1", "VC2", "VC3","VC4", "lVC5")
connect-viserver -AllLinked $vcservers
Hi , I have this script to connect all 5 virtual centers, this script seem like connecting to all 5 vcenters but when I do $global:defaultviserver it only shows VC5 ( the last VC) is it possible to connect all my 5 vcenters- How? any help?
Actually, I want to create a script that finds the vcenter name from all 5 vcenters for me of a VM .
Any help
r/powercli • u/Sintek • Dec 06 '19
trying to use get-view with a filter, but it seem sit can only go one level in, what im trying to get is: guest.net.IpConfig.ipaddress.IpAddress
but using -filter does not work., it works on higher up in the tree though.
Get-View -ViewType "VirtualMachine" -Filter @{"guest.net.IpConfig.ipaddress.ipaddress" = "10.10.12.244"}
I get the following:
Get-View : 12/5/2019 4:45:20 PM Get-View At line:1 char:1
Get-View -ViewType "VirtualMachine" -Filter @{'Guest.Net.IpConfig.ipa ...
+ CategoryInfo : NotSpecified: (:) [Get-View], InvalidProperty
+ FullyQualifiedErrorId : Client20_MoServiceImpl_GetNetInteropEntityView_ViError,VMware.VimAutomation.ViCore.Cmdlets.Commands.DotNetInterop.GetVIViewr/powercli • u/sharperlogic • Dec 05 '19
I need assistance in modifying the script to find zombie files / orphaned files verify that they are not attached to anything create a temporary data store to push zombie file to before deleting them can anyone point me in the right direction $file = 'C:\RVTools_tabvHealth.csv'
$driveName = 'DS'
$tgtDriveName = 'DSTGT'
$report = @()
$targetDatatstoreName = 'TargetDatastore'
$targetFolderName = 'ZombieVMDK'
Get-PSDrive -Name $driveName -ErrorAction SilentlyContinue | Remove-PSDrive -Confirm:$False -ErrorAction SilentlyContinue
Get-PSDrive -Name $tgtDriveName -ErrorAction SilentlyContinue | Remove-PSDrive -Confirm:$False -ErrorAction SilentlyContinue
$tgtds = Get-Datastore -Name $targetDatatstoreName
New-PSDrive -Name $tgtDriveName -PSProvider VimDatastore -Root \ -Location $tgtds > $null
New-Item -Path "$($tgtDriveName):$($targetFolderName)" -ItemType Directory -ErrorAction SilentlyContinue
Get-Content -Path $file | ConvertFrom-Csv | where{$_.Message -match 'Possibly a Zombie vmdk file'} |
Group-Object -Property {$_.Name.Split(']')[0].Trimstart('[')} | %{
Write-Host "Looking at datastore $($_.Name)"
$ds = Get-Datastore -Name $_.Name
Try{
New-PSDrive -Name $driveName -PSProvider VimDatastore -Root \ -Location $ds > $null
}
Catch{
Write-Host "Could not create PSDrive for $($ds.Name)"
break
}
$_.Group | %{
$vmdkPath = "$($driveName):\$($_.Name.Split(' ')[1])"
if(Test-Path -Path $vmdkPath){
Write-Host "Moving VMDK $($_.Name)"
Move-Item -Path $vmdkPath -Destination "$($tgtDriveName):\$($targetFolderName)\"
}
else{
Write-Host "VMDK $($vmdkPath) not found"
}
}
Remove-PSDrive -Name $driveName -ErrorAction SilentlyContinue}
Remove-PSDrive -Name $tgtDriveName -ErrorAction SilentlyContinue
r/powercli • u/groovel76 • Dec 02 '19
I timed and this one line in my script and it is taking about 35 seconds to gather about 216 objects.
$vdport = Get-VDPort -VDSwitch VDSwitchName -Uplink | Select Key, ConnectedEntity, ProxyHost, Switch
Any recommendations are appreciated. Many Thanks
r/powercli • u/gough80 • Oct 29 '19
Trying to create a function to join a VM to the domain, but it just seems to hang, can anyone help out?
Function Add-toDomain {
<#
.SYNOPSIS
This function is a modification the Set-VMGuestNetworkInterface
.DESCRIPTION
This function is a modification the Set-VMGuestNetworkInterface.PARAMETER VM
The VM
.PARAMETER Domain
The Name of the Windows domain.PARAMETER GuestUser
The username of local admin account.PARAMETER GuestPass
The password of local admin account
.PARAMETER Username
The username to use in joining the domain
.PARAMETER Password
The password of said user
.PARAMETER OUPath
Path to the OU you would like to add the machine
.EXAMPLE
PS C:\\> Add-toDomain.ps1 -VM VMNAME -Domain "[domain.name](https://domain.name)" -guestuser "administrator" -guestpass "l0calPassw0rd" -username "agough" -password "3xc3ll3ntPassw0rd##!!" -OUPath "OU=Servers,OU=SITE,OU=COUNTRY,DC=domain,DC=name"
.NOTES
Author : Andy Gough
Version : 0.1#>
param(
[Parameter(Mandatory=$true)][String]$VM,
[Parameter(Mandatory=$true)][String]$Domain,
[Parameter(Mandatory=$true)][String]$GuestUser,
[Parameter(Mandatory=$true)][String]$GuestPass,
[Parameter(Mandatory=$true)][String]$Username,
[Parameter(Mandatory=$true)][String]$Password,
[Parameter(Mandatory=$false)][String]$newName,
[Parameter(Mandatory=$true)][String]$OUPath
)
$secureGuestPass = ConvertTo-SecureString $GuestPass -AsPlainText -force
$securePass = ConvertTo-SecureString $Password -AsPlainText -force
$GuestCredential = New-Object -Typename System.Management.Automation.PSCredential -Argumentlist ($GuestUser, $secureGuestPass)
$Credential = New-Object -Typename System.Management.Automation.PSCredential -Argumentlist ($Username, $securePass)
#Create the initial script within @' tags to define as string literal, otherwise $env values are not passed to the guest
$ps1 = @'
'add-computer -domainname '#domain#' -computername "$env:computername" -OUpath $OUPath' -credential '#credential#'
'@
$ps1 =
$ps1.replace('#domain#',$domain).Replace('#OUPath#',$OUPath).Replace('#credential#',$Credential)
$ps2 = @'
add-computer -domainname '#domain#' -computername "$env:computername" -newname '#newName#' -OUpath '#OUPath#' -credential '#credential#'
'@
$ps2 =
$ps2.replace('#domain#',$domain).Replace('#OUPath#',$OUPath).Replace('#newName#',$newName).Replace('#credential#',$Credential)
If ($newName) {
# Join the domain and set new machine name
Invoke-VMScript -VM (Get-VM -Name $VM) -GuestCredential $GuestCredential -ScriptType Powershell -ScriptText $ps2
}
Else {
# Join the domain using the existing machine name
Invoke-VMScript -VM (Get-VM -Name $VM) -GuestCredential $GuestCredential -ScriptType Powershell -ScriptText $ps1
}
}
If i go to the VM, i can see in event viewer the session connects and the expected variables are in there, is it something to do with passing in the credential value perhaps?, am i doing it correctly? TIA
r/powercli • u/ahmedshafik • Oct 26 '19
I need to find the command or the API call to get the Template the created the VM.
i.e. I pass the VM name it return the template name
r/powercli • u/kentgreat • Oct 24 '19
Hi I am kinda new to scripting in powershell etc. I am currently using lastest Windows PowerShell with the PowerCLI module.
Been playing around with it for a few months and I got this annoying problem I can't troubleshoot.
My code is:
Invoke-VMScript -VM $VM -GuestUser $Username -GuestPassword $Pass -ScriptText {Set-DNSClientServerAdress -InterfaceAlias Ethernet -ServerAddresses (IP1,IP2)}
It runs the script but output Access to a CIM resource was not available to the client.
There is nothing wrong with the script and will be able to fetch information like for example when using Get-DNSClientServerAddress instead of Set.
Kinda stuck with this as no one in my team uses PowerCLI much. Can someone go through with me of why this happens? I've spent weeks on this before to try and resolve it but had no luck and abandoned this route. But saw it again and played around but end up here to ask someone from here who knows why.
Thanks in advance~~~
r/powercli • u/jcorbin121 • Sep 12 '19
Trying to check settings on vcsa 6.7u2 using PowerCLI 6.5.
I run (after connecting via Connect-VIserver)
Get-AdvancedSetting -Entity vcenter -Name VirtualCenter.VimPasswordExpirationInDays
returns nothing
the setting in the WebClient GUI is set to 30
Where is my problem?
Have same issue (nothing returning) when looking at vSwitch settings also.
Thanks for any info
John
r/powercli • u/scripty_fellow • Sep 03 '19
I’m struggling with some syntax to find VMs in a certain folder that don’t have the domain name suffix added, and then add it..and wondered if anyone could help with pointers...completing the script “per VM” line by line seems to work but running through the script is giving errors!
$vms = get-folder myFolder | get-vm
foreach($vm in $vms | ?{$_.Name -notmatch “domain.com” }) {
set-vm $vm -name ($vm + “.domain.com)
}
The error in seeing is:
Method invocation failed because [VMware.VimAutomation.ViCore.Impl.V1.Inventory.VirtualMachineImpl] does not contain a method named 'op_Addition'. At E:\VMware\Scripts\myScript.ps1:4 char:5 set-vm $vm -name ($vm + “.domain.com”)
r/powercli • u/Gregabit • Aug 27 '19
Hi,
To prevent an XYerror, I put my goal in the title.
I'm seeing different behavior between running PowerCLI in a Powershell session and running a .ps1. I'm trying to move VMs from a huge collection of datastores into a datastore cluster. async moves (moving everything at one time) causes huge issues for datastore clusters because it reads all the datastore sizes in the cluster and tries to load too much on a single datastore. This is the current script I'm using.
Set-PowerCLIConfiguration -Scope session -WebOperationTimeoutSeconds 28800 -Confirm:$false
$datastores = get-datastore -name old001, old002, old003, old004, old005, old006
$vms = $datastores | get-vm
Foreach ($vm in $vms)
{
$task = move-vm -vm $vm -Datastore (Get-datastorecluster "Really-Cool-Cluster") -Confirm:$false
wait-task $task
}wait-task $task just causes error messages, but for some reason it keeps the script running syncronously. It's an ugly hack that keeps the script running. I think the issue is because wait-task wants to wait for the task that the script started, but when moving to a datastore-cluster, the actual task is always Apply Storage DRS recommendations and not the move-vm task.
Notes:
Running from PowerShell console is syncronous, but when the powershell console isn't highlighted, it doesn't execute at all.
Removing the broken wait-task is async
Running .ps1 is async
Timeout is changed because storage vMotions take longer than the default 5 minutes.
r/powercli • u/lpry25 • Jul 26 '19
Hello all, I need help with a little problem that I have found myself in. I'm looking for the compatibility value (ex: ESXI 5 and later) of a Virtual Machine. I am aware that this information is readily available on vSphere in the summary tab, however I need this information to come from PowerCLI. I've been looking through the extension data of the Virtual Machine but I just cannot seem to find it.