Enable SSH on VMhost with PowerCLI

How to Enable SSH for VMhost with PowerCli

To enable SSH:

Get-VMHost <HostName> | Get-VMHostService | Where Key -EQ "TSM-SSH" | Start-VMhostService

Enable SSH via PowerCli

To disable SSH:

Get-VMHost <HostName> | Get-VMHostService | Where Key -EQ "TSM-SSH" | Stop-VMHostService -Confirm:$False

Disable SSH via PowerCli

– Stuart… Continue reading

PowerShell to gather Lenovo Warranty information

Lenovo Warranty Information Lookup

To continue with the theme of my last post, I’m going to show how to gather the warranty information for Lenovo Servers.  This was a bit tricky as this isn’t an API call, but more of a website parsing.

Getting the Lenovo Server information

To be able to perform this warranty lookup, the server information will need to be retrieved, and what a better way than getting it from the VMhosts themselves.… Continue reading

PowerCli to Increase Hardware on Multiple VMs

The other night I had a task of upgrading 22 VMs with additional vCPUs and memory.  I also had a maintenance window of 60 minutes to get this completed.  So I wasn’t going to do this more than once, so I just wrote a simple PowerCli script that would handle this process for me.

$servers = "VMServer01","VMServer02","VMServer03","VMServer04","VMServer05"

foreach ($server in $servers){
Shutdown-VMGuest $server -confirm:$false
Do {
sleep -Seconds 5
$Status = (Get-vm $server).powerstate
If($status -eq "PoweredOff")
{"$Server has been powered off adding hardware"}
else{
"$server is still powered on looping until off"
}
}
While ($Status -eq "PoweredOn")

$TotalvCPU=6
$Cores=1
$VMname = get-vm $server
$spec=New-Object –Type VMware.Vim.VirtualMAchineConfigSpec –Property @{“NumCoresPerSocket” = $cores}
($VMname).ExtensionData.ReconfigVM_Task($spec)

$VMname | Set-VM -MemoryGB 28 -NumCpu $TotalvCPU -Confirm:$false

Sleep -Seconds 5
Start-VM $server -Confirm:$false
}

So this script starts off identifying the servers that the work is going to be performed on.… Continue reading

New Method for Installing PowerCLI

New Method for Installing PowerCLI

Starting with the newest version of PowerCLI, 6.5.1, the method for installation has changed from the typical MSI file to using the PowerShell Gallery.

Step 1. Uninstall PowerCLI

The first step is to uninstall PowerCLI from your system.  To do this use Add/Remove Programs.

Uninstall PowerCLI via Add/Remove Programs

Before Installing the New PowerCLI, the old installation needs to be removed.  … Continue reading

Building VMs using OSCustomizationSpec

With the release of Windows Server 2016, we did a complete overhaul of all of our VM templates.  The current way that I was building VMs (link to article) and configuring the NICs (link to article) stopped working because we increased the security footprint in the templates.  So I was stuck figuring out how to revamp my build script.  … Continue reading

Using PowerCLI to Find Datastore with Missing VM

PowerCLI to Find Datastore with missing VM

During the last maintenance window at work, we starting having issues with vCenter, so to resolve the issues vCenter services were restarted.  After the vCenter services came back up, I noticed one of the servers on a host had lost it connection.  To make things worse, the datastore for the VM changed from the human readable format to location name.… Continue reading

New PowerCLI Release: PowerCLI 6.5 R1

PowerCLI 6.5 R1

VMware just release a new version of PowerCLI just today.  Like every new release, they have packed with one with a ton of new features, and updates to the existing cmdlets to help with automation and daily operations.

Updated Cmdlets

Move-VM – This cmdlet has been updated to support the ability to vMotion machines between vCenters.  … Continue reading

Get vMotion IPs from all VMHost

I was recently asked to gather the vMotion IPs for all of the hosts in our environment. We have about 80 or so VM Hosts, so this was a job for PowerCli.  Below is the script.

$Report = @()

$Clusters = Get-Cluster | Sort Name

ForEach ($Cluster in $Clusters){
    $VmHosts = $Cluster | Get-VmHost | Where {$_.ConnectionState -eq “Connected”} | Sort Name
        ForEach ($VmHost in $VmHosts){
            $Report += Get-VMHostNetworkAdapter -VMHost $VmHost.Name -VMKernel | Where {$_.VMotionEnabled -eq “True”} | select VmHost,IP
        }
}
$Report | Export-Csv C:\Scripts\Logs\vMotionIPs.csv -NoTypeInformation -UseCulture
vMotion IPs Gather from the Script
vMotion IPs
vMotion IPs gather with PowerCLI

First there needs to be a place to put all of the information that is going to be collected.  … Continue reading

Issues with PowerShell Modules and Duplicate Cmdlets

At the end of the day I always take my laptop with me as I never know when I’ll get a call about server issues.  So my PowerShell sessions remain open all of the time, with all of the modules loaded.  Granted I do save my scripts that I work on frequently, and I had a problem before losing a few scripts without having a recent save.  … Continue reading

Using PowerCli to gather NIC settings

We had some changes recently in the environment, and the old DNS and WINS servers were decommissioned.  So I was tasked with getting all of the NIC settings of the virtual machines so we can see how many were using the old settings.  So I started with a simple WMI call to gather the settings from the NICs.… Continue reading