Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@sandeep-sr
sandeep-sr / powercli_poweroff_multiple_vms.ps1
Created June 3, 2021 15:27
powercli - Stop or power-off multiple VM’s
Get-Module -ListAvailable *vm*|Import-Module
$cred=Get-Credential
Connect-VIServer vcenter01 -Credential $cred
$deletevmlist=Get-Content C:\temp\stopvms.txt
foreach($vm in $deletevmlist)
{
$vmstate=get-vm $vm
if($vmstate.PowerState -eq "PoweredOn")
{
write-output ("$vm is powered-on hence stopping it")
@sandeep-sr
sandeep-sr / powercli_reboot_multiple_vms.ps1
Created June 3, 2021 15:26
powercli - Reboot multiple VM’s in a cluster
Get-Module -ListAvailable *vm*|Import-Module
$cred=Get-Credential
connect-viserver vcenter01 -Credential $cred
$vmlist=Get-Content C:\temp\rebootvms.txt
foreach ($vm in $vmlist)
{
get-cluster cluster02|get-vm $vm | Restart-VM -Confirm:$false
start-Sleep 2
Write-Output "$vm has been rebooted"
}
@sandeep-sr
sandeep-sr / powercli_vm_esxists.ps1
Created June 3, 2021 15:24
powercli - VM exists in a specific cluster
Get-Module -ListAvailable *vm*|Import-Module
$cred=Get-Credential
Connect-VIServer vcenter01 -Credential $cred
$vms=Get-Content C:\temp\vmcheck.txt
foreach($vm in $vms)
{
$exsists=Get-Cluster cluster02|get-vm $vm -ErrorAction SilentlyContinue
if($exsists){
Write-Output "$vm exist" }
else{
@sandeep-sr
sandeep-sr / network_adapter_change_multipe_vms.ps1
Created June 3, 2021 15:20
powercli - changing the network adapter for multiple VM's in a cluster
<#
.Author
Sandeep S R
.Synopsis
A simple script to Change the network adapter of a VM
.Note
- Copy the vm names into a text file named "servers" and place it into C:\temp before executing the script
- in $cl , provide the cluster name Ex : "cluster-25"
@sandeep-sr
sandeep-sr / VSAN_Disk_Health_Check.ps1
Last active June 3, 2021 15:16
Using powercli , we can check whether a disk in error state in VSAN cluster
<#
. Synopsis
VSAN Health check.
Health checks get the SSD & NonSsd's failed information and Uuid of failed disk
When a Disk failed it will be shown as NonSSD disk error
#>
Get-Module -ListAvailable VM* | Import-Module
$cred=Get-Credential
Connect-VIServer vcenter -Credential $cred -ErrorAction stop
@sandeep-sr
sandeep-sr / enbalingssh.ps1
Created June 3, 2021 13:37
Powercli - Enabling ssh to Esxi host and run esxcli commands using powercli
<#
.Synopsis
Enabling SSH & Execute esxcli commands
.Description
By using this script we can check the SSH service status and if ssh service is stopped we will start it
As well how to execute the esxcli commands
#>
Get-Module -ListAvailable *vm*|Import-Module