PowerShell V3 Scheduled Job to start iSCSI service for Hyper-V Server

PowerShell V3 Scheduled Job to start iSCSI service for Hyper-V Server
Hi Guys, During one of our maintenance activities which involved patching of our Hyper-V hosts i noticed that during the restart of the servers after patching all cluster shared volumes mapped to the cluster was showing up in redirected access mode as below.

I went through cluster event logs and saw that the msiscsi service went to a stopped state after the server went for a restart.

When i manually started the msiscsi service all the CSV’s showed up again in “Online” status.

To Tackle this problem i created a script to check and restart msisci service across all our Hyper-V Nodes if it was in stopped state using the new PSScheduledJob module in PowerShell V3 daily at 3am.

To Develop the script i used the failover cluster module.

ipmo failoverclusters -ErrorAction SilentlyContinue

The Below commands list out all the Hyper-V nodes which are part of nkngv1 cluster

Get-ClusterNode -clustername nkngv1

Here’s The Entire small but powerful Script 🙂

$trigger = New-JobTrigger -Daily -At 3am

Register-ScheduledJob -Name
Start-iSCSIService -Trigger $trigger -ScriptBlock {

<#

.Synopsis

Following Cmdlet Check's the status of iSCSI service on all nodes for a clustername input by user and start's it if it’s not started.

This Cmdlet can be run from any of the ops boxes

.DESCRIPTION

Following Cmdlet Check's the status of iSCSI service on all nodes for a clustername input by user and start's it if it’s not started.

#>

ipmo failoverclusters -ErrorAction SilentlyContinueGet-ClusterNode -clustername nkngv1 | ForEach-Object {(Get-WmiObject -computerName $_.name Win32_Service -Filter "Name='msiscsi'").StartService()}



}

After i Ran this script on my elevated powershell prompt i was able to see the Job created in task scheduler under “TaskSchedulerLibraryMicrosoftWindowspowershellscheduledjobs”

Share this post

Post Comment