Backtrack:  
 
showing posts tagged with 'powercli'
 
edited by on October 14th 2022, at 14:41
In order to install a fresh copy of Windows Server on a VM with the VMWare Paravirtual SCSI controller, as the driver for the PVSCSI adapter is not included in the default Windows Server ISO, you would use the built-in floppy images to make the PVSCSI driver available during the installation, avoiding the need to install using a different SCSI controller and then swap the controller after the installation of the guest OS and VMWare Tools.

To facilitate this, you would add a virtual floppy drive, connect the correct floppy image containing the PVSCSI driver, and then load the driver during the disk selection portion of the installation wizard. Unfortunately, since the deprecation of the Flas  ...
edited by on March 18th 2021, at 12:36

With PowerCLI it is very easy to get a list of provisioned storage for a list of VMs:

Get-VM | Select-Object Name,@{n="ProvisionedGB"; e={(Get-HardDisk -VM $_ | Measure-Object -Sum CapacityGB).Sum}}

You can combine this with other cmdlets to limit the search to a specific folder, datastore, etc...

To get a complete sum of all the VMs, add | Measure-Object -Sum ProvisionedGB at the end.

edited by on February 18th 2021, at 17:35
Offline installation of PowerCLI module is possible by following these easy steps:Uninstall all older PowerCLI software (6.5R1 or earlier).

Download the PowerCLI offline bundle (ZIP-file) from the PowerCLI home page.

Transfer the ZIP to the machine on which PowerCLI is to be installed.

Open Powershell on the target machine.

To determine the modules folder paths, run this:$env:PSModulePath

The modules will have to be extracted in one of the folders from the output of the above command. Both user-based and machine-based installation is possible (e.g. C:\Windows\System32\WindowsPowerShell\v1.0\Modules).

Extract the contents of the ZIP file directly into the folder.

For Windows, run this   ...
edited by on November 4th 2020, at 09:57
Using PowerCLI, you can easily retrieve the status of CPU/Memory hot-add/remove. After logging in (use Connect-ViServer), run this cmdlet:

(Get-VM | Select ExtensionData).ExtensionData.config | FT -Auto Name, MemoryHotAddEnabled,CpuHotAddEnabled,CpuHotRemoveEnabled

If you only want a list of VMs which have hot-add/remove enabled for either CPU or memory, you can use filters to filter on this:

(Get-VM | Select ExtensionData).ExtensionData.config | ? {$_.MemoryHotAddEnabled -eq $true -or $_.CpuHotAddEnabled -eq $true -or $_.CpuHotRemoveEnabled -eq $true} | Select Name, MemoryHotAddEnabled,CpuHotAddEnabled,CpuHotRemoveEnabled | FT -Auto

To export the result to CSV, replace the FT -Auto in t  ...
edited by on May 14th 2020, at 12:20
You can force-trigger storage DRS recommendations (and possible subsequent storage vMotions) through PowerCLI.

Run the snippet below, replacing the value of $dscName to match the name of the datastore cluster you wish to trigger the DRS recommendation on:

$dscName = 'DatastoreCluster1'$dsc = Get-View -ViewType StoragePod -Filter @{'Name'=$dscName}$si = Get-View ServiceInstance$storMgr = Get-View -Id $si.Content.StorageResourceManager$storMgr.RefreshStorageDrsRecommendation($dsc.MoRef)$dsc.UpdateViewData()if($dsc.PodStorageDrsEntry.Recommendation){ $dsc.PodStorageDrsEntry.Recommendation | %{ $storMgr.ApplyStorageDrsRecommendationToPod_Task($dsc.MoRef,$_.Key) }}

  ...
edited by on May 14th 2020, at 12:17

If the webclient is letting you down, you can also use PowerCLI to expand datastores.

First, as usual, expand the volume on the storage level. Then, fire up PowerCLI, log on to the vCenter/host and run the following script, replacing the name of the datastore you wish to expand:

$name = 'Datastore1'
$datastore = Get-Datastore $name
$esxi = Get-View -Id ($Datastore.ExtensionData.Host | Select -Last 1 | Select -ExpandProperty Key) 
$datastoreSystem = Get-View -Id $esxi.ConfigManager.DatastoreSystem
$expandOptions = $datastoreSystem.QueryVmfsDatastoreExpandOptions($datastore.ExtensionData.MoRef)
$datastoreSystem.ExpandVmfsDatastore($datastore.ExtensionData.MoRef,$expandOptions.spec)
edited by on September 9th 2019, at 12:45
Handling snapshots (creating, deleting, restoring) is rather intuitive when you already have some experience with PowerCLI. As a reference, here are some one-liners. As always with Powershell, there's more than one way to achieve a goal... The examples used here assume a VM named "SRV01". Adjust as needed.

Create a snapshot:

Get-VM SRV01 | New-Snapshot -Name "My snapshot"

Remove all snapshots (disabling confirmation request in the process):

Get-VM SRV01 | Get-Snapshot | Remove-Snapshot -Confirm:$false

To handle a specific snapshot, you could do something like this:

$vm = Get-VM SRV01$snap = Get-Snapshot -VM $vm -Name "My snapshot"# do something with the sn  ...
edited by on December 20th 2018, at 11:17
Starting or stopping the SSH service on multiple ESXi hosts can be a tedious job when having to do this via the vSphere (Web)Client. Fortunately, you can also use PowerCLI to start/stop services quickly. With a little scripting, you can expand this to start/stop services on a set of hosts, a cluster, or the entire vCenter.

First, start PowerCLI and make a connection to the vCenter. For automation, you can use something like this (note that you have to add code for credentials, if needed):

if (-not (Get-PSSnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue)) { Add-PSSnapin VMware.VimAutomation.Core | Out-Null }Connect-VIServer vcenter.domain.local

Once that's done, you can ga  ...
edited by on September 27th 2018, at 11:38
It is best practice not to have an ISO mounted on a VM if it is not necessary. This is especially the case with VDI: if you forget to set the optical drive back to client, each of your desktops will have the ISO mounted as well, which can create a hassle with dependencies on the datastore where the ISO is located.

With PowerCLI, you can quickly resolve the matter with this one-liner:

Get-VM | Get-CDDrive | Where {$_.ISOPath -ne $null} | Set-CDDrive -NoMedia -Confirm:$false

For VDI, note that this will not work for replicas and master images containing snapshots, as the dependency remains intact if a snapshot exists where the ISO was still mounted. In that case, it is better to clone the m  ...
edited by on December 14th 2017, at 14:03

Sometimes, you need to temporarily start a service (such as SSH) to perform some maintenance task. PowerCLI can help you with this:

To start the SSH server on each host of a vCenter:

Get-VMHost | Get-VMHostService | ? {$_.Key -eq "TSM-SSH"} | Start-VMHostService

To stop the SSH server:

Get-VMHost | Get-VMHostService | ? {$_.Key -eq "TSM-SSH"} | Stop-VMHostService -Confirm:$false

As always, you can make adjustments to the oneliner to select another service to start/stop, or further limit the selection of hosts to a cluster or a group of hosts (e.g. filtered by name).

edited by on December 14th 2017, at 14:00
If you're making changes to the datastore, setting up a new cluster and have a lot of hosts, and wish to set up system logging, you can do so very quickly using PowerCLI.

First, add all the hosts to the vCenter like you normally would. Then, connect to the vCenter server and run this cmdlet:

Get-VMHost | % { $vm = $_ $vm | Get-AdvancedSetting "Syslog.global.logDirUnique" | Set-AdvancedSetting -Value "True" -Confirm:$false $vm | Get-AdvancedSetting "Syslog.global.logDir" | Set-AdvancedSetting -Value "[DataStore01] ESXiLogs" -Confirm:$false}

The cmdlet above will set the system log location to a folder on DataStore01 and enables unique log di  ...
edited by on December 12th 2017, at 12:35
When performing large storage migrations, it may be useful to get a list of VMs and the datastore and/or folder they are located in. PowerCLI can provide this very quickly:

Get-VM | Select Name,@{N="Datastore";E={[string]::Join(',',(Get-Datastore -Id $_.DatastoreIdList | Select -ExpandProperty Name))}},@{N="Folder";E={$_.Folder.Name}}

You can further pipe this to other cmdlets (such as Where-Object to filter even more), or export it to a CSV.

You can also go into more detail and determine the location of each virtual disk (VMDK) of each VM:

Get-VM | Get-View | % { $name = $_.Name $_.Layout.Disk | % { New-Object PSObject -Property @{ Nam  ...
edited by on May 8th 2017, at 14:32
A very common practice when setting up SAN storage on a VMWare cluster is to configure the storage path policy to be set to "Round Robin" to properly benefit from MPIO in addition to standard failover. However, if the cluster consists of many nodes or there are many volumes, this can take up quite a lot of time if you configure this using the (Web)GUI. A better way to adjust the setting for the entire cluster is through PowerCLI.

The one-liner:

Get-VMHost <Cluster-or-Host> | Get-ScsiLun -LunType "disk" | Where {$_.MultipathPolicy -ne "RoundRobin"} | Set-ScsiLun -MultipathPolicy RoundRobin

The cmdlet selects a cluster or host, gets all LUNs which are of   ...
edited by on April 11th 2017, at 14:03

I wrote a script to list virtual disk information for a specified VM, including VMDK path, SCSI IDs and more. It is loosely based on this script but excludes all WMI info.

Download here.

edited by on January 19th 2017, at 16:49

With PowerCLI, you can generate all sorts of lists. To retrieve the configured and reported OS version of your VMs, try running this one-liner:

Get-VM | Sort | 
   Get-View -Property @("Name", "Config.GuestFullName", "Guest.GuestFullName", "Guest.IpAddress") | 
   Select -Property Name, 
       @{N="Configured OS";E={$_.Config.GuestFullName}},
       @{N="Running OS";E={$_.Guest.GuestFullName}},
       @{N="IP Address";E={@($_.Guest.IpAddress)}} | 
   Export-CSV -Delimiter ";" -Path "vms.csv"
edited by on December 5th 2015, at 13:19

You can quickly get a list of VMs, the datastores they are using and the logical folder they are in through PowerCLI:

Get-VM | Select Name,@{N="Datastore";E={[string]::Join(',',(Get-Datastore -Id $_.DatastoreIdList | Select -ExpandProperty Name))}},@{N="Folder";E={$_.Folder.Name}}

Combine it with Export-CSV to export the results to a CSV file.

by on January 1st 1970, at 01:00

Occassionally, it may be necessary to perform disk consolidation. If you have a lot of VMs which need consolidation, it can be tedious to do this in the webclient. Fortunately, it's also possible to mass-consolidate via PowerCLI.

Install and log in using PowerCLI.

To show which VM's need consolidation, run:

Get-VM | ? {$_.Extensiondata.Runtime.ConsolidationNeeded}

To actually perform disk consolidation, run:

Get-VM | ? {$_.Extensiondata.Runtime.ConsolidationNeeded} | % {$_.ExtensionData.ConsolidateVMDisks_Task()}
by on January 1st 1970, at 01:00
In VMware, using VMFS-6 as the datastore filesystem introduces automatic storage reclamation. This process, also called "VMFS unmap" runs in the background (by default at low priority so it doesn't interfere with performance) to clear allocated unused storage space by sending "unmap" commands to the underlying storage so it can reclaim the blocks for other uses.

Sometimes it may become necessary to (temporarily) turn off (or on, if it's turned off already) storage reclamation on a datastore. You can do this through the WebClient but if you want to change this for a bunch of datastores, you can also do this via PowerCLI. While the latter is pretty complicated, William Lam  ...
 
showing posts tagged with 'powercli'
 
 
« March 2024»
SunMonTueWedThuFriSat
     12
3456789
10111213141516
17181920212223
24252627282930
31      
 
Links
 
Quote
« Debating Windows vs. Linux vs. Mac is pointless: they all have their merits and flaws, and it ultimately comes to down to personal preference. »
Me