I am having trouble finding the Get-VIEvent equivalent in the vcenter and vcenter server API.
Am I missing something?
Or is it not there, YET?
I am having trouble finding the Get-VIEvent equivalent in the vcenter and vcenter server API.
Am I missing something?
Or is it not there, YET?
Hi All,
Earlier today when trying to do some basic work in PowerCLI on a vCenter 6.5 server, I started to see some strange results
PS C:\WINDOWS\system32> Get-VMHost $serverlist | Get-VM
Get-VM : 26/Jun/2018 13:26:31 Get-VM Exception has been thrown by the target of an invocation.
At line:1 char:26
+ Get-VMHost $serverlist | Get-VM
+ ~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-VM], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM
I thought "new version of VC, so maybe a new version of PowerCLI is needed"
PowerCLI v10 is available but, the only prerequisite, PowerShell Core 6 needs to be installed.
No big deal, right ?
Wrong !
PowerShell Core 6 no longer uses the ISE.
Microsoft are recommending the VS Code instead.
I've installed the VS Code App, PowerShell extensions and, installed PowerCLI using Install-Module -Name VMware.PowerCLI -Scope AllUsers
VS Code, doesn't appear to have tab completion, connect-viserv + TAB doesn't return Connect-VIserver for example.
Am I missing something here or, do I need to use something other than VS Code to replace the ISE when using PowerCLI 10 ?
Thanks
I know this is probably simple fix but I am coming to a blank.
What I need to do is check the ESXi version to make sure it is above 6.x before running code and running different code on 5.x hosts. My pseudo code is below.
If (host level = version 6.x)
{
run code set 1
}
else
{
run code set 2
}
Thanks in advance.
how do I use the guest credential in invoke-vmscript?
I have no problem using local admin password for guestuser and guiestpassword
but when I use a domainuser which is part of the local admin group. it fails with access denied
Hello Community,
quick to our environment:
- 2 x vCenter 6.5
- each vCenter with round about 60 DataCenters around the world
- templates synced between the vCenters with Content Library
Now, I need to have the actual templates synced/deployed from my main site in my vCenter to all other DataCenters so that every site is using the same templates. After a maintenance where we patching our templates I need to sync again all templates with the newest one in our main site.
Community, how do you handle this?
- vSphere Replication
- PowerCli
- ovftool
- backup software
- ? ? ?
My idea is to write a script where I delete all the templates on all DCs and do a "Clone Template" to all sites - hugh traffic each maintenance weekend.
Would be cool if you can give me some input!
Thank you very much and greetings
KKvss
Hello everybody
We are having the issue that our backup software sometimes forgets to unlock VMs after it is done with its thing.
The software itself only allows the unlocking by browsing the backup selection and selecting each and every VM individually and hitting "unlock".
This not only hampers new backup attempt sometimes, it also blocks DRS vMotions and manual ones. While troubleshooting this on PS, I noticed that PS was aware that the VM was actually locked by the backup plugin.
So my hope is to find all VMs with such a lock and remove the lock via PS.
Does anybody have experience with this issue or can anyone be of assistance in finding a way to do this?
Thanks in advance for your time
Regards,
Marco
Hi People, im new in powercli!
Is possible in powercli, create a script where appears a menu with options to choose like a what vcenter to connect, choose cluster in this vCenter.... and with this data, execute a task
For example, to choose a vCenter, in this vCenter choose a cluster, in that cluster that shows me the DRS rules..
It's possible?
How can I do it?
Thanks in advanced
Regards
Hi All, Anyone have an updated version of this script? Appreciate the help!
$CIvms =$CIvApp |get-CIvm
$report =@()
foreach($vm in$CIvms){
$row =""| Select "Name","CIVApp","Org","Status","Operating System","CpuCount","Memory (GB)","Owner"
$row."Name"=$vm.Name
$row."CIvapp"=$CIVapp.Name
$row."Org"=$CIVapp.Org.Name
$row."Status"=$CIVapp.Status
$row."Operating System"=$vm.GuestOSFullName
$row."CpuCount"=$vm.CpuCount
$row."Memory (GB)"= ($vm |Measure-Object-Property MemoryMB -Sum).Sum/1024
$row."Owner"=$CIvapp.Owner.Name
$report +=$row
}
$report |export-csv C:\tmp\VcloudVMsNEW.csv
So I have installed a Azure Hybrid worker on my script server.
I can launch a script with Local System / Local Service or Network Service as a scheduled task or interactively.
But running it through Test Pane in fails on the Azure Runbook if fails with a rather non-informed error
New-VM : 6/27/2018 4:05:30 PM New-VM Could not find item C:\ProgramData.
At line:56 char:1
+ New-VM -Name $VMname -template $myTemplate -location $env -ResourcePo ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-VM], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM
Paired it down my script , to make it simple
Param (
[String]$VMNamesuffix = 'MyTestServerLocal',
[string]$Env = "Test01",
[String]$VCServiceAccount ="Domain\svc_UserAccount",
[String]$VCServicePassword = "SomePassword"
)
## Varaibles ##
$VMname = ($Env+"-"+$VMNameSuffix).ToUpper()
$sourcevc = "vcenter01.domain.test"
$TargetDataStore = "TFC_XIO_"+$env
$sourceDS = 'TFC_XIO_UTILITY'
$ResourcePool = 'GoldRP'
# List of modules to be loaded
$moduleList = @(
"VMware.VimAutomation.Core",
"VMware.VimAutomation.Vds",
"VMware.VimAutomation.Cloud",
"VMware.VimAutomation.PCloud",
"VMware.VimAutomation.Cis.Core",
"VMware.VimAutomation.Storage",
"VMware.VimAutomation.HorizonView",
"VMware.VimAutomation.HA",
"VMware.VimAutomation.vROps",
"VMware.VumAutomation",
"VMware.DeployAutomation",
"VMware.ImageBuilder",
"VMware.VimAutomation.License"
)
# Load modules
function LoadModules(){
$loaded = Get-Module -Name $moduleList -ErrorAction Ignore | % {$_.Name}
$registered = Get-Module -Name $moduleList -ListAvailable -ErrorAction Ignore | % {$_.Name}
$notLoaded = $registered | ? {$loaded -notcontains $_}
foreach ($module in $registered) {
if ($loaded -notcontains $module) {
Import-Module $module
}
}
}
#Run LoadModules function
LoadModules
$VCSecurePassword = Convertto-SecureString -String $VCServicePassword -AsPlainText -force
$VCCreds = New-object System.Management.Automation.PSCredential $VCServiceAccount ,$VCSecurePassword
Connect-VIServer -Server $sourcevc -Credential $VCCreds
$SourceDataStoreOB = Get-Datastore $SourceDataStore
$TargetDataStoreOB= Get-Datastore $TargetDataStore
$myTemplate = Get-Template -Name "WinTemplate" -Location Templates
New-VM -Name $VMname -template $myTemplate -location $env -ResourcePool $ResourcePool -Datastore $TargetDataStoreOB -Verbose
After an upgrade from powercli 6.3. to 6.5.1 some parts of my script to configure an ESXi host have been showing warnings that I haven't seen before.
The iscsi-binding of 2 vmk ports completely broke but I will ask about this in a different subject if I can't fix it that myself.
question: What do I need to change in the syntax to get rid of the warnings?
The first snippit:
Set-PowerCLIConfiguration-InvalidCertificateActionIgnore-DisplayDeprecationWarnings$false-Confirm:$false|out-null
Write-Host"add local user to readonly role"-foregroundcolorgreen
New-VIPermission-Principaltestuser-Role" readonly "-Propagate:$true-Entity$vmhostname|Out-Null
Write-Host"Done"
Write-Host""
The snippit still works but gives this warning:
WARNING: Parameter 'Principal' is obsolete. This parameter no longer accepts multiple values.
WARNING: Parameter 'Entity' is obsolete. This parameter no longer accepts multiple values
Another snippit:
Write-Host"Connect NFS Datastores"-foregroundcolorgreen
foreach ($datastorein (Get-cluster$cluster|Get-Datastore|where {$_.Type -eq"nfs"-and$_.Accessible -eq"true"})){
New-Datastore-vmhost$vmhostname-Nfs-Name$datastore.Name -Path$datastore.RemotePath -NfsHost$datastore.RemoteHost |Out-Null
}
Write-Host"Done"
Write-Host""
The snippit still works but gives this warning:
WARNING: Parameter 'VMHost' is obsolete. This parameter no longer accepts multiple values.
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 ImageBuilder PowerCLI Component 6.5 build 4561891
VMWare AutoDeploy PowerCLI Component 6.5 build 4561891
VMware Vds PowerCLI Component 6.5 build 4624695
VMware Cloud PowerCLI Component 6.5 build 4624821
VMware HA PowerCLI Component 6.0 build 4525225
VMware HorizonView PowerCLI Component 7.0.2 build 4596620
VMware Licensing PowerCLI Component 6.5 build 4624822
VMware PCloud PowerCLI Component 6.5 build 4624825
VMware Storage PowerCLI Component 6.5 build 4624820
VMware vROps PowerCLI Component 6.5 build 4624824
VMware vSphere Update Manager PowerCLI 6.5 build 4540462
Powercli config:
Powercli helptext:
NAME
New-Datastore
SYNOPSIS
This cmdlet creates a new datastore.
-------------- Example 1 --------------
C:\PS>New-Datastore -VMHost $vmhost -Name Datastore -Path $scsiLun.CanonicalName -Vmfs -FileSystemVersion 3
Creates a VMFS datastore by specifying the file system type.
-------------- Example 2 --------------
C:\PS>New-Datastore -Nfs -VMHost 10.23.112.60 -Name NFSDatastore -Path /mynfs -NfsHost 10.23.84.73
NAME
New-VIPermission
SYNOPSIS
This cmdlet creates new permissions on the specified inventory objects for the provided users and groups in the role.
-------------- Example 1 --------------
C:\PS>New-VIRole -Name Role -Server $server -Privilege (Get-VIPrivilege -PrivilegeGroup)
$permission = New-VIPermission -Role Role -Principal Administrator -Entity (Get-Datacenter)
Creates a permission on the provided server for a role with the specified privileges.
Hey there,
after i install our ESXi hosts and put them into the vcenter i use a powershell script which will do the rest of configuration needed...
One of the points is to create a local readonly esxi User with a password. I dont like to have passwords in my scripts and in this case the script will only run with user interaction.
So in the first case i try to use a simple
$pwd = read-host "Enter a password:"
the problem here is here you can read the password which is provided...
I read little bit and try..
$pwd = read-host "Enter a password:" -asSecureString
This looks nice in the first step but to avoid password missmatches i fetch the password twice and compare both. In this case $pwd1 & $pwd2 are securestrings and do not match.
Now i try something like...
---Snip----
$check = "0"
while ($check -eq "0") {
$encpasswort1 = Read-Host "Please Enter pwd: " -AsSecureString
$encpasswort2 = Read-Host "again" -AsSecureString
$password1 = [System.Runtime.InteropServices.marshal]::PtrToStringAuto([System.Runtime.InteropServices.marshal]::SecureStringToBSTR($encpassword1))
$password2 = [System.Runtime.InteropServices.marshal]::PtrToStringAuto([System.Runtime.InteropServices.marshal]::SecureStringToBSTR($encpassword2))
if ($passwort1 -eq $passwort2) {
write-host -ForegroundColor Green "Lege Nutzer auf " $esx_Host.Name "an `n"
$status = Connect-VIServer $esx_Host.Name -User root -wa 0
$status = New-VMHostAccount -Id $user -Password $passwort1 -Description $desc -UserAccount
$status = New-VIPermission -Principal $user -Role $role -Entity (Get-Datacenter)
$status = Disconnect-VIServer $esx_Host.Name -Confirm:$false
$check = "1"
}
}
---snip----
This works so far but maybe there is a better way...
Maybe to compare to Securestring objects or pass them to an esxi host...
Some ideas would be welcome.
Thanks
HI,
i try to create a local readonly esxi user. In the past i had script like this..
New-VMHostAccount -Id $user -Password $pwd -Description $desc -UserAccount
New-VIPermission -Entity $ent -Principal $user -Role $role
where -Entiity of the New-VIPermission cmdlet was "ha-folder-root". if found this solution here in the community but i was not sure why it is this entity.
Now with my 6.5 host it comes to an error that the entity could not be found and a litle bit research brought me to this..
New-VIPermission -Entity (get-datacenter) -Principal $user -Role $role
Since Entity is descript as viobjekt this works well in the first step... but it the end its looks not that good..
New-VIPermission -Entity (get-datacenter) -Principal username -Role ReadOnly
Role Principal Propagate IsGroup
---- --------- --------- -------
ReadOnly username True False
Get-VIPermission|select Role, Principal, Entity
Role Principal Entity
---- --------- ------
ReadOnly username ha-datacenter
ReadOnly username host
Admin vpxuser root
Admin dcui root
Admin root root
ReadOnly username vm
It looks like that this is not the best option. So maybe somebody can point me to some information regarding this entity thing or can exlpain it to me?
And at the end ... is there an easy way to mark code as code so that it will be colored in this forum?
Greetings...
Good afternoon all, I am trying to automate the changing of an alarm trigger with VCenter 5. Currently when users use 75% or more of the storage on the local HD I get an alarm for "Datastore Disk Usage". I want to change the Warning from 75% to 85% and the Alert from 85% to 90%. I have been using VSphere PowerCLI for many tasks from adding and configuring hosts and their storage, networks, dns, etc... So I understand the basics. I just can't seem to figure out how to do anything other then get the name of the alarm. Any help would be appreciated.
I read some doc about how to run my PowerCLI script to get my reports.
I understood It's necessary to initialize PowerShell environment to load required components and if you want to load all these ones, you have to run the script Initialize-PowerCLIEnvironment.ps1. It's right?
If I open the link, which VMware Power CLI created during installation, it shows:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noe -c ". \"C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1
How Can I run my script (test.ps) by the previous line loading all components?
What do you suggest me please?
Hello guys,
can anyone help me with script a clean tmp files via PowerCLI.
My host disconnected from VCenter, and i can't connect for SSH.
Hi,
I was looking at a post from a few months back Scheduled maintenance mode script with email status report
I tweaked it a bit to powerdown VM's before placing the host into Maintenance Mode
(couldn't vMotion them as the Hosts in this case are not part of a cluster)
Here's what I've come up with.
This works except the body of the email received is
"*
26"
I was expecting "ServerName OK", this is the content of the $report variable
$hostlist=Get-VMHost ($serverlist)
$sMaint=@{
enable=$true
timeout=60
}
$report=@()
# If Host is in a Cluster, vMotion VM's to other Hosts in the Cluster
<# work in progress #>
# If Host is standalone, powerdown any running VM's
Foreach ($vmhostin$hostlist)
{
foreach ($vmin$vmhost)
{
$v=$vm|Get-VM
if ($v.PowerState-match'PoweredOn' )
{
Shutdown-VMGuest $v-Confirm:$false-ErrorAction SilentlyContinue
}
}
}
# Put Host into Maintenance Mode
Foreach ($serverin$serverlist)
{
$esxcli=Get-EsxCli-VMHost $server-V2
if($esxcli.system.maintenanceMode.set.Invoke($sMaint))
{
$report+="$($server) OK"
}
else
{
$report+="$($server) NOK"
}
}
# Email a report
$sMail=@{
From='Jason.Pierce2@emc.com'
Subject='Scheduled Maintenance Mode'
Body=$report|ConvertTo-Html|Out-String
BodyAsHtml=$true
SmtpServer='mailhub.lss.emc.com'
}
Send-MailMessage@sMail
How do I correct the email body content ?
Hey there,
what i try and what i do..
I have a script which will configure some Settings of my ESXi Hosts from the vCenter view and also will create local ESXi User... for this task i connect to the ESXi Host directly..
Soo..what i do ..
----
1. Connect to my vcenter...
2. Start my script...
3. All Setting will be aplied to the first esxi host in the list...
4. Connect to esxi
Connect-VIServer $esx_Host.Name -User $rootpwd.User -Password $rootpwd.Password -wa 0
create a user...
Disconnect-VIServer -Server $esx_Host.Name -Confirm:$false
5. The loop starts again.. and..
Get-VMHost : 29.06.2018 15:30:31 Get-VMHost You are not currently connected to any servers. Please connect first using a Connect cmdlet.
----
I try this on the cli ...
Connect-VIServer <vcenter> (OK)
Connect-VIServer <esxi host> (OK>
Disconnect-VIServer -Server <esxi Host> (Ok)
Get-VMHost
Get-VMHost : 29.06.2018 15:30:31 Get-VMHost You are not currently connected to any servers. Please connect first using a Connect cmdlet.
In Zeile:1 Zeichen:1
+ Get-VMHost
+ ~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (:) [Get-VMHost], ViServerConnectionException
+ FullyQualifiedErrorId : Core_BaseCmdlet_NotConnectedError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVMHost
Get-VMHost -Server <vcenter> (works)
Name ConnectionState PowerState NumCpu CpuUsageMhz CpuTotalMhz MemoryUsageGB MemoryTotalGB Version
---- --------------- ---------- ------ ----------- ----------- ------------- ------------- -------
So the connection to the vcenter is still there.. is it possible to recover this connection as default connection?
Greetz
Any prompt answer will be appreciated!!VMware PowerCLI
I can view performance metrics in vsphere web access and pull vm information using get-view but when I try to use get-stat I receive the following error.
Get-Stat Permission to perform this operation was denied. Required privilege 'System.Read' on managed object with id 'Folder-group-d1'.
I am not an admin in this VMSphere environment but I have been told by the admins I do have access. Is anyone able to tell me what permissions/roles could be missing so that I can take them back to the admins and have them test this. I only have access to a set of folders and vm clients. So I will not be able to be set as an admin. This is a corporate environment so that is not possible.