Quantcast
Channel: VMware Communities : Discussion List - VMware PowerCLI
Viewing all 14549 articles
Browse latest View live

VM's list running on the specific Hosts in a cluster

$
0
0

Hi All,

 

Can we pull the list of VM's running on specific host e.g. C:\temp\hostname.txt.  from power cli script ?

 

Want to include cluster name also and power state of VM's

 

thanks

vmk


Script for Audit - VMware tools,VM version, VMFS and ESXi host version etc..

$
0
0

Hello All,

 

 

I'm looking for a script which will help me do interim audit while upgrading the

 

 

1)VM tool version status

2)VM Hardware version

3)VMFS version upgrade. ( E.g. 5.60, 5.81,6.81 etc

4)ESXi Firmware Upgrade (HPE HW - I have the script)

5)ESXi host version 5.5 & 6.5

 

 

Note :- 1)We need to extract report only for the Microsoft OS 2008,2008R2,2012,2012R2 & 2016 only.

        ii) EXclude powered off VM's

      

 

 

 

 

thanks

vmk

cwvx- and cwvxp

PowerCLi refresh network information

$
0
0

Hello,

 

I need to add a new Host to a Cluster using PowerCLi. I can configure the host settings using PowerCLi but when I try to add the Host to my DVSwitches I get an error message

 

"Add-VDSwitchVMHost       The object or item referred to could not be found"

 

I have run the script and put in a pause and then I go to vCenter and manually refresh the Host and then the script progresses with out issue.

 

I have seen the message - "Refresh network information"

 

Using PowerCLi how can I refresh the network information so the Host connects to the DVSwitches?

 

Regards,

Script for DV Switch Backup of Multiple vCenter Servers

$
0
0

I am looking to schedule a backup of all dvswitch from multiple vcenter servers. I am using below script, what else can be added here to to mitigate below points?

 

1) All vcenter should run from single schedule job

1) Output should have contained vCenter name in starting_portgroup name

2) Schedule the task for daily run at particular time

3) Send an email confirmation after completion

 

LucD - Your help required.

 

___________

 

$vcenter = “vc1", "vc2", "vc3"

$vcenteruser = “domain\user“

$vcenterpw = “password“

#

$date=get-date -uformat %Y-%m-%d

#

# End of script parameter section

#—————————————— #

#

# Connect to vCenter Server

connect-viserver $vcenter -User $vcenteruser -Password $vcenterpw

#

# Get the vNetwork Distributed switches

$switches=get-vdswitch

#

# Perform the backups

foreach ($switch in $switches)

{

#

# Backup each vNetwork Distributed Switch not including the port groups

export-vdswitch $switch -Withoutportgroups -Description "Backup of $switch without port groups" -Destination "c:\vSphere\$switch.without_portgroups.$date.zip"

#

# Backup each vNetwork Distributed Switch including the port groups

export-vdswitch $switch -Description "Backup of $switch with port groups" -Destination "c:\output\$switch.with_portgroups.$date.zip"

#

# Backup each port group individually

get-vdswitch $switch | Get-VDPortgroup | foreach { export-vdportgroup -vdportgroup $_ -Description "Backup of port group $($_.name)" -destination "c:\vSphere\$($_.name).portgroup.$date.zip"

}

}

Permissions set via script

$
0
0

Hi, I am trying to set permissions to a list of vCenter objects ( Folders and Datacenters ).

We have pre-created the roles required centrally at vCenter level.

Now I have a mix of permissions to be applied, which contains both domain accounts and vSphere local accounts.

 

My question is - could we use New-VI Permission to set permissions for both domain and lvSphere local accounts.

 

# Variables $Role $Principal $viobject $Propagate  values are read from csv

# Loop

# To set folder permissions

  $folder_viobject = Get-Folder -Name $foldername ( Similarly I get the datacenter vi-object for datacenter permissions )

  New-VIPermission -Role $Role -Principal $Principal -Entity $folder_viobject -Propagate $Propagate

 

Please let me know whether this would work or if need to do something for domain accounts specially.

Exception has been thrown by the target of an invocation Windows Server 2016

$
0
0

Hello folks , I am stuck 

 

I am running a simple command 

 

Import-Module "VMware.VimAutomation.Core"

Connect-VIServer something.something.vcenter1

 

$vms = Import-CSV D:\Scripts\~\adhoc.csv

 

foreach ($vm in $vms){

 

$vmn = $vm.vmname

Invoke-VMScript -vm $vmn -ScriptText "ping something.something" -GuestUser $GuestCred -GuestPassword $GuestPass -ScriptType Bat

 

}

 

I am getting the follow error:

 

Invoke-VMScript : 3/5/2019 7:45:31 PM    Invoke-VMScript        Exception has been thrown by the target of an invocation.   

At D:\Scripts\~\dr_adhoc.ps1:90 char:9

+ Invoke-VMScript -vm $vmn -ScriptText "ping something.something" -GuestU ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [Invoke-VMScript], VimException

    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.InvokeVmScript

 

If I run the same command on a non windows 2016 it works without any problem I am curios if it is something else

Open-VMConsoleWindow Authorize Exception

$
0
0

Just noticed that Open-VMConsoleWindow no longer works ? Or did something change that I'm not aware of ? I can run VMRC from vSphere Web Client; also from PowerShell using this approach.

 

PS C:\PowerCLI\_> get-vm xxxx | Open-VMConsoleWindow

Open-VMConsoleWindow : A general system error occurred: Authorize Exception

In Zeile:1 Zeichen:23

+ get-vm xxxx | Open-VMConsoleWindow

+               ~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [Open-VMConsoleWindow], VimException

    + FullyQualifiedErrorId : VMware.Vim.VimException,VMware.VimAutomation.ViCore.Cmdlets.Commands.OpenVMConsoleWindow

 

Some info:

Windows 10 1803

 

PS C:\PowerCLI\_> $PSVersionTable.PSVersion

 

Major  Minor  Build  Revision

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

5      1      17134  228

 

PS C:\PowerCLI\_> Get-PowerCLIModules

 

Name                                Version

----                                -------

VMware.DeployAutomation             6.7.0.8250345

VMware.ImageBuilder                 6.7.0.8250345

VMware.PowerCLI                     11.0.0.10380590

VMware.Vim                          6.7.0.10334489

VMware.VimAutomation.Cis.Core       11.0.0.10335701

VMware.VimAutomation.Cloud          11.0.0.10379994

VMware.VimAutomation.Common         11.0.0.10334497

VMware.VimAutomation.Core           11.0.0.10336080

VMware.VimAutomation.HA             6.5.4.7567193

VMware.VimAutomation.HorizonView    7.6.0.10230451

VMware.VimAutomation.License        10.0.0.7893904

VMware.VimAutomation.Nsxt           11.0.0.10364044

VMware.VimAutomation.PCloud         10.0.0.7893924

VMware.VimAutomation.Sdk            11.0.0.10334495

VMware.VimAutomation.Security       11.0.0.10380515

VMware.VimAutomation.Srm            10.0.0.7893900

VMware.VimAutomation.Storage        11.0.0.10380343

VMware.VimAutomation.StorageUtility 1.3.0.0

VMware.VimAutomation.Vds            11.0.0.10336077

VMware.VimAutomation.Vmc            11.0.0.10336076

VMware.VimAutomation.vROps          10.0.0.7893921

VMware.VumAutomation                6.5.1.7862888

Adding existing disks to a VM via PowerCLi

$
0
0

Hi there,

 

I'm working on a process to add existing vmdk hard-drive files to a VM (doing a migration from HyperV to vSphere using commvault).

 

I've discovered that when the VM is migrated, the hard-disks are pointing to snapshot files, which requires having to remove the disk references (easy done via powercli).

 

The trouble is that I need to re-add the existing disks to the VM (in order to be correctly mapped). I've been trying to add the disks using powercli, but it's having none of it.

 

I'm using the following command example..

$x = get-vm -Name my_vmname

New-HardDisk -DiskPath "[datastore]/my_vmname/my_vmname.vmdk" -VM $x

 

when I do this, I get :

New-HardDisk : 06/03/2019 10:57:13 New-HardDisk No matching datastore found.

At line:1 char:1

+ New-HardDisk -DiskPath "[datastore]/my_vmname/myvmname.vmdk"  ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : ObjectNotFound: (:) [New-HardDisk], VimException

    + FullyQualifiedErrorId : Client20_VirtualDeviceServiceImpl_NewVirtualHardDisk_DatastoreNotFound,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevice.NewHardDisk

 

 

(I'm using PowerCli 6.5 Release1 build 4624819)

 

I can map this via the web-console without issue, but it's seriously slow in comparison to the command line.. especially with a large number of folders in the LUN (especially when they're not in any alphabetical order!)

 

Would really welcome any suggestions on how to do this.. to save my sanity

 

Alternatively is there a way to change the file path of a harddisk.. so that I could drop the '-000001' from the filename, thus saving the need to remove disks, then re-add.

Anyone done this before ??

 

Thanks in advance


script_structure_powercli

$
0
0

Hi Luc,

 

can you please suggest on the orange part of the following code.  This is to add static routes on each esxi host and do some operations on replication appliances .

since there are no commands for replication nor any api so iam trying to automate whaterver possible with existing commnds.

 

 

i have two questions related to orange lines.

 

 

1 .stop-vm -vm $replication_appliance -whatif

will stop-vm is a kind of graceful shutdown for vm.

2:Start-Process https://172.16.7.20:5480 -Credential $cred_vami

can we ensure if start-proces to access vami opens in mozila and assign credential as mentioned above.

 

 

code is below:

 

 

 

$vcenter=read-host "provide vcenter name"

$cred=get-credential

$cred_vami=Get-Credential

connect-viserver $vcenter -credential $cred|out-null

$con=$global:defaultviserver

if($con.name -eq '172.1.1.1')

{

write-host "we are working in prod vcentercer remeber to enable vspherereplication traffic on vmk2 on esach esxi" -ForegroundColor DarkMagenta

 

$vmhosts=get-vmhost

foreach($vmhost in $vmhosts)

{

 

new-vmhostroute -vmhost $vmhost -destination 172.16.9.0 -prefixlength 25 -gateway 172.16.9.1 -whatif

 

 

 

}

 

$replication_appliance = get-vm vra_pro

stop-vm -vm $replication_appliance -whatif

$portgroup_replication=get-vdportgroup -name replication_113

new-networkadapter -vm $replication_appliance -portgroup $portgroup_replication -whatif

start-vm -vm $replication_appliance -whatif

write-host "now we are going to configure vra prod appilance" -ForegroundColor Blue

 

Start-Process https://172.16.7.20:5480 -Credential $cred_vami

}

else

{

write-host "we are working in dr vcenter rember to configure replication nfc traffic on each esxi on vmk2" -ForegroundColor Green

 

$vmhosts=get-vmhost

foreach($vmhost in $vmhosts)

{

 

new-vmhostroute -vmhost $vmhost -destination 172.16.9.128-prefixlength 25 -gateway 172.16.9.129 -whatif

 

 

 

}

 

$replication_appliance = get-vm vra_dr

stop-vm -vm $replication_appliance -whatif

$portgroup_replication=get-vdportgroup -name replication_113

new-networkadapter -vm $replication_appliance -portgroup $portgroup_replication -whatif

start-vm -vm $replication_appliance -whatif

  write-host "now we are going to configure vra_dr appilance" -ForegroundColor Blue

 

Start-Process https://172.16.7.150:5480 -Credential $cred_vami

 

 

 

 

 

}

Deleting snapshots with wait

$
0
0

I have a script that deletes snapshots throughout several vCenter environments. The number of snapshots has grown to ~500 every week due to the size of the overall environment. I am beginning by gathering a list of any snapshots older than x days, excluding some that have special wording in the description. This gives me a csv that has the VM name, the vCenter, the snapshot name, creation date, description, server owner (VM tag), and SizeMB. I then sort by date so in the case of a VM with multiple snapshots (rare) I am deleting newest first, and then doing something like this:

 

Get-VM -Name $VM.Name |    Get-Snapshot -Name $VM.Snap |        Remove-Snapshot -Confirm: $false

 

The script works, but I find that there is no method for waiting until one is done before moving on to the next. So what happens, if I have 500 servers that have snapshots, is they all attempt to kick off one after another. I could do a simple sleep, but with the differing size of snapshots that is a crap shoot. I have also tried something like this:

 

$t = Get-VM -Name $VM.Name | Get-Snapshot -Name $VM.Snap | Remove-Snapshot -Confirm: $false


While('Running','Queued' -contains $t.State) {
    Start-Sleep 5    $t = Get-Task -Id $t.Id
}

 

But it doesn't seem to work, it still runs them one after another. The net result is I usually have to make a second pass to clean up any snapshots I missed. I am just curious if there is a better way.

Get-InventoryPlus - include datastores friendly name

PowerCLI Download Location

$
0
0

I'm trying to upgrade my powercli to the latest version and cannot find a download. Is it located somewhere else now or named differently.

I am looking under Automation Tools and SDKs.

Add server to domain via Invoke-VMScript

$
0
0

Hi,

 

I'm trying to join a new server build to the domain via Invoke-VMScript. I'm hoping to script the whole server build process, or a good majority of it, to save on mouse clicks.

 

The script starts off by connecting to our vCenter server, so it can then reach the remote server and run the script below. Everything works, except for the add-computer line. When it gets to that piece it just hangs. Even without the sleep 10 line.

 

If i modify this, remove the invoke-vmscript command and I run the Add-Computer command on the VM locally, it joins the domain and reboots just fine. Any idea what I'm doing wrong, and how i can have the server join the domain and reboot via Invoke-VMScript?

 

My test server for this script is a brand new build and VMTools are up to date.

 

$scriptCode="

    ## Configure the IP address and gateway ##

    New-NetIpAddress -InterfaceAlias Ethernet0 -IPAddress $ip -PrefixLength 24 -DefaultGateway $gway

   

    ## Configure the DNS Server IP address ##

    Set-DnsClientServerAddress -InterfaceAlias Ethernet0 -ServerAddresses $dns

   

    ## wait for 10 seconds ##

    sleep 10

   

    ## add the server to the domain and reboot ##

    Add-Computer –domainname $domain -restart -credential $cred2

"

 

#use the invoke-vmscript command to send all of the code in the $scriptCode variable above to the remote server

Invoke-VMScript-VM$vm-ScriptText$scriptCode-GuestCredential$cred

powercli error due to hardware version 13

$
0
0

We have been using these commands which have been working for a long time.  We recently upgraded few Windows server's hardware version to 13.  Due to that, following three commands no longer works for any VMs which are at hardware version 13(It works fine for all other VMs which are at hardware version 11, 9, 8, 7)

 

1.

Import-CSV $ImportName | ForEach-object {Set-NetworkAdapter -NetworkAdapter ( Get-NetworkAdapter $_.Name ) -NetworkName $VLAN -StartConnected $Connectivity -confirm:$false}

 

Here is the Error:

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

    Get-NetworkAdapter : 3/4/2019 11:08:25 AM    Get-NetworkAdapter        Exception has been thrown by the target of an invocation.   

 

+ Import-CSV $ImportName | ForEach-object {Set-NetworkAdapter -NetworkAdapter ( Ge ...

+                                                                               ~~

    + CategoryInfo          : NotSpecified: (:) [Get-NetworkAdapter], VimException

    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevice.GetNe

   tworkAdapter

 

2.

$Servers  | ForEach-object { Get-VM (Get-VM -Name $_.Name) | Get-VMQuestion | Set-VMQuestion -Option $Option -Confirm:$false}

 

Here is the Error:

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

Set-VMQuestion : 3/4/2019 11:11:30 AM    Set-VMQuestion        Exception has been thrown by the target of an invocation.   

 

+ $Servers  | ForEach-object { Get-VM (Get-VM -Name $_.Name) | Get-VMQuestion | Se ...

+                                                                               ~~

    + CategoryInfo          : NotSpecified: (:) [Set-VMQuestion], VimException

    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.SetVMQuestion

 

 

3.

Import-CSV $ImportName | ForEach-object { Remove-VM $_.Name -Confirm:$false }

Here is the Error:

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

Remove-VM : 3/4/2019 11:45:59 AM    Remove-VM        Exception has been thrown by the target of an invocation.   

 

+ Import-CSV $ImportName | ForEach-object { Remove-VM $_.Name -Confirm:$false }

+                                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [Remove-VM], VimException

    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.RemoveVM

 

 

 

Any suggestions / thoughts will be appreciated. thank you in advance.

 

Thank you!!!!!

Script to delete vms that are x days old on a test server

$
0
0

Hi

 

I am new to PowerCLI and are trying to create a script to delete VMs older than a day (to cleanup on a testserver).

 

My plan was to find some code that did something similar and see if I could redo it to fit my purpose.

 

I have been trying to merge these 2 scripts and have been failing for a couple of days:

 

Create a list of candidates for deletion: Get Snapshots older than X Days – PowerCLI | VMMaster

Delete the VMs: Script for reporting and removing VMs older than 2 weeks.

 

Connect-viserver -Server viserver

 

function Get-VMCreationTimes {

   $vms = get-vm -Datastore datastore-9

   $vmevts = @()

   $vmevt = new-object PSObject

   foreach ($vm in $vms) {

 

#

#Progress bar:

#

      $foundString = "Found: "+$vmevt.name+"   "+$vmevt.createdTime

      $searchString = "Searching: "+$vm.name

      $percentComplete = $vmevts.count / $vms.count * 100

      write-progress -activity $foundString -status $searchString -percentcomplete $percentComplete

 

      $evt = get-vievent $vm | sort createdTime | select -first 1

      $vmevt = new-object PSObject

      $vmevt | add-member -type NoteProperty -Name createdTime -Value $evt.createdTime

      $vmevt | add-member -type NoteProperty -Name name -Value $vm.name

        

      $vmevts += $vmevt   

   }

   $vmevts | sort createdTime

}

 

$deletioncandidates = Get-VMCreationTimes | Where {$evt.CreatedTime -lt (Get-Date).AddDays(-1)} | Select-Object Name

Stop-VM -VM $deletioncandidates -Confirm:$false -whatif

 

But this gives me this message:

 

Stop-VM : Cannot bind parameter 'VM'. Cannot convert the "" value of type "System.Management.Automation.PSCustomObject" to type "VMware.VimAutomation.ViCore.Types.V1.Inventory.VirtualMachine".

At line:29 char:13

+ Stop-VM -VM $deletioncandidates -Confirm:$false -whatif

+             ~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidArgument: (:) [Stop-VM], ParameterBindingException

    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,VMware.VimAutomation.ViCore.Cmdlets.Commands.StopVM

 

start-sleep 30

 

$vms = @{}

Get-VM | where {$_.PowerState -eq "PoweredOff"} | % {$vms.Add($_.Name, $_)}

Get-VIEvent -Start (Get-Date).AddDays(-1) -Entity $vms.Values -MaxSamples ([int]::MaxValue) | where {$_ -is [VMware.Vim.VmPoweredOffEvent]} |

  Sort-Object -Property CreatedTime -Unique | % {

  $vms.Remove($_.VM.Name)

}

 

Remove-VM -VM $vms.Values -DeletePermanently -Confirm:$false -WhatIf

 

But this gives me this message

 

Exception calling "Add" with "2" argument(s): "Item has already been added. Key in dictionary: 'Windows2012'  Key being added: 'Windows2012'"

At line:3 char:54

+ Get-VM | where {$_.PowerState -eq "PoweredOff"} | % {$vms.Add($_.Name, $_)}

+                                                      ~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

    + FullyQualifiedErrorId : ArgumentException

 

Can anybody figure out what i am doing wrong?

(or point me in the direction of a script that works)


Get-VMhost and the related datastores to it

$
0
0

Hello, I need to list all of my hosts, and the related datastores to each, and also count these datastores per host, but the last part is optional I may do it manually for the sake of making the script simpler now.

Powercli to set NTP service startup policy

$
0
0

 

I have script to set ntp servers on my esxi hosts:

 

Get-VMHost | Add-VMHostNtpServer -NtpServer ntpserver1
#This set of commands is aprt of our standard build process.

#Configure NTP server
Add-VmHostNtpServer -NtpServer ntpservers1 -VMHost $VMHosts

#Allow NTP queries outbound through the firewall
Get-VMHostFirewallException -VMHost $VMHosts | where {$_.Name -eq "NTP client"} | Set-VMHostFirewallException -Enabled:$true

#Start NTP client service and set to automatic
Get-VmHostService -VMHost $VMHosts | Where-Object {$_.key -eq "ntpd"} | Start-VMHostService
Get-VmHostService -VMHost $VMHosts | Where-Object {$_.key -eq "ntpd"} | Set-VMHostService -policy "automatic"

 

But how do I use powercli to set the startup policy to start with host ?

ESXCLI v2 Commands in PowerCLI - Get-EsxCli -V2

$
0
0

I am trying to run the following  Get-EsxCli script:

 

$EsxHosts = Get-VMHost
foreach($EsxHost in $EsxHosts){
  $esxcli = Get-VMHost $EsxHost | Get-EsxCli -V2
  $esxcli.software.acceptance.set("VMwareAccepted")
  }

Name                           Port  User                         
----                           ----  ----                         
192.168.217.6                  443   root                         
Method invocation failed because [VMware.VimAutomation.ViCore.Impl.V1.EsxCli.EsxCliElementImpl] does not contain a method named 'Set'.
At line:5 char:3
+   $esxcli.software.acceptance.set("VMwareAccepted")
+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Set:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound

 

If I don't use the -V2 parameter it works fine, but I thought newer versions of powercli should use -V2 parameter?
My build is;

   VMware PowerCLI 11.2.0 build 12483598
---------------
Component Versions
---------------
   VMware Cis Core PowerCLI Component PowerCLI Component 11.2 build 12483642
   VMware VimAutomation VICore Commands PowerCLI Component PowerCLI Component 11.2 build 12483638
   VMware VimAutomation Vds Commands PowerCLI Component PowerCLI Component 11.2 build 12483615

PowerCLI to list all Powered Off VMs and Date of Event

$
0
0

I am trying to get this script to work but it doesn't even seem close at this point.  I am looking to run a report on Powered Off VMs and information about them.  I need to be able to clean the environment and have to wait 60 days before I permanently delete anything.  Any help would be great.

 

Connect-VIServer -Server XXX-vcenter1 -User administrator@vsphere.local -Password XXXXXXXXXXXX

Connect-VIServer -Server XXX-vcenter1 -User administrator@vsphere.local -Password XXXXXXXXXXXX

 

$Report = @()

$VMs = get-vm |Where-object {$_.powerstate -eq "poweredoff"}

$Datastores = Get-Datastore | select Name, Id

$VMHosts = Get-VMHost | select Name, Parent

 

foreach ($vm in Get-VM){

$view = Get-View $VMs

Get-VIEvent -Entity $VMs -MaxSamples ([int]::MaxValue) |

where {$_ -is [VMware.Vim.VmPoweredOffEvent]}

Group-Object -Property {$_.Vm.Name} | %{

  $lastPO = $_.Group | Sort-Object -Property CreatedTime -Descending | Select -First 1

  $row = '' | select VMName,Powerstate,OS,Host,Cluster,Datastore,NumCPU,MemMb,DiskGb,PowerOFF

    $row.VMName = $VMs.Name

    $row.Powerstate = $VMs.Powerstate

    $row.OS = $VMs.Guest.OSFullName

    $row.Host = $VMs.host.name

    $row.Cluster = $VMs.host.Parent.Name

    $row.Datastore = ($Datastores | where {$_.ID -match (($vmview.Datastore | Select -First 1) | Select Value).Value} | Select Name).Name

    $row.NumCPU = $VMs.NumCPU

    $row.MemMb = (($VMs.MemoryMB),2)

    $row.DiskGb = ((($VMs.HardDisks | Measure-Object -Property CapacityKB -Sum).Sum * 1KB / 1GB),2)

    $row.PowerOFF = $lastPO.CreatedTime

  $report += $row

}}

$report | Sort Name | Export-Csv -Path "C:\XXXXX\Powered_Off_VMs.csv"

disconnect-viserver * -confirm:$false

 

I don't get an export to CSV and a display on screen of the following:

 

Template             : False

Key                  : 165369

ChainId              : 165369

CreatedTime          : 6/28/2016 10:19:35 AM

UserName             :

Datacenter           : VMware.Vim.DatacenterEventArgument

ComputeResource      : VMware.Vim.ComputeResourceEventArgument

Host                 : VMware.Vim.HostEventArgument

Vm                   : VMware.Vim.VmEventArgument

Ds                   :

Net                  :

Dvs                  :

FullFormattedMessage : ServerName on  XXX-prodesxi-10.xxxxx.com in ClusterName is powered off

ChangeTag            :

error connecting with powercli 11.2

$
0
0

I've been receiving some complaints from non-admin users that they cannot connect to vcenter once they update to the newest powercli 11.2 modules.

 

Anyone running 11.0 or lower seems fine but those that have upgraded are receiving this error:

 

Connect-VIServer : 2019-03-06 15:57:13 Connect-VIServer Permission to perform this operation was denied. Required privilege 'System.Read' on managed object with id 'OptionManager-VpxSettings'.
At line:1 char:1
+ Connect-VIServer -Server $ServerName
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    + CategoryInfo          : SecurityError: (:) [Connect-VIServer], NoPermission    + FullyQualifiedErrorId : ViCore_ConnectivityServiceImpl_GetSetting_NoPermission,VMware.VimAutomation.ViCore.Cmdlets.Commands.ConnectVIServer

 

 

As an admin I don't seem to have any issue.

 

They are able to connect to without issue via the GUI (VCSA 6.7U1)

 

Trying to install a specific version doesn;t' work (always seems to install 11.2 from the powershell gallery) or even use the save script provided on a vmware blog gives me errors when i try to run it.

 

ANyone else seeing this issue or know how to download older powercli versions?

Viewing all 14549 articles
Browse latest View live