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

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


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

diffent_observation_webclient_powercli

$
0
0

Hi Luc,

 

i see two different values of datastore free space when viewed from webclient and powercli.

 

 

 

 

 

and drom web client

 

 

 

 

its showing inactive in webclient as space is full .while powercli showing diferent result.

 

 

could you suggest anything on above.

Change portgroup of VMs with specific IP adress

$
0
0

Hi,

 

I'm moving ESX servers from one vCenter to another.

VMs that have been migrated to my new vCenter/DVswitch don't have a correct PG configured.

 

My setup:

 

PG10 = 192.168.10.0/24

PG11 = 192.168.11.0/24

PG12 = 192.168.12.0/24

Etc...

 

Found this script somewhere which solves my problem per vlan

 

$sourceVMhost = "esx03"

$VMnameFilter = "*"

$IPFilter = "192.168.10.*"

$logfolder = "c:\MigrationLogs"

 

$getvms = Get-VMhost $sourceVMhost | Get-VM | where name -Like $VMnameFilter | Select Name, @{ L = "IP Address"; E = { ($_.guest.IPAddress[0]) } } | where "IP Address" -Like $IPFilter | select -ExpandProperty name

 

foreach ($vm in $getvms)

{

$NEWDPG = Get-VDSwitch -Name dvSwitch-prod | Get-VDPortgroup -Name 'PG10'

get-vm $vm | Get-NetworkAdapter | Set-NetworkAdapter -NetworkName $NEWDPG -Confirm:$false

 

If (!$error)

{ Write-Output $vm, $error[0] | out-file -append -filepath "$logfolder\success.log" }

Else

{ Write-Output $vm, $error[0] | out-file -append -filepath "$logfolder\failed.log" }

 

Above script works fine but I have to run it many times and change the $IPFilter and $NEWDPG.   (My VMs are spread out on vlan10-20)

 

Possible to use some kind of If statement to accomplish this task in one single script?

 

Regards

Tyler

param block_powercli

$
0
0

[cmdletbinding()]

param (

[string[]]$esxiname

)

 

There are many times we define valuefrompipeline = $true in param block.

is this to make commands (start accepting values from pipeline)which natively don’t accept pipeline ?

could you suggest some simple power cli code where it works.

 

 

 

 

Vmware Horizon Get vms and users logon time

$
0
0

Hi VM guru's!

Hi LUCD!

 

We have 350 vms in Horizon View Farm!

Now i need a script that will show the name of the VM. user, and the last time logon on this VM.

We need to find machines that are no longer used by users.

Any ideas ?

Viewing all 14549 articles
Browse latest View live


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