I noticed that when I update-module PowerCLI the old versions aren't removed.
Is there a way to cleanup this ? i.e. automatically remove the old module versions ?
Of course I can do this manually but hey we are automating stuff here
I noticed that when I update-module PowerCLI the old versions aren't removed.
Is there a way to cleanup this ? i.e. automatically remove the old module versions ?
Of course I can do this manually but hey we are automating stuff here
Hi there,
I'm trying to build a powercli script to perform the following actions:
Poweroff a list of VMs
VMotion to the new hosts
Upgrade VM Hardware and tick the VMware Tools upgrade at next power cycle box
SVMotion the VMs to the storage
Start up the VMs
The problem I'm getting is when the SVMotion is started the script doesn't wait for it to finish to start up the VMs. I tryied with the Wait-Task, but the problem is that the Move-VM task itself finishes but the SVMotion is still running.
Can someone help me here please.
Thanks
This is the script I'm using: (please note I'm new to powerCLI)
# List of VMs to move and Upgrade
$vms = Import-CSV "C:\tmp\list_of_vms.csv"
# Shutdown gracefully and wait for Power Off state
foreach ($vm in $vms){
Get-VM -Name $vm.name | Shutdown-VMGuest -Confirm:$false
}
do {} until ((Get-VM $vm.name | select PowerState).powerstate -eq "PoweredOff")
# VMotion VMs to the new Cluster and Upgrade Hardware Version and VMware Tools
foreach ($vm in $vms){
Move-VM -VM $vm.name -Destination $vm.targetHost -RunAsync
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo
$vmConfigSpec.Tools.ToolsUpgradePolicy = "UpgradeAtPowerCycle"
Get-View -ViewType VirtualMachine | %{
$_.ReconfigVM($vmConfigSpec)
}
Set-VM -VM (Get-VM -Name $vm.name) -Version v11 -Confirm:$false -RunAsync
Move-VM -VM $vm.name -Datastore $vm.targetDataStore -RunAsync
Start-VM -VM $vm.name -Confirm:$false -RunAsync
}
Hello!
The main question in topic. I tried this one example:
$VM = get-civm 'centos_template'
($VM.ExtensionData.Section | where {$_ -is [VMware.VimAutomation.Cloud.Views.guestCustomizationSection]}).computername = 'centos'
But it's not working...
I found some useful article how to set some parameters of VM here GeekAfterFive - Infrastructure as Code . Looks like that is possible, but you must know exact section and property. Where can I get this?
And the second quiestion.
The performance of requests through the powershell module is a bit sloooow. Is it by design or it depends on performance inside the Vcloud Provider I'm connecting to? In my org connection latency to cloud is ~7ms.
Thanks.
Hi!
I'm trying to connec to to a vCenter server from powershell session with PowerCLI module loaded but receive the following error:
Connect-VIServer : Could not load file or assembly 'VMware.Vim, Version=6.7.0.185, Culture=neutral,PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.At line:1 char:1
Here is the script code:
#Unload existing PowerCLI
If (Get-PSSnapin | ? {$_.Name -like "VMware*"}) { Get-PSSnapin VMware* | Remove-PSSnapin }
If (Get-Module | ? {$_.Name -like "VMware*"}) { Get-Module VMware* | Remove-Module -Force }
#Import PowerCLI v11
$ModulePath = $PSScriptRoot +"\Modules\VMware-PowerCLI-11.2.0.12780525"
$env:PSModulePath = $ModulePath
Import-Module VMware.VimAutomation.Core
#Set PowerCLI configuration
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Scope Session -DisplayDeprecationWarnings:$false -Confirm:$false | out-null
Connect-VIServer ********
....
....
$env:PSModulePath variable does not contain old PowerCLI paths and after loading new path to $env:PSModulePath shows :
PS C:\Users\a> get-module -listavailable
Directory: D:\*******\Modules\VMware-PowerCLI-11.2.0.12780525
ModuleType Name ExportedCommands
---------- ---- ----------------
Script VMware.DeployAutomation {Add-DeployRule, Add-ProxyServer, Add-ScriptBundle, Copy-DeployRule...}
Script VMware.ImageBuilder {Add-EsxSoftwareDepot, Add-EsxSoftwarePackage, Compare-EsxImageProfil...
Manifest VMware.PowerCLI
Script VMware.Vim
Script VMware.VimAutomation.Cis.Core {Connect-CisServer, Disconnect-CisServer, Get-CisService}
Script VMware.VimAutomation.Cloud {Add-CIDatastore, Connect-CIServer, Disconnect-CIServer, Get-Catalog...}
Script VMware.VimAutomation.Common
Script VMware.VimAutomation.Core {Add-PassthroughDevice, Add-VirtualSwitchPhysicalNetworkAdapter, Add-...
Script VMware.VimAutomation.Hcx {Connect-HCXServer, Disconnect-HCXServer, Get-HCXAppliance, Get-HCXAp...
Script VMware.VimAutomation.HorizonView {Connect-HVServer, Disconnect-HVServer}
Script VMware.VimAutomation.License Get-LicenseDataManager
Script VMware.VimAutomation.Nsxt {Connect-NsxtServer, Disconnect-NsxtServer, Get-NsxtPolicyService, Ge...
Script VMware.VimAutomation.Sdk {Get-ErrorReport, Get-InstallPath, Get-PSVersion}
Script VMware.VimAutomation.Security {Get-SecurityInfo, Get-VTpm, Get-VTpmCertificate, Get-VTpmCSR...}
Script VMware.VimAutomation.Srm {Connect-SrmServer, Disconnect-SrmServer}
Script VMware.VimAutomation.Storage {Add-KeyManagementServer, Copy-VDisk, Export-SpbmStoragePolicy, Get-K...
Script VMware.VimAutomation.StorageUtility Update-VmfsDatastore
Script VMware.VimAutomation.Vds {Add-VDSwitchPhysicalNetworkAdapter, Add-VDSwitchVMHost, Export-VDPor...
Script VMware.VimAutomation.Vmc {Connect-Vmc, Disconnect-Vmc, Get-VmcSddcNetworkService, Get-VmcServi...
Script VMware.VimAutomation.vROps {Connect-OMServer, Disconnect-OMServer, Get-OMAlert, Get-OMAlertDefin...
Script VMware.VumAutomation {Add-EntityBaseline, Copy-Patch, Get-Baseline, Get-Compliance...}
Get-Module also shows different VMware.Vim that in the error:
PS C:\Users\a> Get-Module | select ModuleType,name,version
ModuleType Name Version
---------- ---- -------
Manifest Microsoft.PowerShell.Management 3.0.0.0
Manifest Microsoft.PowerShell.Utility 3.0.0.0
Script VMware.Vim 6.7.0.12483609
Script VMware.VimAutomation.Cis.Core 11.2.0.12483642
Script VMware.VimAutomation.Common 11.2.0.12483627
Script VMware.VimAutomation.Core 11.2.0.12483638
Script VMware.VimAutomation.Sdk 11.2.0.12483635
Which is quite weird imho...
PowerCLI 5.5 is installed on the following machine (do not ask me to remove or update it, I cannot modify it). If i remove PowerCLI 5.5 from the system- everything works fine. But i cannot remove it.
Any ideas how can I resolve it and import PowerCLI 11 without removing 5.5 into a powershell session?
P.S. OS is w2012 (not R2), and it is isolated from the Internet.
HI guru
Does anyone has a script that will let me know which VM in a cluster has an RDM disk on disk mode Non-Persistent.
is this even possible?
Thanks a bunch gurus
Hello.
Anybody have powercli script for tags cleaning: find tags that no attached to any object and delete them?
advanced apology/warning!:
I have tried to format my post to show the script nicely/properly using guide I was previously pointed to by a member on here but it just won't (not sure if it's because it's quite long!) so my apologies ( I had this trouble before so I've attached my script instead)
my script is basically looping through every server on my estate, and determining a bunch of things and then getting the uptime of that server via the os guest (wasn't happy with the stat from the hosts itself) . it works fine until it finds a server where invoke-vmscript returns the error "the guest operations agent is out of date"
fine don't mind that i'll just pipe that in my csv, move on and look at it after.. problem is - it stops my script dead, instead of continuing on through the estate (of which I suspect there to be more or the same error)
I thought by checking the tool status (which can seen in the ELSE of the first IF) before going down to the level of the actual OS checking it would filter/capture it but it seems to be ignoring this. How would I go about doing this with invoke-vmscript? do I simply need to do another if and do something based on the scripts output.
any guidance is appreciated
Hello,
I feel stupid but I can't move a VM into a specific VM folder ?
When I do it the old way, using "-Destination" I get a warning about "destination switch" being deprecated + an error telling me that index is out of array bounds.
Okey.
I do it using -InventoryLocation, no warning, but still out of bounds.
Please tell me what am I doing wrong ?
PS C:\Users\Shar> $vm = get-vm "tests-guillaume-infra-sn"
PS C:\Users\Shar> $vm
Name PowerState Num CPUs MemoryGB
---- ---------- -------- --------
tests-guillaume-i... PoweredOff 2 4,000
PS C:\Users\Shar> $folder = get-folder -name WSUS
PS C:\Users\Shar> $folder
Name Type
---- ----
WSUS VM
PS C:\Users\Shar> Move-VM -InventoryLocation $folder -VM $vm
Move-VM : 29/03/2019 14:44:28 Move-VM L'index se trouve en dehors des limites du tableau.
Au caractère Ligne:1 : 1
+ Move-VM -InventoryLocation $folder -VM $vm
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Move-VM], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.MoveVM
I found by luck that there seems to be a new cmdlet, "Move-Inventory" but still same error :
PS C:\Users\Shar> Move-Inventory -Item $vm -Destination $folder
Move-Inventory : 29/03/2019 14:51:04 Move-Inventory L'index se trouve en dehors des limites du tableau.
Au caractère Ligne:1 : 1
+ Move-Inventory -Item $vm -Destination $folder
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Move-Inventory], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.MoveInventory
PS C:\Users\Shar> $PSVersionTable
Name Value
---- -----
PSVersion 5.1.14393.576
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14393.576
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
PS C:\Users\Shar> Get-Module VMware.PowerCLI
PS C:\Users\Shar> Get-Module VMware.PowerCLI -ListAvailable
Répertoire : C:\Program Files\WindowsPowerShell\Modules
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Manifest 11.2.0.... VMware.PowerCLI
Manifest 11.0.0.... VMware.PowerCLI
--EDIT--
I just checked with same powercli but against a vcenter 6.0, no problem
So this may be a bug with vcenter 6.7 ?
Hello, first of all I'd like to inform that I'm not able to open a thread by simply logging into the VMware communities. I'm redirected to "temporary unavailable" message due to maintenance etc..etc.. while if I login through MyVMware I'm able to.
My question: how to identify vMotion or Management portgroup in a dVS? I'm not able to find anything in the extensionData options available in:
Get-VDPortgroup -VDSwitch $VDSwitch
I need it as I'm preparing a script where newly added hosts will have their vmk0 migrated to the management network PG.
Hi,
A newbie question:
How can I find out which Datacenters are using the same Datastore.
The command I'am using is:
Hello
I tried to make the Backup-VCSAToFile work in my development environment.
vSphere 6.5 – Automate VCSA Backup » Brian Graf's Virtualization Blog
I'm stuck here:
A server error occurred: 'com.vmware.vapi.std.errors.unauthorized': Unable to authorize user (Server error id:
'vapi.security.authorization.invalid'). Check $Error[0].Exception.ServerError for more details.
In Zeile:1 Zeichen:1
What did I do?
Windows 7 VM, installed VMware Powershell 6.5
Started ISE
loaded modules
Import-Module VMware.VimAutomation.Core
Import-Module VMware.VimAutomation.Vds
Import-Module VMware.VimAutomation.Cloud
Import-Module VMware.VimAutomation.PCloud
Import-Module VMware.VimAutomation.Cis.Core
Import-Module VMware.VimAutomation.Storage
Import-Module VMware.VimAutomation.HorizonView
Import-Module VMware.VimAutomation.HA
Import-Module VMware.VimAutomation.vROps
Import-Module VMware.VumAutomation
Import-Module VMware.DeployAutomation
Import-Module VMware.ImageBuilder
Import-Module VMware.VimAutomation.License
loaded the script itself as module (necessary?)
connected to vcsa with connect-viserver
Used given example in the script with my parameters.
Then I get a pop up
(Connection to CisServer)
I don't know what that is.
If I use my credentials for the vCenter connection - AD authentication, I get that error
Backup-VCSAToFile:Aservererroroccurred:'com.vmware.vapi.std.errors.unauthorized':Unabletoauthorizeuser (Servererrorid:
'vapi.security.authorization.invalid').Check$Error[0].Exception.ServerError formoredetails.
InZeile:1Zeichen:1
Any hints?
https://code.vmware.com/web/tool/11.2.0/vmware-powercli
VMware-PowerCLI-11.2.0-12780525.zip
download link not update!
Hello there,
I've found many thread and forum that were subject to this bug (?), but I didn't find a solution that suits my environnement...
I'm working on a Linux CentOS 7 with a PowerShell 6.1.1 package on it. I'm trying to make a loading print that show PowerCli commands is still running and is not crashed 'cause sometimes it's... Very... Very long...
The issue is when I run the loading script the jobs never ends, the only one way to make them finish properly is to redirect output, if there are output directed to the console it hangs.
However I want to keep the object that are returned from my jobs commands, I tried to Export-Clixml those outputs but the issue happens in this situation and I didn't find a way to export my objects in a xml file and avoid the issue by redirecting the output, if I do both export and redirect the xml file is empty.
I've tried with simple commands passed to the -ScriptBlockString parameter, like Get-VM.
This script is adapted from this one: http://www.vxav.fr/2017-08-08-easily-run-powercli-commands-as-jobs/
Thanks !
I've been seeing this warning message when calling New-OSCustomizationNicMapping for a while now. No one seems to have commented on it anywhere online, which is odd.
I create my customization using New-OSCustomizationSpec and pass it to New-OSCustomizationNicMapping.
What is the proper thing to do here? Continue to ignore this nonsensical warning?
All,
I have VMs protected by ReocverPoint appliance and under VM summary tab it shows all relevant information. (Please refer attached screenshot). I would like to click on Unprotect button as shown in screenshot.
I am not able to find it using get-view method. Any suggestion?
Hello,
I am trying to build a powercli script to vmotion/svmotion bulk of VMs at the same to other cluster using a CSV.
I found something but it will start first VM and wait to complete then start the second. my request is simultaneous move.
Any help it will be appreciated,
Hi all,
This is my first post on here so please be gentle with me, I am relatively new to Powershell and PowerCLI for VMWare and have delved into attempting to use 'get-esxcli -vmhost v2' against a list of hosts to retrieve the hba adapter details, specifically vmhba driver detail in order to investigate a san connectivity issue.
Once connected, I then drill into this content as follows to retrieve the fc detail I am after, $host.storage.san.fc.list.invoke()
This works fine for newer Synergy 480 Gen10 hardware but for older kit such as a ProLiant BL460c Gen9, It does not list the adapter driver details.
Does anyone know what I am either doing wrong or what I can do to retrieve the details I am after using PowerCLI, I have found other scripts which use ssh via plink and stop/start the ssh service per ESXi host but I find this a bit clunky and unsecure.
Many thanks in advance.
Hi All,
I need to query and possibly set HA settings in particular " Heartbeat Monitoring Sensitivity" (See Screenshot Attached)
Hi,
I am getting the below error, while deploying VM from a template.
Everything works well expect the first part assigning the IP address
Please help.
Set-OSCustomizationNicMapping : 01-04-2019 11:36:34 | Set-OSCustomizationNicMapping | When the IpMode parameter is set to UseStaticIp, you must specify the IPAddress, Subnetmask, Dns |
(on Windows
specs only), and DefaultGateway parameters.
At D:\deploy_Template\testdeploy.ps1:7 char:74
+ ... icMapping | Set-OSCustomizationNicMapping -IpMode UseStaticIp -IpAddr ...
+ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
+ CategoryInfo | : InvalidArgument: (:) [Set-OSCustomizationNicMapping], ViError | |
+ FullyQualifiedErrorId : Core_NicMappingCmdletBase_ValidateParameters_RequiredParametersSaticIp,VMware.VimAutomation.ViCore.Cmdlets.Commands.SetOSCustomizationNicMapping |
The command “get-usbdevice”(also “Remove-UsbDevice”) should retrieve the USB devices that could be located on a VM. The problem is that cmdlt only will display those USB devices, if a USB device is currently connected. It will not report anything if the VM has added USB hardware but it currently isn’t connected to anything (ie Just a USB controller).
Now there are other ways that I can go about finding if the VM has that unwanted hardware:
$unwantedhw = “floppy|serial|usb” (Get-VM $VMname | Get-View).Config.Hardware.Device | Select -Expand DeviceInfo | Select Label, Summary | where {$_.Label –match $unwantedhw}
I just would of thought that instead of having to go back to some get-view shenanigans, I could do it directly with 1 command like the command “Get-UsbDevice” should do in my opinion. I could to try to write my own function (ie Get-USBController) for this and store it in my profile, but I dont have the time on hand atm.
Has anyone else created this function or know of any updates to the PowerCLI to include this in a later feature release??
Versions of PowerCLI:
VMware vSphere PowerCLI 5.0.1 build 581491
VMware AutoDeploy PowerCLI Component 5.0 build 544967
VMware ImageBuilder PowerCLI Component 5.0 build 544967
VMware vCloud Director PowerCLI Component 1.5 build 581492
VMware License PowerCLI Component 5.0 build 544881
VMware vSphere PowerCLI Component 5.0 build 581435
VMware vSphere Update Manager PowerCLI 5.0 build 432001