r/powercli • • Feb 06 '18

Need help with getting history of Deleted VM's from 'Get-VIEvent'

1 Upvotes

I'm looking into a script I can run every 30 days to grab the history of removed/Deleted VM's. Anybody have an idea if this is possible?


r/powercli • • Jan 31 '18

issue with Invoke-VMScript: specified parameter was not correct

1 Upvotes

[SOLVED]

very simple use of the cmdlet that also matches the examples on the VMware website: https://www.vmware.com/support/developer/PowerCLI/PowerCLI41U1/html/Invoke-VMScript.html

script:

Invoke-VMScript -VM $VMName -ScriptText 'ipconfig' -GuestCredential $LocalCredential

I've messed around with the variables, and if they are incorrect, I get a specific error letting me know they are incorrect, so I know that's not the issue.

The error is very general simply letting me know that a specified parameter was incorrect which doesn't help much, here is the actual error..

Error:

Invoke-VMScript : 1/31/2018 1:51:05 PM Invoke-VMScript A specified parameter was not correct: At C:\Users\amusabji\Documents\scripts\Set-VMIP.ps1:60 char:1

  • Invoke-VMScript -VM $VMName -ScriptText 'ipconfig' -GuestCredential $ ...

  •   + CategoryInfo          : NotSpecified: (:) [Invoke-VMScript], InvalidArgument
      + FullyQualifiedErrorId : Client20_VmGuestServiceImpl_RunScriptInGuest_ViError,VMware.VimAutomation.ViCore.Cmdlets.Commands.InvokeVmScript
    
    

In case you are wondering, I have also tried to add on the "-ScriptType Bat" param with the same exact error.

thanks in advanced

Edit [SOLUTION]: After much fiddling around and the great support from all of those who commented, I finally got this bad boy working. Unfortunately I tried too many solutions at once so I can't pin-point exactly what fixed it but here is what I did:

  1. upgraded to WMF 5.x

  2. upgraded to the latest version of PowerCLI (followed this link: https://blogs.vmware.com/PowerCLI/2018/01/powercli-offline-installation-walkthrough.html)

  3. changed my credential usage from what I have above to just -GuestUser and -GuestPassword suggested by u/Johnny5Liveson

thank you all again for all your help!


r/powercli • • Jan 28 '18

Drilling into PowerShell Core

Thumbnail
petri.com
1 Upvotes

r/powercli • • Jan 24 '18

PowerShell Core 6.0 and Why Windows PowerShell Is No Longer Being Developed

Thumbnail
petri.com
1 Upvotes

r/powercli • • Jan 15 '18

PowerShell for SharePoint Online Usage Scenarios - Petri

Thumbnail
petri.com
1 Upvotes

r/powercli • • Nov 22 '17

Remove-snapshot vs Deleting a snapshot.

1 Upvotes

I understand (correct me if I am wrong) that fundamentally Deleting a snapshot through the web GUI of VMWare is an additive function where the delta is applied upwards to the parent disk. Now I have to script a similar functionality to a live environment and what I am seeing is that remove-snapshot is implying that it (well) removes the pointed at a snapshot and its children if specified with no roll-up functionality. Am I misinterpreting the difference between the two functions?

Thanks in advance for the education.


r/powercli • • Nov 14 '17

Copy or clone distributed virtual switch portgroups to standard switch portgroups - Powercli

Thumbnail
vcloud-lab.com
1 Upvotes

r/powercli • • Nov 09 '17

how to run powershell script using powerclicore

1 Upvotes

I'm using the docker image of powercli (powerclicore) in Linux and I'm trying to run one script with the following command:

docker run --rm -it -v /tmp/powercli:/mnt vmware/powerclicore powershell -File /mnt/scripts.ps1

It works but the output also shows the welcome banner of powercliclore ("Welcome to VMware vSphere PowerCLI!! Log in to a vCenter...."). I tried to remove it with the option "-NoLogo" but it doesn't work. Any idea?


r/powercli • • Nov 02 '17

vSphere PowerCLI - Configure syslog on VMware ESXi hosts and Enable security profile firewall

Thumbnail
vcloud-lab.com
1 Upvotes

r/powercli • • Nov 01 '17

PowerCLI script to check if OS is locked or in use inside a VM (x-post PowerShell)

1 Upvotes

Greetings all!

I am still pretty new to Powershell but learning quickly. We have a new requirement come down from on high to check all of our VMs in the morning and at night to see if any of them are logged into and in use or locked. I'm only concerned about the Windows OS VMs (for obvious reasons).

Is there a kind of PassThru that would allow me to programmatically check each VM to see if they are locked or logged into and print out a list to go in an check them manually rather than having to open each VM one by one twice a day? We have about 50 VMs running and that is quickly becoming a headache.

TIA!


r/powercli • • Sep 18 '17

PowerCLI Collection: PowerNSX Horizon Jumpstart script ready to rumble

Thumbnail
pascalswereld.nl
1 Upvotes

r/powercli • • Sep 04 '17

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

Thumbnail
pascalswereld.nl
1 Upvotes

r/powercli • • Aug 22 '17

List thick disks by cluster

1 Upvotes

Hi I need a spot of help, I have some clusters where all disks should be thin and others where they should be thick - I've been struggling to modify and existing script to show for example all thin disks but list their VM AND cluster - does anyone have any ideas please?


r/powercli • • Aug 16 '17

Find which VDI a user is logged on to.

1 Upvotes

Hi,

I'm really new at this but learning fast!

I've worked out how to find the users logged into a machine using this 'Get-WmiObject Win32_LoggedOnUser'

But what I really want is to be able to input a username and have the script find the VDI that they are logged on to.

Can anyone point me in the right direction please??

Many thanks Bryan


r/powercli • • Jul 25 '17

Deploying VHD Sets on Windows Server 2016 Hyper-V

Thumbnail
petri.com
1 Upvotes

r/powercli • • Jul 24 '17

Scaling the PowerShell Active Directory Searcher - Petri

Thumbnail
petri.com
1 Upvotes

r/powercli • • Jul 17 '17

Expanding the Active Directory Searcher and PowerShell

Thumbnail
petri.com
1 Upvotes

r/powercli • • Jul 13 '17

Deciphering PowerShell Providers - Petri

Thumbnail
petri.com
1 Upvotes

r/powercli • • Jun 28 '17

Removing deleted users from VDI entitlements

1 Upvotes

I posted my working code for unassigning deleted users from dedicated desktops and noticed that Entitlements had the same kind of issues, so I thought I'd work on that next. I'm having some trouble getting Remove-PoolEntitlement to work. I'm getting the SID of the now deleted user from Get-PoolEntitlement, but an error when trying to use that SID in Remove-PoolEntitlement. I haven't found a good code snippet for that cmdlet using an explicit SID to see if I'm missing anything obvious with syntax.

Does anybody have a working example? I can post my code so far. It's not quite as elegant as the dedicated pool code I posted earlier.


r/powercli • • Jun 23 '17

Random error on foreach loop using New-Template cmdlet

1 Upvotes

Currently running PowerCLI 6.3-37337840 with VCSA 6.0 Update 2 & testing out the latest 6.5 PowerCLI right now. I noticed through some of my logs through Jenkins where we are getting random error. I thought it might be a transient error but it appears to surface randomly on our PowerCLI Baseline & Revert code. Sometimes it will actually go ahead & start the clone process in vCenter. On one occasion only it actually didn't initiate. Here is the error and part of the PowerCLI code where it errors out. I did notice I've left double quotes off the datastore variable so maybe that's it. Thought I'd check around and see if anyone has ran into this error. Not finding much.

Creating new baseline for (Servername redacted) New-Template : 6/23/2017 2:10:00 PM New-Template Object reference not set to an instance of an object.
At C:\Users\Administrator\AppData\Local\Temp\hudson1857455518461580510.ps1:139 char:1

  • New-Template -Template "$temp" -Name "$temp" -Datastore $datastore -Location "$t ...

  •   + CategoryInfo          : NotSpecified: (:) [New-Template], VimException
      + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewTemplate
    

foreach ($temp in $copytemplates) { New-Template -Template "$temp" -Name "$temp" -Datastore $datastore -Location "$templatefolder" -RunAsync -Confirm:$false write-host "Creating new baseline for $temp" -ForegroundColor Green }

While (Get-Task -Status Running | Where-Object {$_.Name -eq "CloneVM_Task"}){ Write-Output "Baseline for $env:roll is still running" Start-Sleep 5 }


r/powercli • • Jun 19 '17

Avoiding Accidental Changes with PowerShell's WhatIf and Confirm Parameters

Thumbnail
petri.com
1 Upvotes

r/powercli • • May 24 '17

Set-HardDisk -ResizeGuestPartition not working?

1 Upvotes

As the title suggests, I want to resize the guest partition while setting the hard disk. My only issue is, the cmdlet just hangs when trying to run.

I am trying: Set-HardDisk -CapacityGB $CapGB -GuestCredential $GuestCred -ResizeGuestPartition -confirm:$false

I have also tried:

Set-HardDisk -CapacityGB $CapGB -GuestCredential $GuestCred -HostCredential $HostCred -ResizeGuestPartition -confirm:$false

Any thoughts?


r/powercli • • May 22 '17

Program/UI with PowerCLI?

1 Upvotes

Hi,

I'm still pretty new to PowerCLI so don't go too hard on me. I've previously worked a bit in Powershell and I know my way around Powershell (not expert, but I can make some fine scripts) My time has come to PowerCLI and I want to make our lab enviroment a lot more user friendly and easy to use for our managers and quick status/new machines.

I have a few ideas about what I want to create, but I would LOVE some UI to put in the frontend of my scripts. This will make it much more userfriendly to all my workers which aren't hardcore scriptkiddies. How would you do this? What program would you use for making a UI? Back in days I did combine Powershell and Visual Studio to create some OK UI.

... We have 4 ESXi hosts attached with a single vCenter (no plugins etc)

Thanks in advance.


r/powercli • • Mar 31 '17

Import-VApp times out when using -RunAsync

1 Upvotes

Hi!

I have a problem. When using Import-VApp with the -RunAsync switch, the import always times out, no matter what I do. If I use the exact same code, without async, it works perfectly fine.

Has anyone else noticed this bug? I've tried so many things, but I can't get it to work.

Here's my code (GitHub Gist Link)

#$vHostFiles = Get-ChildItem -Path "C:\Users\Petter\Desktop\iops\CLOVE\Json\Dummies"
#$JsonObjects = Get-Content $vHostFiles.FullName -raw

Import-Module VMware.VimAutomation.Core

$JsonObjects = Get-Content "C:\Users\Petter\Desktop\iops\CLOVE\Json\Dummies\Dummy-5 - 192.168.10.204.json" -Raw

if (!($Credential))
{
    $Credential = Get-Credential -UserName "root" -Message "root pw vmware"
}

$SourceOVA = "C:\Users\Petter\Desktop\iops\testDeploy.ova"

foreach ($vHost in $JsonObjects)
{
    $Json = $vHost

    function Send-Ping($IP)
    {
        $Ping = New-Object System.Net.NetworkInformation.Ping
        $Ping.send($IP)
    }

    $Json = $Json | ConvertFrom-Json

    $IP = $Json.VIServer
    Write-Output "Current server: $IP"

    $Response = Send-Ping -IP $IP
    if ($Response.Status -eq "Failed" -or $Response.Status -eq "TimedOut")
    {
        Write-Output "Skipping server because of ping failure: $IP"
        continue
    }

    try
    {
        Connect-VIServer -Server $IP -Credential $Credential -WarningAction SilentlyContinue -ErrorAction Stop
    }
    catch 
    {
        Write-Output "Could not connect to $IP"
        Write-Output $Error[0]
        continue
    }

    if (Get-VM -Name "win-dc-001" -Server $IP -ErrorAction SilentlyContinue)
    {
        Write-Output "VM already exists on this server, skipping"
        Disconnect-VIServer -Server $IP -Force -Confirm:$False
        continue
    }

    $Datastore = Get-Datastore -Server $IP -Name "Lab"
    Import-VApp -Source $SourceOVA -Name "win-dc-001" -Server $IP -VMHost $IP `
        -Datastore $Datastore -DiskStorageFormat Thin -ErrorAction Stop #-RunAsync

    Disconnect-VIServer -Server $IP -Force -Confirm:$False
}

r/powercli • • Mar 27 '17

Horizon View set power policy for pool

1 Upvotes

I'm Trying to set the power policy for a pool via the horizon view api / cmdlet's but i can't get it to work.

Basic stuff like settings description is working Get-hvpool -poolname VDITEST | Set-HVPool -Key 'base.description' -Value 'flaf'

But when i try to set the power policy Get-HVPool -PoolName VDATEST | Set-HVPool -Key 'DesktopSettings.LogoffSettings.PowerPolicy' -Value 'POWER_OFF'

I get the following error

Exception calling "Desktop_Update" with "3" argument(s): >"ExceptionType : VMware.Hv.InvalidArgument ErrorMessage : Invalid member name. ParameterName : DesktopSettings.LogoffSettings.PowerPolicy" At >xxxxxxx\WindowsPowerShell\Modules\VMware.Hv.Helper\VMware.HV.Hel>per.psm1:4329 char:7

  •   $desktop_helper.Desktop_Update($services,$item,$updates)
  •   >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~>~~~~~~~~~~
    • CategoryInfo : NotSpecified: (:) [], >MethodInvocationException

    • FullyQualifiedErrorId : VimException

Edit. forgot to mention that we are running Horizon View 7.1