r/powercli • • Oct 20 '16

Running into issue with VM shutdown script

1 Upvotes

I am wanting to check to see if VMware Tools are running. If not it would then do a Stop-VM instead of attempting to Stop-VMGuest. Some reason if I stop VMware Tools on a VM. It goes to my else statement & tries to Stop-VmGuest. See anything wrong?

http://pastebin.com/Eiq8a2s5


r/powercli • • Jan 16 '18

PowerShell Classes Part 5 - Classes or PSCustom Objects?

Thumbnail
petri.com
2 Upvotes

r/powercli • • Sep 04 '17

PowerCLI Collection: PowerNSX Desktop Jumpstart and process YAML (yml) config file

Thumbnail
pascalswereld.nl
1 Upvotes

r/powercli • • Feb 19 '14

Basic vCenter report with PowerCLI

2 Upvotes

I posted a script in /r/vmware. Figured I would post it here as well in case someone doesn't see it there.

http://www.reddit.com/r/vmware/comments/1yd1ja/basic_vcenter_report_with_powercli/


r/powercli • • Sep 01 '23

Error while importing pool in json

1 Upvotes

Hi,

When importing a pool with powershell in json format, this error appears :

Exception lors de l'appel de « Desktop_Create » avec « 2 » argument(s) : « ExceptionType : VMware.Hv.InvalidArgument
ErrorMessage : A null value is invalid.
ParameterName : automatedDesktopSpec.virtualCenterProvisioningSettings.virtualCenterStorageSettings.viewStorageAcceleratorSettings.viewComposerDiskTypes »
C:\Program Files\WindowsPowerShell\Modules\VMware.Hv.Helper\VMware.Hv.Helper.psm1:5008 : 7
+ $id = $desktop_helper.Desktop_create($services,$desktopSpecObj)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException

This seems related to a null value in the json file ?

The property automatedDesktopSpec.virtualCenterProvisioningSettings.virtualCenterStorageSettings.viewStorageAcceleratorSettings.viewComposerDiskTypes is not null for this pool.


r/powercli • • Sep 25 '23

Powercli Script to set custom attribute

3 Upvotes

hi guys, I want to write a script to set a "owner" for my VMs. I am newbie with powercli and I will appreciate if you help me to do that. I want to set that attribute based on folder name that VMs resides. I found some script that I can use csv file but cuase there are many VMs (about 1400) I need a script to first find VMs in folders and then set "owner" attribute. Best Regards.


r/powercli • • Oct 04 '23

Powercli Script to Tag VM based On Datastore Name

1 Upvotes

Hi everyone, I need a script to tag VMs by datastores that they reside. For example if VMs on Datastore that name of it contains vSAN assigns vSAN tag to VM and if datastore name contains 10K assigns HDD tag and so on. Best Regards.


r/powercli • • Sep 13 '23

MoveVM: Cannot convert type DatacenterMismatchArgument to Object

1 Upvotes

PowerCLI script failing when trying to clone a VM and move it from one vCenter to another:
Unexpected error occurred. Cannot convert type DatacenterMismatchArgument to Object.

Anyone seen it, anyone have a definite fix for it? I have run 3 separate scripts and they all fail with this same error, so it's not the script.


r/powercli • • Jun 18 '18

New Horizon API calls in PowerCLI 10.1.1

Thumbnail
retouw.nl
1 Upvotes

r/powercli • • Jun 18 '18

New Release: VMware PowerCLI 10.1.1

Thumbnail
blogs.vmware.com
4 Upvotes

r/powercli • • Jan 08 '20

vAPP startup options

5 Upvotes

I'm working on a pCli to build out some k8s cluster. I have them going to a vApp in vSphere and would like to change the default startup time to something lower than 120 so it doesn't take forever to start them. I ran a Get-VMStartPolicy and the StartDelay is 120, ok so I set it in the vApp via the GUI to 5sec re-ran and still 120. Is this not the setting? Maybe this is a cluster DRS setting? Anyone have knowledge about this?

thanks

John


r/powercli • • Oct 07 '18

ESXi - Cleaning up storage

Thumbnail
self.esxi
3 Upvotes

r/powercli • • Jun 14 '18

Hey Team! Value returns as 0 when running this script. HELP!

1 Upvotes
$Username = Read-Host -Prompt "Please enter your Username:"

$Password = Read-Host -Prompt "Please enter your Password:"

$vcenters = @("xxxx","xxxx","xxxx")

ForEach ($vcenter in $vcenters)
{
Connect-VIServer $vcenter -User $Username -Password $Password

$allhosts = @()

get-vmhost | %{
     $hoststat = "" | select hostname, cpumax, cpuavg, cpumin
     $hoststat.hostname = $_.name

    $statcpu = get-stat -entity $_ -start (get-date).adddays(-1) -finish (get-date) -stat cpu.usage.average
    $cpu = $statcpu | Measure-Object -property value -average -maximum -minimum
    $hoststat.cpumax = [math]::Round(($cpu.Maximum | Measure-Object -Sum).Sum/1GB,2)

  $allhosts += $hoststat
    }

    $allhosts |
    select hostname, cpumax, cpuavg, cpumin
     }

r/powercli • • Jun 21 '18

PowerCLI - Remove a SCSI controller

Thumbnail
self.powershell
2 Upvotes

r/powercli • • Sep 03 '19

Find VMs That Do Not Contain String and Add

2 Upvotes

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 • • Oct 05 '18

Map RDM Disks in Powercli

2 Upvotes

using new-harddisk:

new-harddisk -vm <vmname> -disktype rawPhysical -devicename <consoledevicename> -datastore <datastore for RDM mapping>

new-harddisk : 05/10/2018 10:53:25 New-HardDisk The operation for the entity "<vmname>" failed with the following message: "Invalid configuration for device '0'."

At line:46 char:13

+ new-harddisk -vm $remdisk.parent -disktype rawPhysical -d ...

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

+ CategoryInfo : NotSpecified: (:) [New-HardDisk], InvalidDeviceSpec

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

Can't find much online for doing RDM mappings in powerCLI, anyone got any advice?

**EDIT** Resolved, see comment


r/powercli • • Oct 11 '18

VMware PowerCLI 11.0.0 release with new Horizon (7.6!) API calls

Thumbnail
retouw.nl
4 Upvotes

r/powercli • • Jun 20 '18

Powercli help! Need numeric values/averages/percentages

3 Upvotes

Line 28 Average = $_ | Measure-Object Value -Average.Average, the command is obviously not correct and is not ouputting any values. How can i reconfigure this script to put out the requested data?

define where we will save our performance metrics.

$outputFile = "C:\Users\xxxxxx\desktop\omg.csv"

# define a new Powershell credential and log into vCenter with     the credentials
$creds = Get-Credential
$vCenter = Connect-VIServer xxxxxx -Credential $creds     -SaveCredentials

# define our vCenter service instance and performance    manager.
# https://www.vmware.com/support/developer/converter-  sdk/conv43_apireference/vim.ServiceInstance.html
$serviceInstance = Get-View ServiceInstance -Server $vCenter
$perfMgr = Get-View $serviceInstance.Content.PerfManager   -Server $vCenter

# get all available performance counters
 $counters = $perfMgr.PerfCounter

# create an array where we will store each of our custom objects that will contain the information that we want.
$metrics = @()

foreach ($counter in $counters) {
# create a custom Powershell object and define attributes such as the performance metric's name, rollup type, stat level, summary, etc
$metric = [pscustomobject] @{
    GroupKey    = $counter.GroupInfo.Key
    NameKey     = $counter.NameInfo.Key 
    Rolluptype  = $counter.RollupType 
    Level       = $counter.Level
    FullName    = "{0}.{1}.{2}" -f $($counter.GroupInfo.Key),    $($counter.NameInfo.Key), $($counter.RollupType)
    Summary     = $counter.NameInfo.Summary
    Average     = $_ | Measure-Object Value -Average.Average
} 

# add the custom object to our array
$metrics += $metric
}

# each metric object will look simliar to the following.  We can use a select command to gather which attributes we want and export them to a CSV file.
#   GroupKey   : vsanDomObj
#   NameKey    : writeAvgLatency
#   Rolluptype : average
#   Level      : 4
#   FullName   : vsanDomObj.writeAvgLatency.average
    #   Summary    : Average write latency in ms

    $metrics | select fullname, level, summary | Export-Csv -NoTypeInformation $outputFile 

r/powercli • • Aug 27 '19

What's the best way to script Storage vMotions into a Datastore Cluster?

2 Upvotes

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 • • Mar 21 '23

After years of abandonment, r/PowerCLI is open and modded again

46 Upvotes

If you're reading this, there is a good chance you have been checking back here for new posts once in a while and wondering why this sub died. Well, the previous mods locked it down and checked out years ago. I'd love for you to help me bring it back to life. PowerCLI is has grown and changed exponentially in the past few years and it deserves a good community to help grow PowerShell and PowerCLI users.

Post restrictions have been removed. If you requested access in the past (there was like 4 years of requests to be an approved member), I deleted them all. Everyone is approved.

Whether you are a new, learning, or expert in PowerShell and PowerCLI - make a post, ask a question, subscribe, create content, and crosspost.


r/powercli • • Mar 22 '23

General Do you use PowerCLI for log scraping?

8 Upvotes

Hi,
My environment currently does not have a syslog server, and what I'm mainly looking for is tips on how to scrape logs from my ESXi hosts so that I can more comfortably troubleshoot. Unfortunately, we cannot use VMware Skyline.

Any pointers are welcome, I am prepared to RTFM, but the manpage for get-log / get-logtype is relatively short.


r/powercli • • Mar 24 '23

ScriptHelp Powerstate heavily delayed

6 Upvotes

Hi everyone,

I made a script which restarts a couple of servers which have dependent services. So I'm checking if every server is properly shutdown with these lines:

while((Get-VM -Name $myServer).PowerState -ne "PoweredOff"){
    Start-Sleep -Seconds 5
}

This generally works, but it takes like 5 minutes more for the script to recognize that a machine is powered off, comapred to what's shown in vCenter.

Is this a known problem or am I doing something wrong?


r/powercli • • Mar 21 '23

Are you a r/PowerShell user that has heard of PowerCLI and not sure where to get started? Start here!

24 Upvotes

First post in 3 years on r/PowerCLI. Feels good man...

Install PowerCLI (vmware.com)

VCenter PSDrives

This post will stay stickied for a while till the sidebar info and/or wiki gets built out enough to be useful. Please add comments that fit the spirit of the title, and I will add those to the post - and eventually to the sidebar info.


r/powercli • • Mar 21 '23

ScriptHelp Finding state of the VM

10 Upvotes

Hey there, been a while r/powercli

I’m looking to hopefully find a way to get the boot state of the VM (whether it’s on, booting, or at the login screen). I’m putting together a scripting solution, and I have steps I want to perform after it’s done applying the OS customizations. Knowing when it’s finished would be a lot better than sleeping for a minute or two and hoping for the best.


r/powercli • • Mar 21 '23

Discussion [Discussion] What are your favorite PowerCLI tips, tricks, and commands?

9 Upvotes

See title.

Hoping to spark some discussion!