Quantcast
Channel: VMware Communities : Discussion List - Automation Tools
Viewing all 9071 articles
Browse latest View live

Setting a delay in powercli script for tagging hosts

$
0
0

Scenario is:  Tagging multiple hosts from my flat switch. I will lose connectivity to hosts until I plug in my startech device and assign the tag to it.  when the script runs it pretty much just stalls after the 1st host. I have tried removing the discconect-viserver.   /Any thoughts? see script below.   Looking for something that acts like nohup sleep command.   Also start-sleep is not what i need. 

 

$file_hosts = "c:\ps\ip.csv"

 

 

#Login Variables

$auth_usr = "root"

$auth_pwd = "Youwillneverknow"

 

 

#variables - Management network

$pg_ManageNet = "Management Network"

 

 

 

 

#variables - CVM network

$Host_CVM_VLAN = 3

$New_NamePortGroupCVM = "CVM_MGNT"

$pg_CVM = "VM Network"

   

  Import-csv $file_hosts | ForEach-Object {

    $host_ntnx = $_.hostntnx 

   

    Connect-VIServer -Server $host_ntnx -User $auth_usr -Password $auth_pwd -Force

    Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -WarningAction SilentlyContinue -Confirm: $false

    Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $false -Confirm: $false

    Write-Host "******************************************************************"

    Write-Host "******************************************************************"

    Write-Host "connected to" $host_ntnx

 

 

    Write-Host "******************************************************************"

    Write-Host "******************************************************************"

    Write-Host "Configuring CVM Portgroup for" $host_ntnx

 

 

    #Setting vSwitch0 Variable

    $VSwitch0 = Get-VirtualSwitch -VMHost $host_ntnx -Name "vSwitch0"

 

 

    #rename/tag CVM port group

    Write-Host "rename/tagging cvm portgroup"

    $VSwitch0 = Get-VirtualSwitch -VMHost $host_ntnx -Name "vSwitch0"

    $CVM_PortGroup_Config = Get-VirtualPortGroup -VMHost $host_ntnx -VirtualSwitch $VSwitch0 -Name $pg_CVM | Set-VirtualPortGroup -Name $New_NamePortGroupCVM -VlanId $Host_CVM_VLAN

   

    if($?)

{

Write-Host "******************************************************************"

Write-Host "******************************************************************"

  Write-Host "command succeeded"

Write-Host "******************************************************************"

Write-Host "******************************************************************"

  

}

else

{

Write-Host "******************************************************************"

Write-Host "******************************************************************"

   Write-Host "command failed"

Write-Host "******************************************************************"

Write-Host "******************************************************************"

}

 

 

    Write-Host "******************************************************************"

    Write-Host "******************************************************************"

    Write-Host "Configuring Host Portgroup for" $host_ntnx

 

 

    #Tag Management Network

    Write-Host "Tagging mgmt network"

    $TAGnetwork = Get-VirtualPortGroup -VMHost $host_ntnx -VirtualSwitch $VSwitch0 -Name $pg_ManageNet | Set-VirtualPortGroup -VlanId $Host_CVM_VLAN

   

 

 

        Write-Host "******************************************************************"

    Write-Host "******************************************************************"

    Write-Host "Finished DNS Config" $host_ntnx

    Write-Host "******************************************************************"

    Write-Host "******************************************************************"

    Write-Host "Disconnecting from" $host_ntnx

 

 

    Disconnect-VIServer -Server $host_ntnx -Confirm:$false

 

    }


VMware Management with PowerCLI 5.0

$
0
0

Download the PowerCLI 5.0 Poster from this post.

get-vm -tag gives a timeout with newer versions of PowerCLI

$
0
0

We use get-vm -tag <tagname> a lot with the Powershell Powercli module, but as of late we found out that it gives a timeout on some machines.

I have tried the latest powerclicore container (to rule out incompatibilities with older module versions) but that does also give a timeout.

 

Machines with older versions of the module (6.5) can still use this functionality.

 

I tried downgrading to 6.5, but on my machine it still gives a timeout.

 

Ideally I would start using PowerCLIcore so we can containerize our scripts (always the right version for the scripts) so my question is:

Has someone seen this working on the newer versions of PowerCLI (or knows what could be the problem)

 

Version 11 and 6.5 do not seem to work when downloaded with install-module

 

Best regards,

Sander

 

VMware ESXi, 6.5.0, 8294253

Vcenter 6.5.0 7312210

PowerCLI - License label update

$
0
0

Hi All,

 

I'm new member so thanks in advance for your help for my little problem .

 

I have do a PowerCLI script that add a host license in the connect VC and put this in one host, the list of license key and hosts are in the file lic.txt and hosts.txt. This the code:

 

$MyVC=Connect-VIServer -Server 192.168.100.10 -User administrator@vsphere.local -Password *************

 

$LicenseManager = get-view ($MyVC.ExtensionData.content.LicenseManager)

$LicKey = Get-Content C:\Script\lic.txt
$ESXiHost = Get-Content C:\Script\hosts.txt

 

foreach($row in $ESXiHost) {
   
    $LicenseManager.AddLicense($LicKey,$null)
    Set-VMHost -VMHost $ESXiHost -LicenseKey $LicKey

 


}

Disconnect-VIServer -Server * -Force -Confirm:$false

 

All works fine but I need to change the label on column "License" from "License 1" to "host_name", there is some way to do this?

 

Domesenn

Script error when trying to move vms to their dedicated folders

$
0
0

Hello,

 

I am having issues when using a script to move VMs from the Discovered VMs folder to their dedicated VM folders as they were on the old vCenter. I already recreated the folder structure on the new vCenter.

 

The csv from where i am importing is on the form:

 

Name  Path

 

vm1     DatacenterFolderName\folder1\folder2\vm1

vm2     DatacenterFolderName\folder2\folder3\vm2 etc

 

The script is the following:

 

Get-Module -Name VMware* -ListAvailable | Import-Module

If ($globale:DefaultVIServers ) {

Disconnect-VIServer -Server $global:DefaultVIServers -Force

}

 

$destVI = Read-Host "Please enter name or IP address of the destination Server"

$datacenter = Read-Host "DataCenter name in VC"

$creds = get-credential

connect-viserver -server $destVI -Credential $creds

 

# move the vm's to correct location

$VMfolder = @()

$VMfolder = import-csv "c:\csv-files\test\04-$($datacenter)-vms-with-FolderPath.csv" | Sort-Object -Property Path

 

foreach($guest in $VMfolder){

$key = @()

$key =  Split-Path $guest.Path | split-path -leaf

if ($key -eq $datacenter) {

Write-Host "Root folder $guest.path"

#

Move-VM (Get-VM $guest.Name) -Destination "vm"

}

else

{

Move-VM (Get-VM $guest.Name) -Destination (Get-folder $key)

}

}

 

Disconnect-VIServer "*" -Confirm:$False

 

and the error i am getting is the following:

 

Move-VM : 10/19/2018 7:50:24 AM Move-VM Server task failed: The request refers to an unexpected or unknown type.

At C:\Users\username\Desktop\CheapDisasterRecovery\import-05-move-vms-folders.ps1:27 char:3

+         Move-VM (Get-VM $guest.Name) -Destination (Get-folder $key)

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

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

    + FullyQualifiedErrorId : Security_Impl_TaskResultConverter_TaskNotSucceeded,VMware.VimAutomation.ViCore.Cmdlets.Commands.MoveVM

 

Can someone let me know what i am doing wrong or if there is something that needs to be modified to make it work?

 

The original vCenter is 5.5 and the destination vCenter is 6.5.

 

Thank you.

Powercli list VM's Portgroups

$
0
0

i am running vCenter 6.0 and i need to list all of my VM's and their assigned portgroup names via powercli

PowerCLI Help: Code to Remove Snapshot Task with Remove-Snapshot cmdlet

$
0
0

Hello,

 

I am trying to write a script which will remove a snapshot task once the remove-snapshot has run and completed.  I am having some problem creating the commands.  Please can someone assist.  I have a script which creates the snapshot tasks but can't figure out how to make one to remove the snapshot task.  Please can someone help me fix this?  Thank you for your assistance.

 

Here is an example of my code below.  The first one doesn't remove the task.  The second works and creates the task.

 

# Remove Snapshots after Windows Patching

Param(
    [Parameter(Mandatory=$true)]    [string]$name, # Description of the snapshot "Windows Patching Staging 1" or "Windows Patching Staging 2"    [string]$path  # Path to the host file used for creating the snapshots prior to patching
);
$vms = (Get-Content $path).Split("`n");
$inLine = @();
foreach ($vm in $vms) {    $inLine += Get-VM $vm | Get-Snapshot | fl    if (Get-VM $vm | Get-Snapshot | Where-Object {$_.Description -eq $name} | select VM,Description,Created) {        Get-Snapshot -VM $vm -Name $name | Remove-Snapshot -Confirm:$false        $inLine += Write-Host $vm ": Removed snapshot"}        else {        (Get-VM $vm | Get-Snapshot | Where-Object {$_.Description -eq $name} | select VM,Description,Created)        $inLine += Write-Host $vm ": Could not locate snapshot with that description"}    };
foreach ($vm in $vms) {     if ((Get-View ScheduledTaskManager).ScheduledTask | %{ (Get-View $_).Info } | Where-Object {$_.Name -match ".*$vm.*"}) {        $inLine += (Get-View ScheduledTaskManager).ScheduledTask | %{ (Get-View $_).Info } | Where-Object {$_.Name -match ".*$vm.*"}        ((Get-View ScheduledTaskManager).ScheduledTask | %{ (Get-View $_).Info } | Where-Object {$_.Name -match ".*$vm.*"}).RemoveScheduledTask        }        else {        $inLine += Write-Host $vm ": Could not locate snapshot task with that description"}    };
$inline;

 

# Create Scheduled Task for Snapshots
# Windows Patching

param (
    [Parameter(Mandatory=$true)]    [string]$path, # Example: "H:\Scripts\hosts.csv"    [string]$date, # Example: "11/11/2016 05:00"    [string]$name  # Example: "Windows Patching Staging 1 or 2"
);
$snapTime = (Get-Date $date); # [datetime]$date;
$snapName = $name;
$snapDescription = $name;
$snapMemory = $false;
$snapQuiesce = $true;
$emailAddr = 'name@somewhere.com';
$vms = (Get-Content $path).Split("`n");
$interval = "30";
foreach ($vm in $vms) {    $vm = Get-VM -Name $vm    $instance = get-view ServiceInstance    $scheduledTaskManager = Get-View $instance.Content.ScheduledTaskManager    # Task Specifics    $spec = New-Object VMware.Vim.ScheduledTaskSpec    $spec.Name = "PowerCLI: Snapshot of " + $($vm.Name)    $spec.Description = "Take a snapshot of $($vm.Name)"    $spec.Enabled = $true    $spec.Notification = $emailAddr    # Schedule Task Once    $spec.Scheduler = New-Object VMware.Vim.OnceTaskScheduler    $spec.Scheduler.runat = $snapTime    # Create Snapshot Task    $spec.Action = New-Object VMware.Vim.MethodAction    $spec.Action.Name = "CreateSnapshot_Task"      @($snapName,$snapDescription,$snapMemory,$snapQuiesce) | %{        $arg = New-Object VMware.Vim.MethodActionArgument        $arg.Value = $_        $spec.Action.Argument += $arg     }    $scheduledTaskManager.CreateScheduledTask($vm.ExtensionData.MoRef, $spec) #    Write-Host "--------";    Write-Host "Run At: " $snapTime    Write-Host "VM Name: " $vm    Write-Host "Snapshot Name: " $name    Write-Host "--------";    $snapTime = $snapTime.AddMinutes($interval)
};

how to modify vSphere power policy with powercli

$
0
0

Hi,

 

I'm looking a way to modify the power management settings for the hosts with powercli.

 

switching between the 4 policy and getting info on hosts having this capability.

 

I didn't find anything so far

 

any clue?

 

thanks

 

Eric


Mass Upgrade Of VMware Tools for Linux Hosts

$
0
0

Hi,

 

Is there a way to upgrade VMware Tools on multiple linux VMs using powercli

 

As per the VMware document, I see we can right click on the VM and click on upgrade vmware tools by passing --default parameter to linux VM.

 

Is this can be achieved by PowerCLI ?

 

Please help

 

Backup-VCSA module error

$
0
0

Hello, I'm getting a weird error when using the Backup-VCSA module created by Brian Graaf. I have successfully used that module over 4 vCenter servers already for months, but on this Windows jump box dedicated to a different vCenter appliance I'm getting this error (I don't avail of another jump box), I am wondering whether it could be related to the .net framework which I just upgraded to 5.1?

 

This is the script:

 

$user = 'xxxxxxx@vsphere.local'      $vcenter = 'xxxxxxxx'      $password = get-content "C:\Scripts\Pro\VCSA-Backup\creds.txt" | convertto-securestring -key (1..16)      $cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $user,$password            Connect-CisServer -Server $vcenter -User $user -Password $cred.GetNetworkCredential().Password      Connect-VIServer -Server $vcenter -User $user -Password $cred.GetNetworkCredential().Password                $Comment = "Full Backup $vcenter-$(Get-Date).ToString('yyyy-MM-dd')"        $LocationType = "FTPS"        $location = "xxxxxx/backup/$vcenter-$((Get-Date).ToString('yyyy-MM-dd'))"        $LocationUser = "xxxxxxxx"        [VMware.VimAutomation.Cis.Core.Types.V1.Secret]$locationPassword = "xxxxxxxxx"        Backup-VCSAToFile -LocationType $LocationType -Location $location -LocationUser $LocationUser -LocationPassword $locationPassword -Comment $Comment -FullBackup

 

I broke the execution bit by bit and the error is thrown when last line is executed. So something inside the Backup-VCSAToFile module, however it runs fine on other jump boxes for otehr vCenter servers, here's the error:

 

Method invocation failed because [System.Management.Automation.PSCustomObject] does not contain a method named 'Create'.
At C:\Scripts\Pro\VCSA-Backup\Backup-VCSA.psm1:60 char:9
+         $CreateSpec = $BackupAPI.Help.create.piece.Create()
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    + CategoryInfo          : InvalidOperation: (Create:String) [], RuntimeException    + FullyQualifiedErrorId : MethodNotFound

The property 'parts' cannot be found on this object. Verify that the property exists and can be set.
At C:\Scripts\Pro\VCSA-Backup\Backup-VCSA.psm1:61 char:9
+         $CreateSpec.parts = $parts
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException    + FullyQualifiedErrorId : PropertyNotFound

The property 'backup_password' cannot be found on this object. Verify that the property exists and can be set.
At C:\Scripts\Pro\VCSA-Backup\Backup-VCSA.psm1:62 char:9
+         $CreateSpec.backup_password = $BackupPassword
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException    + FullyQualifiedErrorId : PropertyNotFound

The property 'location_type' cannot be found on this object. Verify that the property exists and can be set.
At C:\Scripts\Pro\VCSA-Backup\Backup-VCSA.psm1:63 char:9
+         $CreateSpec.location_type = $LocationType
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException    + FullyQualifiedErrorId : PropertyNotFound

The property 'location' cannot be found on this object. Verify that the property exists and can be set.
At C:\Scripts\Pro\VCSA-Backup\Backup-VCSA.psm1:64 char:9
+         $CreateSpec.location = $Location
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException    + FullyQualifiedErrorId : PropertyNotFound

The property 'location_user' cannot be found on this object. Verify that the property exists and can be set.
At C:\Scripts\Pro\VCSA-Backup\Backup-VCSA.psm1:65 char:9
+         $CreateSpec.location_user = $LocationUser
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException    + FullyQualifiedErrorId : PropertyNotFound

The property 'location_password' cannot be found on this object. Verify that the property exists and can be set.
At C:\Scripts\Pro\VCSA-Backup\Backup-VCSA.psm1:66 char:9
+         $CreateSpec.location_password = $LocationPassword
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException    + FullyQualifiedErrorId : PropertyNotFound

The property 'comment' cannot be found on this object. Verify that the property exists and can be set.
At C:\Scripts\Pro\VCSA-Backup\Backup-VCSA.psm1:67 char:9
+         $CreateSpec.comment = $Comment
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException    + FullyQualifiedErrorId : PropertyNotFound

A server error occurred: 'com.vmware.vapi.std.errors.invalid_argument': Structure operation-input is missing a field piece (Server error id: 'vapi.data.structure.field.missing'). Check 
$Error[0].Exception.ServerError for more details.
At C:\Scripts\Pro\VCSA-Backup\Backup-VCSA.psm1:72 char:13
+             throw $_.Exception.Message
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~    + CategoryInfo          : OperationStopped: (A server error ...r more details.:String) [], RuntimeException    + FullyQualifiedErrorId : A server error occurred: 'com.vmware.vapi.std.errors.invalid_argument': Structure operation-input is missing a field piece (Server error id: 'vapi.data.structure.field.m    issing'). Check $Error[0].Exception.ServerError for more details.

Trying to schedule AddStandaloneHost_Task with PowerCLI

$
0
0

I need to schedule adding host, yet the only thing I get is this unhelpful error:

vmerror.JPG

Here is how I do this(credentials and IP addresses changed, obviously):

 

$spec = new-object VMware.Vim.ScheduledTaskSpec

$spec.Name = "AddStandaloneHost_Task"

$spec.description = "some description"

$spec.Enabled = $true

 

$spec.scheduler = new-object vmware.vim.hourlytaskscheduler

$spec.scheduler.interval = 12

$spec.scheduler.minute = 59

 

$spec.action = new-object vmware.vim.methodaction

$spec.action.name = "AddStandaloneHost_Task"

 

$spec.action.argument = new-object vmware.vim.methodactionargument

 

$hostconnectspec =  new-object vmware.vim.hostconnectspec

$hostconnectspec.HostName = 192.192.192.192

$hostconnectspec.UserName ="user"

$hostconnectspec.Password ="1"

$hostconnectspec.Force = $true

 

$newargument = new-object vmware.vim.methodactionargument

$newargument.Value =  $hostconnectspec

 

$spec.action.argument +=$newargument

 

$dc = get-datacenter

$vmonlyfolder = get-folder -type VM -name vm -location $dc

$vmonlyfolderview = get-view -id $vmonlyfolder.Id

 

$stm = Get-View -Id 'ScheduledTaskManager-ScheduledTaskManager'

$stm.CreateScheduledTask($vmonlyfolderview.moref,$spec)

 

Any suggestion on what should I check to figure out why it refuses to work?

remove-shapshot woes

$
0
0

I am working to automate snapshot removal using powercli 6.5

 

My code is

 

## get the list of VM names from a text file

$vmList = Get-Content C:\Scripts\remove_snapshots.csv

 

$computernames = Get-Content -Path "C:\Scripts\remove_snapshots.csv"

$snapshotname = "Before MSPatching"

 

## Remove command

foreach ($vmName in $vmList) {Remove-Snapshot -Snapshot $snapshotname  -Confirm:$false -WhatIf}

 

I getting the following errors

 

Remove-Snapshot : Cannot bind parameter 'Snapshot'. Cannot convert the

"Before MSPatching" value of type "System.String" to type

"VMware.VimAutomation.ViCore.Types.V1.VM.Snapshot".

 

Any suggestion on fixing the current scrip or potentially ready to use script to  delete  specifically named snapshots on VMs

 

This is in ESXi 6.5 environment with PowerCLI Version :   VMware PowerCLI 6.5 Release 1 build 4624819

issue with the Veeam Find-VBRViEntity Cmdlet when PowerCLI Modules are loaded

$
0
0

Hello,

 

 

I ran into a strange issue with the Veeam Find-VBRViEntity Cmdlet when PowerCLI Modules are loaded:

PS C:\Users\Administrator> Find-VBRViEntity

 

 

WARNING: One or more errors occurred.

Id                                   Name               Path        

--                                   ----               ----        

49500DBE-39E7-4A3E-A48B-3F995D1EFF63 Hosts and Clusters             

e5f8ee73-cd14-4333-bf38-b7b14b2392f0 192.168.3.101      192.168.3.101

 

 

PS C:\Users\Administrator> Find-VBRViEntity

 

 

WARNING: Object reference not set to an instance of an object.

Id                                   Name               Path        

--                                   ----               ----        

49500DBE-39E7-4A3E-A48B-3F995D1EFF63 Hosts and Clusters             

e5f8ee73-cd14-4333-bf38-b7b14b2392f0 192.168.3.101      192.168.3.101

 

 

 

 

The expected output of the Cmdlet is:

PS C:\Users\Administrator> Find-VBRViEntity

 

 

Id                                                Name               Path                                       

--                                                ----               ----                                       

49500DBE-39E7-4A3E-A48B-3F995D1EFF63              Hosts and Clusters                                            

e5f8ee73-cd14-4333-bf38-b7b14b2392f0              192.168.3.101      192.168.3.101                              

e5f8ee73-cd14-4333-bf38-b7b14b2392f0_datacenter-2 Lab                192.168.3.101\Lab                          

e5f8ee73-cd14-4333-bf38-b7b14b2392f0_domain-c225  Cluster01          192.168.3.101\Lab\Cluster01                

e5f8ee73-cd14-4333-bf38-b7b14b2392f0_host-9       esxi-01.lab.local  192.168.3.101\Lab\Cluster01\esxi-01.lab.local

e5f8ee73-cd14-4333-bf38-b7b14b2392f0_vm-189       test19             192.168.3.101\Lab\Cluster01\test19         

e5f8ee73-cd14-4333-bf38-b7b14b2392f0_vm-184       test14             192.168.3.101\Lab\Cluster01\test14         

e5f8ee73-cd14-4333-bf38-b7b14b2392f0_vm-179       test9              192.168.3.101\Lab\Cluster01\test9          

e5f8ee73-cd14-4333-bf38-b7b14b2392f0_vm-14        PhotonOS           192.168.3.101\Lab\Cluster01\PhotonOS       

e5f8ee73-cd14-4333-bf38-b7b14b2392f0_vm-180       test10             192.168.3.101\Lab\Cluster01\test10         

e5f8ee73-cd14-4333-bf38-b7b14b2392f0_vm-185       test15             192.168.3.101\Lab\Cluster01\test15         

e5f8ee73-cd14-4333-bf38-b7b14b2392f0_vm-186       test16             192.168.3.101\Lab\Cluster01\test16         

e5f8ee73-cd14-4333-bf38-b7b14b2392f0_vm-182       test12             192.168.3.101\Lab\Cluster01\test12         

e5f8ee73-cd14-4333-bf38-b7b14b2392f0_vm-175       test5              192.168.3.101\Lab\Cluster01\test5          

e5f8ee73-cd14-4333-bf38-b7b14b2392f0_vm-190       test20             192.168.3.101\Lab\Cluster01\test20         

e5f8ee73-cd14-4333-bf38-b7b14b2392f0_vm-188       test18             192.168.3.101\Lab\Cluster01\test18         

e5f8ee73-cd14-4333-bf38-b7b14b2392f0_vm-18        test2              192.168.3.101\Lab\Cluster01\test2          

e5f8ee73-cd14-4333-bf38-b7b14b2392f0_vm-17        test3              192.168.3.101\Lab\Cluster01\test3          

e5f8ee73-cd14-4333-bf38-b7b14b2392f0_vm-183       test13             192.168.3.101\Lab\Cluster01\test13         

e5f8ee73-cd14-4333-bf38-b7b14b2392f0_vm-177       test7              192.168.3.101\Lab\Cluster01\test7          

e5f8ee73-cd14-4333-bf38-b7b14b2392f0_vm-15        Veeam-03           192.168.3.101\Lab\Cluster01\Veeam-03       

e5f8ee73-cd14-4333-bf38-b7b14b2392f0_vm-174       test4              192.168.3.101\Lab\Cluster01\test4          

e5f8ee73-cd14-4333-bf38-b7b14b2392f0_vm-176       test6              192.168.3.101\Lab\Cluster01\test6          

e5f8ee73-cd14-4333-bf38-b7b14b2392f0_vm-16        test               192.168.3.101\Lab\Cluster01\test           

e5f8ee73-cd14-4333-bf38-b7b14b2392f0_vm-187       test17             192.168.3.101\Lab\Cluster01\test17         

e5f8ee73-cd14-4333-bf38-b7b14b2392f0_vm-181       test11             192.168.3.101\Lab\Cluster01\test11         

e5f8ee73-cd14-4333-bf38-b7b14b2392f0_vm-178       test8              192.168.3.101\Lab\Cluster01\test8          

e5f8ee73-cd14-4333-bf38-b7b14b2392f0_host-228     esxi-02.lab.local  192.168.3.101\Lab\Cluster01\esxi-02.lab.local

 

 

The expected output is generated in the same system. But the difference is:

  • Load Veeam Snapin / Connect VBR Server -> Cmdlet works fine
  • Load Veeam Snapin / Connect VBR Server / Load VMware Modules / Connect vCenter Server-> Cmdlet does not work
  • Load Veeam Snapin / Connect VBR Server / run Find-VBRViEntity / Load VMware Modules / Connect vCenter Server-> Cmdlet works fine

 

My used Versions:

  • PowerShell 5.1
  • Veeam 9.5 U3a
  • VMware PowerCLI 11.0.0
  • VMware vCenter 6.5 U2

 

 

 

Might someone please try to reproduce my findings?

Has someone hit a similar problem?

 

 

Best regards,

Markus

Need help getting total vCPUs,MemoryGB,Provisionedspace(GB) per resource pool

$
0
0

I'm trying to build a report that will list total vCPUS, total provisioned Memoery GB, and total provisioned HDD drive space GB per resource pool.

 

 

 

 

Looking for something like this. I've managed to get to. It lists each resource pool and shows total vCPU's allocated, but I can't get the other fields to populate.

 

 

 

Here's the script i'm using to get this far.

foreach ($vmhost in get-resourcepool){

$vms=$vmhost|get-vm

$vmsVcpucount=($vms|Measure-Object -Property numcpu -Sum).sum

""|Select @{N='Host';E={$vmhost.name}},numcpu,MemoryGB,@{n="HardDiskSizeGB"; e={(Get-HardDisk -VM $_ | Measure-Object -Sum CapacityGB).Sum}},ResourcePool,@{N='Actual vCPU allocated';E={$vmsVcpucount}}

}

 

 

 

 

 

Any Help would be appreciated.

Hello need to dump all my hosts in what top level folder they are in then datacetner then number of vm's per host.

$
0
0

Got this far

 

Get-VMHost | Select @{N="Datacenter";E={datacenter -VMHost $_}}, Name, @{N="NumVM";E={($_ | Get-VM).Count}} | Sort datacenter, NumVM

 

but not able to get it to dump the top level folder.

 

I have VC, Folders, Datacenters, hosts then VM's

 

Thanks


Correlating ESXi snapshot name to corresponding vmdk file

$
0
0

I'm working with raw ESXi 6.7 without vCenter using PowerCLI 11.0.0. What I need to be able to do is to figure out which *-0000*.vmdk file (the text descriptor file) corresponds to a particular snapshot returned from Get-Snapshot.

 

There don't seem to be any properties of the snapshot objects that contain disk information that I can see.

 

Getting the .vmdk files in that VM's folder via the vmstore: PS drive is easy enough but it obviously doesn't tell you which snapshot a particular *0000* vmdk file belongs to.

 

Can I simply sort the snapshots on the created date and the earliest will be 000001, the next oldest 000002 and so on? I'm not sure how this approach would cope with deleted/consolidated snapshots though.

 

I was also wondering if the order of the objects returned by Get-Snapshot corresponds to the number in the vmdk name so the 1st one returned is 000001 and so on.

 

I've looked at the .vmsd file but that doesn't contain vmdk info.

 

I guess I could also work my way through the snapshots looking at the ParentSnapshot and Children to make an ordered list but there's still no guarantee of disk numbering correlation I fear.

 

ESXi must know so how does it do that - any ideas folks please?

 

The reason I need this is that I'm writing a script to clone VMs from other VMs but without vCenter so there's no built-in templating and using something like -LinkedClone to New-VM gives an unsupported error as you'd kind of expect. I can clone from base disks ok, even renaming them after copying, but I'd like to add reliable linked clones too, to save on disk space if nothing else.

try_catch_$global:defaultvisever_powercli

$
0
0

Hi Luc,

Good morning,

 

could yu check following if we can use try_catch method to check connection to vcenter .

 

 

 

Try{

 

   $conn = $global:DefaultVIServer

    $conn

 

}

Catch{

    connect-viserver -Server 'vc'

}

parameter binding exception_powercli

$
0
0

Hi Luc,

 

could yu check the following and suggest how to fix "parameter binding exception" error .

 

 

[cmdletbinding()]

param (

 

[string[]]$esxiname

 

 

 

 

 

)

foreach($esxi in $esxiname)

 

 

{

 

$vms=get-vm -Location $esxi|select name

 

 

$dsnames=Get-Datastore -RelatedObject $esxi|select name

 

 

$prop = {esxiname = $esxi.name

        model = $esxi.Model

        verison = $esxi.Version

        build = $esxi.Build

        memorysize = $esxi.MemoryTotalGB

        manufectureer = $esxi.Manufacturer}

 

 

        $obj=New-Object -TypeName psobject -Property $prop

        Write-Output $obj

 

 

        }

 

 

 

 

error message:

 

 

New-Object : Cannot bind parameter 'Property'. Cannot convert the "esxiname = $esxi.name

        model = $esxi.Model

        verison = $esxi.Version

        build = $esxi.Build

        memorysize = $esxi.MemoryTotalGB

        manufecturer = $esxi.Manufacturer" value of type "System.Management.Automation.ScriptBlock" to type

"System.Collections.IDictionary".

At C:\users\in0079d6\Desktop\Technicolor_script\toolmaking1.ps1:36 char:54

+         $obj=New-Object -TypeName psobject -Property $prop

+                                                      ~~~~~

    + CategoryInfo          : InvalidArgument: (:) [New-Object], ParameterBindingException

    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.NewObjectCommand

Script modification to ADD MAC Address against respective NICs_ vCloud Director

$
0
0

Dear Friends,

Need some help to modify\update below script to add a MAC Address Column in front of each NICs IP.

It is a simple script which connects to vCloud Director, asks for VAPP and provides details abut it like VM info, Org Networks etc etc.

Attached please find the CSV generated by the script and also sample what i am looking forward to add in it.

Below is the the script which i am using so far to update my CMDB.

===========================================================

function exportTRS{
try {
# $date = (Get-Date).ToString("s").Replace(":","-")
 
$excel = New-Object -ComObject Excel.Application
 
$excel.Visible = $false
 
$workbook = $excel.Workbooks.Add()
 
$sheet = $workbook.ActiveSheet
$sheet.Name = 'AS Built'
 
$range1 = $sheet.range("1:1")
$range1.Cells.Interior.ColorIndex =1 
$range1.Cells.font.bold = $true
$range1.Cells.Font.ColorIndex = 46
$range1.Cells.HorizontalAlignment = -4108
 
$sheet.Cells.Item(1,1) = 'OrgVDC Name'
$sheet.Cells.Item(1,2) = 'vApp Name'
$sheet.Cells.Item(1,3) = 'Server Name'
$sheet.Cells.Item(1,4) = 'eth0'
$sheet.Cells.Item(1,5) = 'eth1'
$sheet.Cells.Item(1,6) = 'eth2'
$sheet.Cells.Item(1,7) = 'vCPU'
$sheet.Cells.Item(1,8) = 'Memory'
$sheet.Cells.Item(1,9) = 'Storage'
$sheet.Cells.Item(1,10) = 'Guest OS Name'
 
 
$range3 = $sheet.range("2:2")
$range3.Cells.Interior.ColorIndex = 56
$range3.Cells.Font.ColorIndex = 2
$range3.Cells.HorizontalAlignment = -4108
 
$sheet.Cells.Item(2,4) = 'Prod'
$sheet.Cells.Item(2,5) = 'Nic2'
$sheet.Cells.Item(2,6) = 'Nic3'
 
 
$range2 = $sheet.range("50:50")
$range2.Cells.Interior.ColorIndex =1 
$range2.Cells.font.bold = $true
$range2.Cells.Font.ColorIndex = 46
$range2.Cells.HorizontalAlignment = -4108
$sheet.Cells.Item(50,1) = 'OrgVDCs networks connected'
$sheet.Cells.Item(50,2) = 'Gateway'
$sheet.Cells.Item(50,3) = 'Subnet Mask'
 
 
#$column = 1
$row = 3
$nume_VAPP = read-host "Please Enter the Name of the VAPP"
write-host "Getting vApp Properties for $nume_VAPP"
$vapp = Get-CIVApp -Name $nume_VAPP
$orgtemp = $vapp.Org.Name
$name = $nume_VAPP
 
$date = (Get-Date).ToString("d")
 
write-host "Searching for organization $orgtemp"
$Org = Search-Cloud -QueryType Organization -Name "$orgtemp";
write-host "Searching for organization VDC with $($Org.id)"
$aOvdcs = Search-Cloud -QueryType AdminOrgVdc -Filter "org==$($Org.id)";
$aVApps = Search-Cloud -QueryType AdminVApp -Filter "Name==$name";
$VappOrgID = $aVApps.PropertyList.Vdc
$OrgName = Get-OrgVDC -ID $VappOrgID
 
Write-host "Getting VM information"
$vms = Get-CIVM -VApp $nume_VAPP
#$vms = search-cloud -querytype Adminvm -Filter "container==$($vapp.id)"
 
foreach ($vm in $vms ){
$hardware = $vm.ExtensionData.GetVirtualHardwareSection()
$diskMB = (($hardware.Item | where {$_.resourcetype.value -eq "17"}) | %{$_.hostresource[0].anyattr[0]."#text"} | 
 
Measure-Object -Sum).sum
$diskGB = ($diskMB/1024)
$column = 1
$adapters = Get-CINetworkAdapter -VM $vm
$sortadapters = $adapters | Sort-Object
$sheet.cells.Item($row,$column) = $OrgName.Name
$column++
$sheet.cells.Item($row,$column) = $vm.VApp.Name
$column++
$sheet.cells.Item($row,$column) = $vm.Name
$column++
$sheet.cells.Item($row,$column) = $sortadapters[0].IPAddress.IPAddressToString
$column++
$sheet.cells.Item($row,$column) = $sortadapters[1].IPAddress.IPAddressToString
$column++
        $sheet.cells.Item($row,$column) = $sortadapters[2].IPAddress.IPAddressToString
$column++
$sheet.cells.Item($row,$column) = $vm.CpuCount
$column++
$sheet.cells.Item($row,$column) = $vm.memoryGB
$column++
$sheet.cells.Item($row,$column) = $diskGB
$column++
$sheet.cells.Item($row,$column) = $vm.GuestOSFullName
$row++
}
 
 
$net = Get-CIVAppNetwork -VApp $nume_VAPP
$row = 51
$column = 1
$sheet.cells.Item($row,$column) = $net[0].Name
$column++
$sheet.cells.Item($row,$column) = $net[0].Gateway.IPAddressToString
$column++
$sheet.cells.Item($row,$column) = $net[0].Netmask.IPAddressToString
$column = 1
$row++
$sheet.cells.Item($row,$column) = $net[1].Name
$column++
$sheet.cells.Item($row,$column) = $net[1].Gateway.IPAddressToString
$column++
$sheet.cells.Item($row,$column) = $net[1].Netmask.IPAddressToString
$column = 1
$row++
$sheet.cells.Item($row,$column) = $net[2].Name
$column++
$sheet.cells.Item($row,$column) = $net[2].Gateway.IPAddressToString
$column++
$sheet.cells.Item($row,$column) = $net[2].Netmask.IPAddressToString
$column = 1
 
$objRange = $sheet.UsedRange
[void] $objRange.EntireColumn.Autofit()
 
$filename = "C:\Work\ASB_$name.xlsx"
$workbook.SaveAs($filename)
$excel.Quit()
}
catch {
  Write-Warning $_.Exception.Message
}
}
connect-ciserver XXXXXXXX -User XXXXXXX -Password XXXXXXXX
exportTRS
function exportTRS{
try {
# $date = (Get-Date).ToString("s").Replace(":","-")
 
$excel = New-Object -ComObject Excel.Application
 
$excel.Visible = $false
 
$workbook = $excel.Workbooks.Add()
 
$sheet = $workbook.ActiveSheet
$sheet.Name = 'AS Built'
 
$range1 = $sheet.range("1:1")
$range1.Cells.Interior.ColorIndex =1 
$range1.Cells.font.bold = $true
$range1.Cells.Font.ColorIndex = 46
$range1.Cells.HorizontalAlignment = -4108
 
$sheet.Cells.Item(1,1) = 'OrgVDC Name'
$sheet.Cells.Item(1,2) = 'vApp Name'
$sheet.Cells.Item(1,3) = 'Server Name'
$sheet.Cells.Item(1,4) = 'eth0'
$sheet.Cells.Item(1,5) = 'eth1'
$sheet.Cells.Item(1,6) = 'eth2'
$sheet.Cells.Item(1,7) = 'vCPU'
$sheet.Cells.Item(1,8) = 'Memory'
$sheet.Cells.Item(1,9) = 'Storage'
$sheet.Cells.Item(1,10) = 'Guest OS Name'
 
 
$range3 = $sheet.range("2:2")
$range3.Cells.Interior.ColorIndex = 56
$range3.Cells.Font.ColorIndex = 2
$range3.Cells.HorizontalAlignment = -4108
 
$sheet.Cells.Item(2,4) = 'Prod'
$sheet.Cells.Item(2,5) = 'Nic2'
$sheet.Cells.Item(2,6) = 'Nic3'
 
 
$range2 = $sheet.range("50:50")
$range2.Cells.Interior.ColorIndex =1 
$range2.Cells.font.bold = $true
$range2.Cells.Font.ColorIndex = 46
$range2.Cells.HorizontalAlignment = -4108
$sheet.Cells.Item(50,1) = 'OrgVDCs networks connected'
$sheet.Cells.Item(50,2) = 'Gateway'
$sheet.Cells.Item(50,3) = 'Subnet Mask'
 
 
#$column = 1
$row = 3
$nume_VAPP = read-host "Please Enter the Name of the VAPP"
write-host "Getting vApp Properties for $nume_VAPP"
$vapp = Get-CIVApp -Name $nume_VAPP
$orgtemp = $vapp.Org.Name
$name = $nume_VAPP
 
$date = (Get-Date).ToString("d")
 
write-host "Searching for organization $orgtemp"
$Org = Search-Cloud -QueryType Organization -Name "$orgtemp";
write-host "Searching for organization VDC with $($Org.id)"
$aOvdcs = Search-Cloud -QueryType AdminOrgVdc -Filter "org==$($Org.id)";
$aVApps = Search-Cloud -QueryType AdminVApp -Filter "Name==$name";
$VappOrgID = $aVApps.PropertyList.Vdc
$OrgName = Get-OrgVDC -ID $VappOrgID
 
Write-host "Getting VM information"
$vms = Get-CIVM -VApp $nume_VAPP
#$vms = search-cloud -querytype Adminvm -Filter "container==$($vapp.id)"
 
foreach ($vm in $vms ){
$hardware = $vm.ExtensionData.GetVirtualHardwareSection()
$diskMB = (($hardware.Item | where {$_.resourcetype.value -eq "17"}) | %{$_.hostresource[0].anyattr[0]."#text"} | 
 
Measure-Object -Sum).sum
$diskGB = ($diskMB/1024)
$column = 1
$adapters = Get-CINetworkAdapter -VM $vm
$sortadapters = $adapters | Sort-Object
$sheet.cells.Item($row,$column) = $OrgName.Name
$column++
$sheet.cells.Item($row,$column) = $vm.VApp.Name
$column++
$sheet.cells.Item($row,$column) = $vm.Name
$column++
$sheet.cells.Item($row,$column) = $sortadapters[0].IPAddress.IPAddressToString
$column++
$sheet.cells.Item($row,$column) = $sortadapters[1].IPAddress.IPAddressToString
$column++
        $sheet.cells.Item($row,$column) = $sortadapters[2].IPAddress.IPAddressToString
$column++
$sheet.cells.Item($row,$column) = $vm.CpuCount
$column++
$sheet.cells.Item($row,$column) = $vm.memoryGB
$column++
$sheet.cells.Item($row,$column) = $diskGB
$column++
$sheet.cells.Item($row,$column) = $vm.GuestOSFullName
$row++
}
 
 
$net = Get-CIVAppNetwork -VApp $nume_VAPP
$row = 51
$column = 1
$sheet.cells.Item($row,$column) = $net[0].Name
$column++
$sheet.cells.Item($row,$column) = $net[0].Gateway.IPAddressToString
$column++
$sheet.cells.Item($row,$column) = $net[0].Netmask.IPAddressToString
$column = 1
$row++
$sheet.cells.Item($row,$column) = $net[1].Name
$column++
$sheet.cells.Item($row,$column) = $net[1].Gateway.IPAddressToString
$column++
$sheet.cells.Item($row,$column) = $net[1].Netmask.IPAddressToString
$column = 1
$row++
$sheet.cells.Item($row,$column) = $net[2].Name
$column++
$sheet.cells.Item($row,$column) = $net[2].Gateway.IPAddressToString
$column++
$sheet.cells.Item($row,$column) = $net[2].Netmask.IPAddressToString
$column = 1
 
$objRange = $sheet.UsedRange
[void] $objRange.EntireColumn.Autofit()
 
$filename = "C:\Work\ASB_$name.xlsx"
$workbook.SaveAs($filename)
$excel.Quit()
}
catch {
  Write-Warning $_.Exception.Message
}
}
connect-ciserver XXXXXXXX -User XXXXXXX -Password XXXXXXXX
exportTRS

Change Boot Sequence with new Extensiondata option

$
0
0

Hello PowerCLI masters,

 

I'm attempting to change the boot order for a VM (or a bunch of VMs) with the new Extensiondata.Config.Bootoptions.  Easy enough to edit these values but i'm having some issues determining what the values shoudl be.  I've tried some of the values we used to use and it's failing to take the change.

 

$vm.Extensiondata.Config.Bootoptions.BootOrder = "Ethernet0"

$vm.Extensiondata.Config.Bootoptions.BootOrder = "Ethernet0,ide0:0"

etc.

 

Can someone provide some guidance on how to make the appropriate changes?

 

Thanks!

 

Brent

Viewing all 9071 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>