Skip to content

Instantly share code, notes, and snippets.

@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
@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 / 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 / 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 / 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_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_delete_multiple_vms.ps1
Created June 3, 2021 15:29
powercli - Delete multiple VM’s
Get-Module -ListAvailable *vm*|Import-Module
$cred=Get-Credential
Connect-VIServer vcenter02 -Credential $cred
$deletevmlist=Get-Content C:\temp\delete.txt
foreach($deletevm in $deletevmlist)
{
write-output ("$deletevm is deleting...")
get-cluster cluster02|get-vm $deletevm |Remove-VM -DeletePermanently -Confirm:$false -RunAsync| out-null
Start-Sleep 10
}
@sandeep-sr
sandeep-sr / powershell_SCCM_client_status_version.ps1
Created June 3, 2021 15:36
powershell - script to check SCCM client status,version & sitecode
<#
.Synopsis
This script will check SCCM client status,version & sitecode.
If the site code is not cloudwiki1 it will assign/change to cloudwiki1
#>
Start-Transcript c:\temp\versionlog.txt
$r="Running"
@sandeep-sr
sandeep-sr / powershell_sccm_server_status.ps1
Created June 3, 2021 15:38
powershell - SCCM Check for Server online/offline, Servers presents in AD or not, Service status, Site Code and SCCM client installed or not
$r="Running"
$servers=get-content "C:\temp\SCCM\servers.txt"
$Name = "SCCM_Serv.html"
$report = "C:\temp\SCCM\" + $Name
$header = "
<html>
<head>
@sandeep-sr
sandeep-sr / powershell_clear_temp_files.ps1
Last active June 3, 2021 15:46
powershell - useful script to clear temporary files before start patching the windows servers to make some space
#This script can be used to to clear un used space of C:\ in windows servers
#once the task is completed it will send a mail to the added in $msg.To.Add
#please update your own smtp server address
#enter the servers suppose to release un-used space in 123.txt file (ex--c:\temp\123.txt)
#Create a folder named Cleanupreports in C:\temp
#Script assumes delprof is already installd in all the servers
$Path = "C:\temp\Cleanupreports\"