Tag: Scripts

Script to upgrade vm hardware for list of VM

hello guys..

Here is the script to update the vm hardware for list of VM’s

$vms=Get-Content C:\Temp\servers.txt
foreach($MyVM in $vms){
Write-Host "========Before Upgrading===================" -ForegroundColor Yellow
$MyVM = Get-VM -Name vm10
Write-Host $MyVM.Name $MyVM.Version -ForegroundColor White
if ($MyVM.PowerState -eq "PoweredOn") {
 Write-Host "Shutting Down" $MyVM
 Stop-VMGuest -VM $MyVM -Confirm:$false
 do {
 Start-Sleep -s 5
 $MyVMStat = Get-VM -Name $MyVM
 $status = $MyVMStat.PowerState
 }until($status -eq "PoweredOff")
 $snapTask=New-Snapshot -VM $MyVM -Name HardwareUpgrade -RunAsync
 Wait-Task $snapTask
 $snapState= Get-Task -Id $snaptask.Id |Select State,VM
 if($snapState.State -eq "Success"){
 Write-Host $MyVM "Snapshot is created and proceeding for Hardware Upgrade"
 #Get-Snapshot -VM $MyVM|Select Name,Created
 $vmversiontask=Set-VM -VM $MyVM -Version v10 -Confirm:$false -RunAsync
 $wtask=Wait-Task $vmversiontask 
 write-host $wtask.Id,$vmversiontask.Id
 $state=Get-Task |Select-Object * |where{($_.ObjectId -eq $wtask.Id) -and ($_.Name -eq "UpgradeVM_Task")}

Write-Host "================After the hardware Upgrade===========" -ForegroundColor Yellow
Write-Host $MyVM.Name $MyVM.Version -ForegroundColor White

How to clear WINS from Network Adapter Configuration with Powershell

Hello Guys…!!!

Here is the simple script to clear the WINS entry from multiple servers with powershell script.

$servers=gc C:\ServerList.txt
foreach($server in $servers){
$adapters=Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=TRUE -ComputerName $server
foreach($adapter in $adapters){
Write-Host "=======Before Making the WINS NULL=========" -ForegroundColor White
Write-Host $adapter.Description,$adapter.WINSPrimaryServer,$adapter.WINSSecondaryServer

Script to Get Datastore Path Information

Hello guys…!!!

Here is script developed to get the No Of Paths per DS and Type of path selection policy and to which VMHBA it is connected.

PowerShell Scrip:

Connect-VIServer -Server servername -User username -password password
#Get list of ESXi Hosts
$esxihosts=gc C:\hosts.txt
For($i = 1; $i -le $esxihosts.count; $i++)
ForEach ($esxihost in $esxihosts) {
 $esxi = Get-VMHost -Name $esxihost
 $hbas = $esxi | Get-VMH

 ForEach ($hba in $hbas) {
 $scsiluns = $hba | Get-ScsiLun
 ForEach ($scsilun in $scsiluns) { 
 $exportDSPaths=New-Object PSObject
 $scsipaths =$scsilun | Get-Scsilunpath |Select-Object *
 $DS=Get-Datastore |Get-View |Where-Object {$_.Info.vmfs.Extent.DiskName -eq $LunNaaID}
 #Write-Host $DS.Name,$LunNaaID,$LunPathPolicy,$PathCount,$hba.Name,$esxi.Name
 $exportDSPaths|Add-Member -MemberType NoteProperty -Name "EsxiHost" -Value $esxi.Name
 $exportDSPaths|Add-Member -MemberType NoteProperty -Name "DatastoreName" -Value $DS.Name
 $exportDSPaths|Add-Member -MemberType NoteProperty -Name "LunNAAID" -Value $LunNaaID
 $exportDSPaths|Add-Member -MemberType NoteProperty -Name "MultipathPolicy" -Value $LunPathPolicy
 $exportDSPaths|Add-Member -MemberType NoteProperty -Name "LunPathCount" -Value $PathCount
 $exportDSPaths|Add-Member -MemberType NoteProperty -Name "VmHBA Connected" -Value $hba.Name
 Write-Progress -Activity “Now Scaning $datastore in $hba on $esxi” -status “Found $countofESXi esxi hosts and working on $esxi” -PercentComplete ($i / $esxihosts.count*100)
$expotDSPathCount| Export-Csv -NoTypeInformation 'DSPathCountInformation.csv'

Sample Out PutDSPathInfo

Script to Get the Path Count of VMHBA

Hello guys…

Here is the script  to get the Number of Paths for each and every VMHBA in esxi and the out put will be saved in CSV Files…Thanks to Lucd…


Connect-VIServer -Server vcenterservername -User vcenterusername -password vcenterpassword
$esxs=gc C:\Users\TIRU\hosts.txt
foreach($esxi in $esxs){
$esx = Get-VMHost -Name $esxi
foreach($hba in (Get-VMHostHba -VMHost $esx ))
$target = ($hba.VMhost.ExtensionData.Config.StorageDevice.ScsiTopology.Adapter | where {$_.Adapter -eq $hba.Key}).Target
$luns = Get-ScsiLun -Hba $hba 
$nrPaths = ($target | %{$_.Lun.Count} | Measure-Object -Sum).Sum
$exportObject=New-Object PSObject 
$exportObject |Add-Member -MemberType NoteProperty -Name "HostName" -Value $esx
$exportObject |Add-Member -MemberType NoteProperty -Name "HBAName" -Value $hba.Device
$exportObject |Add-Member -MemberType NoteProperty -Name "NumberOfPaths" -Value $nrPaths
$exportData| Export-Csv -NoTypeInformation 'ESXiStoragePathInformation.csv' 

Sample Output:

SampleOutput Of Script