Posts

Showing posts with the label scripts

Migrating VMs to a Standard Switch

One of my customers has asked me to help them migrate from one vCenter server to another.  In order to do this without causing interruptions, we're using ESXi servers like boats to bring the VMs from the old environment into the new one; basically the same process that I used last time a customer asked me to do this. This time, we're completing this process at many different sites and each site has many VMs that need to traverse the vCenter servers.  Since this customer doesn't yet have vSphere 6 with its inter-vCenter vMotion capability, we're left doing it the hard way.  That means doing an arduous, detail oriented, highly repetitive task... or, writing a script to do it for me. The worst part of this process comes from the VM networking.  We have to create Standard vSwitches on each ESXi host with VLAN configurations that mirror the Distributed vSwitch that belongs in the vCenter, then move all of the VMs to the appropriate Port Groups on the newly create...

Running PowerShell Scripts from Windows Task Scheduler

Sometimes, we write scripts that we want to schedule.  For example, I recently put together a small script that checks an environment for Snapshots that are older than 7 days and then emails the sys admins a report if it finds any.  Alan Renouf put together a quick guide on how to run PowerShell scripts with Windows Task Scheduler back in 2009, but I ran into a hiccup while trying to use that procedure the other day. Alan suggests two possible methods for accomplishing this task.  One involves editing your scripts to add the required PS Snapins and the other involves launching the PowerShell session from a pre-configured Console File.  I decided that I’d had enough of messing around with Add-PSSnapin, so I decided to experiment with the PowerShell Console option.  The example syntax that he provides is basically: Powershell.exe –PSConsoleFile myConsole.psc1 & myScript.ps1 Which didn’t exactly work for me.  When I executed this at a command li...

vSphere Environment Analysis

vSphere Infrastructure analysis is important, so I wrote this script to help me to easily get a quick understanding of a given environment.  This grew out of the CPU Ready script that I wrote several months ago, in addition to CPU Ready detection, it can check for Memory problems as well as report the maximum CPU Usage and Active Memory for every VM in an environment. Usage:  vm-analyze.ps1 -Stat <metric to examine> -VM <VM to examine> -Days <# of days to examine> -Threshold <Threshold % as an integer above which to report CPU Ready> The script accepts the following for the Stat option: cpuReady memProblem cpuMax memMax The -VM option is optional - if it is included (as the name of a VM), the script will perform its work on that specific VM, otherwise it will analyze all VMs in the inventory.  The -Days option specifies how far back to analyze; it defaults to 6 days if not specified.  This can be important to play around with, as ...