What is the best method for enabling this option on all VMs? Is there a good way to do it without either editing the VMX files on every machine or doing it manually though edit settings?
Need script to enable "Check and upgradetools during power cycling" on all VMs
The remote server returned an error: (503) Server Unavailable.
Can anyone help on this...
While connecting to vCenter through Power CLI using C# code got the below error.
System.Net.WebException: The remote server returned an error: (503) Server Unavailable.
at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context)
at System.Net.HttpWebRequest.GetRequestStream()
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
at VimApi_60.VimService.RetrieveServiceContent(ManagedObjectReference _this)
at VMware.Vim.ServiceInstance.RetrieveServiceContent()
at VMware.Vim.VimClientImpl.Connect()
at VMware.Client.VMwareClient..ctor(String ip, String username, String password)
Power CLI 6.3 vCenter connection failing ...
Using Power CLI 6.3, connection failing to vCenter with username and password.
System.Net.WebException: The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel. ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.
at System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, Exception exception)
Did anyone faced similar issue. ...
How we can download certificate from vCenter using username and password ?
Add User to DCUI Access using PowerCLI
Hello There
Is everyone know how to add user (instead of root ) in advanced setting to have DCUI access in VMware ESXi5.1 using power cli?
In Addition I read the Article below and it doesn't work.
Thanks
How to know if a a script is running on vcenter ?
Hi there,
Ask myself about how to know if a script was played on a vcenter, any idea to ckeck that ?
We got some trouble with one of our vcenter like huge latency and deconnexion, and i suspect someone is playing a powercli script.
So if you now of to check that i ll be gratefull
thanks
vshield Endpoint driver check via PowerCLI for specific VM only.
Hello,
I gave thankful reply as below link before.
I have a one more question.
The below main script is only for all of the VM.
If the target VMs were 500, and login fail VMs were 200!.
I need to run the script for 200 login fail VMs.
is it possible to run the script for specific VM?
for example, target vm list is in textfile(notepad) then run the script from the text file.. is it possible?
I hope to understand, but I am not good at English..
Thank you.
FYI, below is main script!
$vms=GET-VM| Where-Object {$_.PowerState -eq"PoweredOn" }
ForEach($vmin$vms)
if (Get-VMguest-VM$vm|Where-Object {$_.OSFullName -like"*Microsoft*"})
try{
$out=Invoke-VMScript-VM$vm-GuestUser"administrator"-GuestPassword"vmware1!" `
-ScriptText"sc query type= driver | find `"vsepflt`" "-ScriptTypebat-ErrorActionStop|
Select-ExpandPropertyScriptOutput
catch[VMware.VimAutomation.ViCore.Types.V1.ErrorHandling.InvalidGuestLogin]{
$out="Invalid logon"
catch{
$out="Other error"
Write-Output"VM: $($vm.Name): $out"
Powercli script to list all flows
Hi there,
Want to know if there is a way to list all inbound and outbound connection with IP and port for a vcenter infrastructure.
Try to it with span and dvs but seem tricky, also Vmware infrastructure navigator maybe can do that.
But for sure i think we can do it with powercli just want to confirm with you if it's already exist.
Thanks !
unmap timeout?
Hi All,
I've been trying to script an unmap of our datastores using powercli.
This lead me to this fantastic post and script/s,
Like others in this discussion I continue to have a problem with the unmap command timing out on the powercli window. It just hangs and seems to be waiting for a response from the esxcli unmap command, however from the ESXi host I can tell that the command has completed.
I added the following command to the script without any changes.
Set-PowerCLIConfiguration -Scope Session -WebOperationTimeoutSeconds -1
The previous workaround which seems to have worked was to change the unit count (number of blocks per call of unmap) to a much higher number. In the script it is 0.5% of the free space. This results in a much quicker execution and is below the timeout, so everything works.
However ESXi has changed the way it allows unmaps with high unit counts, so that its no longer possible to change the unit count if the datastore free space is less than 25%. It reverts to the default of 200 and results in a timeout in powercli.
https://drewtonnesen.wordpress.com/2015/07/26/unmap-in-esxi-5-5-p3/
I've tried to log an SR (15832009712) but GSS doesn't support PowerCLI. I was referred to VMware SDK and API Support | United States however we don't have API/SDK support (just the normal production GSS support).
My Current Situation
- PowerCLI waits definitely for a response from the unmap command if the default unit size is used on a large datastore.
- If <75% and unit size changed, it works.
- If datastore is quite small with 200 unit size ~1TB, it works.
I don't know if this is PowerCLI timeout, vCenter or even ESXi. All i know at present is that the powercli window says its executing the script and seems like its waiting for a response from the unmap command.
A previous post when using a different script (had same issue but the issue wasn't understood at the time) resulted in only 1 reply saying they had the same issue.
unmap - only unmaps first datastore
I've looked into running the command async and then a sleep, as a job, but I don't know powershell enough to pull off an advanced topic such as that.
If anyone has a working version of an unmap script, I would appreciate to understand how you got around this issue.
New-VM -- when adding exist vm to new VCenter, Mem, CPU, and Disk are incorrect
Hi,
When I run the following:
New-VM-VMFilePath $VMXFile -VMHost $ESXHost -RunAsync -Confirm
Just before it adds to inventory, it shows the vm will get a default number of CPUs, amount of memory, and certain size hard disk (sorry I can't run it now to get the exact values).... However, when the vm gets imported it keeps its original settings.
Does anyone know why, how to fix this message? I don't want the user to think the configuration is changing.
Thanks,
Jen
Memory question - Sizing properly (this may be the wrong forum, please suggest a better one.
I have a (5) node cluster, each with 96GB ram. I am getting constant "Host memory usage" alarms, yet my active mem is 74GB max (across the cluster)
Running Lucd's memory script (below) - I get a MemoryConsumedGB of 54GB. If each host has 96GM, how could I be having any memory alerts?
Get-VM | Select-Object Name, MemoryGB,@{N='MemoryConsumedGB';E={
[math]::Round((
(Get-Stat -Entity $_ -Start (Get-Date).AddDays(-7)-Stat 'mem.active.average' |
Measure-Object -Property Value -Average | Select-Object -ExpandProperty Average)/1MB),1)}
} | export-csv c:\temp\Get-VM-AvgMemUsage-$dateTime.csv -NoTypeInformation
Thanks-
-Cliff
Output list to CVS or Excel
I'm trying to export a list of VMs and their SRM state according to this script from VMware below. However, how do I output the list/report to a csv or an excel file?
vSphere 6.0 Documentation Center
Generate a report of the protected virtual machines.
$protectionGroups | % {
$protectionGroup = $_
$protectionGroupInfo = $protectionGroup.GetInfo()
# The following command lists the virtual machines associated with a protection group
$protectedVms = $protectionGroup.ListProtectedVms()
# The result of the above call is an array of references to the virtual machines at the vSphere API
# To populate the data from the vSphere connection, call the UpdateViewData method on each virtual machine view object
$protectedVms | % { $_.Vm.UpdateViewData() }
# After the data is populated, use it to generate a report
$protectedVms | %{
$output = "" | select VmName, PgName
$output.VmName = $_.Vm.Name
$output.PgName = $protectionGroupInfo.Name
$output
}
} | Format-Table @{Label="VM Name"; Expression={$_.VmName} }, @{Label="Protection group name"; Expression={$_.PgName} }
Move-VM between datacenters on same vCenter
Hey all..
With a VM powered off, I'm trying to migrate a VM between datacenters within the same vCenter. There's no shared storage, different networks at the destination host. The GUI works (shows warning about missing network at destination), yet move-vm doesn't work between datacenters.
Trying: move-vm -vm test-20150309 -destination esx1 -datastore datastore1, I get the error:
move-vm : 3/9/2015 2:48:20 PM Move-VM Destination container must be in the same Datacenter.
At line:1 char:1
+ move-vm -vm test-20150309 -destination esx1. ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (esx1:VMHostImpl) [Move-VM], VimException
+ FullyQualifiedErrorId : Client20_VmHostServiceImpl_CheckMoveVmParameters_InvalidDatacenter,VMware.VimAutomation.
ViCore.Cmdlets.Commands.MoveVM
The manual states -Destination can be folder,host,cluster etc.. Since hosts AND folders are bound by datacenters, I'm guessing it needs to know the new host & new folder. I've tried to use -destination twice, and I've tried -destination host,folder.
Move-VM : Cannot bind parameter because parameter 'Destination' is specified more than once. To provide multiple values to parameters that can accept multiple values, use the array syntax. For example, "-parameter value1,value2,value3".
Move-VM : Missing an argument for parameter 'Destination'. Specify a parameter of type 'VMware.VimAutomation.ViCore.Types.V1.Inventory.VIContainer' and try again.
I'm using PowerCLI 5.8, and tried on vCenter 5.0 and 4.0.
move-vm : 3/9/2015 2:48:20 PM Move-VM Destination container must be in the same Datacenter.
At line:1 char:1
+ move-vm -vm test-20150309 -destination esx1. ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (esx1:VMHostImpl) [Move-VM], VimException
+ FullyQualifiedErrorId : Client20_VmHostServiceImpl_CheckMoveVmParameters_InvalidDatacenter,VMware.VimAutomation.
ViCore.Cmdlets.Commands.MoveVM
Add VM to inventory not working
Hello,
I am trying to use PowerCLI to add a VM to inventory. I know the exact location and I'm not having any issues seeing the file, I have verified the location using ls:
ls vmstores:\srmvc2.MYDOMAIN.ca@443\DR\NASG_SVM1_ESX_Templates\PICOB_NEW1\PICOB_NEW1.vmx
Datastore path: [NASG_SVM1_ESX_Templates] PICOB_NEW1
LastWriteTime Type Length Name
------------- ---- ------ ----
2016/04/18 11:35 AM VmConfigFile 3554 PICOB_NEW1.vmx
This result seems to indicate the path to the vmx file is correct, I attempt to add the file to inventory using the following command:
New-VM -VMHost srmesxi62.MYDOMAIN.ca -Location Migrating -VMFilePath "vmstores:\srmvc2.MYDOMAIN.ca@443\DR\NASG_SVM1_ESX_Templates\PICOB_NEW1\PICOB_NEW1.vmx"
This returns an invalid path error. This must be dead simple to fix, but I can't see where I'm going wrong. Any ideas?
Having trouble filtering Get-Task on StartTime
I have a script where I store the start time in a variable $SCRIPT_START, and then I want to call Get-VIEvent and Get-Task and filter on only events that were logged after the script started (ie Get-Task | ? {$_.StartTime -gt $SCRIPT_START}).
The filtering, when run from the script, works fine for Get-VIEvent, but not for Get-Task. But if I execute the same commands manually filtering on Get-Task works correctly. Not sure if this is a bug or I'm missing something. Here are the stripped down code blocks relevant to the issue, all you need to do is substitue in $SERVERS and $CLUS_NAME. To test, move $SERVERS off of $CLUS_NAME and execute to the script.
$SCRIPT_START = Get-Date
$SERVERS = 'SERVER_A', 'SERVER_B'
$SERVERS
Function Check-vMotion {
Param (
[Parameter(Mandatory=$TRUE)]$SERVERS,
[Parameter(Mandatory=$TRUE)]$SCRIPT_START
)
$vMotion_Count = 0
###$RECENT_TASKS = Get-Task | ? {$_.Name -eq 'RelocateVM_Task' -AND $_.StartTime -gt $SCRIPT_START}
$RECENT_TASKS = Get-Task | ? {$_.StartTime -gt $SCRIPT_START}
Write-Host "recent tasks"
$RECENT_TASKS
$VIEVENTS = Get-VIEvent | ? {$_.CreatedTime -gt $SCRIPT_START}
Write-host "vi events"
$VIEVENTS
ForEach ($SERVER in $SERVERS) {
$CHECK = $RECENT_TASKS | ? {$_.ObjectID -eq ((Get-VM $SERVER).Id)}
If ($CHECK.State -eq 'Success' -and $CHECK.PercentComplete -eq '100') {$vMotion_Count++}
}
$vMotion_Count
}
Start-Sleep -s 3
$VM_CLUS = Get-Cluster SOME_CLUSTER
Move-VM SERVER_A -Destination $VM_CLUS
Move-VM SERVER_B -Destination $VM_CLUS
$vMotion_Count = Check-vMotion $SERVERS $SCRIPT_START
$vMotion_Count
Now if I run this manually it works correctly:
PowerCLI C:\> $SCRIPT_START = (Get-Date).AddMinutes(-5)
PowerCLI C:\> $RECENT_TASKS = Get-Task | ? {$_.StartTime -gt $SCRIPT_START}
PowerCLI C:\> $recent_tasks.count
6
Within the script the value is empty.
storing credentials for Alans vCheck script
I hope this is a stupid question - this is quite new stuff for me
Recently I started to use Alans vCheck powershell script.
It works great as long as I can connect to the vCenter with an account like "administrator"
Then storing the credentials in the file specified via
$CredFile = ".\administrator.crd"
works great..
But when ever I run the script against a vCenter where I need to login via "domain\admin"
storing the credentials fails and I need to supply them via manual input each time I run the script.
Has anyone seen this and is there a workaround ?
Automate server deployment with PowerCLI
Hello,
I'm new to the VMWare world and PowerCLI. We are working on a project that requires the creation of a few dozen servers. We are currently cloning templates and manually configuring them, but there's obviously better ways to accomplish this. My first attempt was to use PowerCLI and the Invoke-VMScript. I have it configuring the NICs, setting the static IP, renaming the machine, activating windows, and joining it to the domain. I've found that the Invoke-VMScript works about 60-75% of the time. It will throw errors about waiting for VMWare tools, regardless of the VMWare tools state. I've dug as much as I can and cannot get any solid answers. The servers are 2012R2, so I'm wondering if it's a compatibility issue since it seems that only up through 2008 is supported.
I found another avenue to try, the OSCustomizationSpec, but I'd had even less luck with that. Can anyone shed some light on what should be a fairly simple task?
Matt
virtual machine vsphere ha protection status using power cli?
How to check the status of the virtual machine vsphere ha protection status using power cli?
Log into multiple vCenter Servers using PowerCLI
So, I am having some troubles setting up a connection to multiple servers at the same time.
Here is the current configuration pulled using Get-PowerCLIConfiguration
I have tried to connect using:
- Connect-VIServer Server1, Server2
- $hosts =@(
"Server1",
"Server2
);
$user="me"
$password="mypassword"
Connect-VIServer -Server $hosts -User $user -Password $password
After displaying the contents of the $defaultviservers array, it changes to the last server that it had connected to and never more than just the one.
Some thoughts on this would be appreciated.
Tag handling in PowerCLI with Platform Services handling the Inventory service
I have an environment with Inventory Service located behind Load Balancer and thus another URL etc. When trying to get-tag or newTagAssignment, I get only
New-TagAssignment Unable to connect to the Inventory Service at 'http://localhost:10080/invsvc' which is required for the tagging
The roles and permissions should be ok, so this seems the real problem. Is there a way to get the commandlets to connect the inventory service from another location than the Vcenter Connected with Connect-VIServer?
Or any other solutions? REST API is not usable for this scenario.
The only article or discussion I found so far is this:
VMware KB: Reviewing and managing tags and tag association in VMware vCenter Server 6.0
And it does not discuss my problem.
Thanks in advance if you have any ideas.
New-VM fail with vm exist error, read inside.
Hi,
i'm using a powershell script to deploy vms based on csv file (orig script here https://blog.smasterson.com/2014/05/21/deploying-multiple-vms-via-powercli-updated-v1-2/).
i'm using 3 different vcenter servers (selected by params in the csv).
2 are ok but the third recently start failing with vm exist.
the thing is that the vm doesn't exist until the new-vm command (i'm checking it right before the new-vm).
if (Get-VM -Name $vmName -Location $cluster -Server $vcserver |Select Name) {
Out-Log "Line 292: $vmName Exist, Moving to next one" "Red"
Continue
}
$taskTab[(New-VM -Name $VM.Name -Server $vcserver -VMHost $vmhost.Name -Location $VM.Folder -Datastore $datastore -Notes $notes -VM $VM.Template -OSCustomizationSpec $tempSpec -RunAsync).Id] = $tid
when the new-vm task starting i see that there is a line in the vc recent tasks of the clone, but 2 seconds later there is another attempt and fail with the vm exist error.
i can't find any thing that will explain this behavior, not in the script and not in the vc logs.
any thoughts/ideas?
thanks
mor