Home
%3CLINGO-SUB%20id%3D%22lingo-sub-372101%22%20slang%3D%22en-US%22%3EUsing%20PowerShell%20script%20make%20any%20application%20highly%20available%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-372101%22%20slang%3D%22en-US%22%3E%0A%20%26lt%3Bmeta%20http-equiv%3D%22Content-Type%22%20content%3D%22text%2Fhtml%3B%20charset%3DUTF-8%22%20%2F%26gt%3B%3CSTRONG%3EFirst%20published%20on%20MSDN%20on%20Jun%2006%2C%202016%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%20%3CEM%3E%20Author%3A%20%3C%2FEM%3E%20%3CBR%20%2F%3E%20%3CEM%3E%20Amitabh%20Tamhane%20%3C%2FEM%3E%20%3CBR%20%2F%3E%20%3CEM%3E%20Senior%20Program%20Manager%20%3C%2FEM%3E%20%3CBR%20%2F%3E%20%3CEM%3E%20Windows%20Server%20Microsoft%20%3C%2FEM%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CEM%3E%20OS%20releases%3A%20Applicable%20to%20Windows%20Server%202008%20R2%20or%20later%20%3C%2FEM%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Now%20you%20can%20use%20PowerShell%20scripts%20to%20make%20any%20application%20highly%20available%20with%20Failover%20Clusters!!!%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20The%20Generic%20Script%20is%20a%20built-in%20resource%20type%20included%20in%20Windows%20Server%20Failover%20Clusters.%20Its%20advantage%20is%20flexibility%3A%20you%20can%20make%20applications%20highly%20available%20by%20writing%20a%20simple%20script.%20For%20instance%2C%20you%20can%20make%20any%20PowerShell%20script%20highly%20available!%20Interested%3F%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20We%20created%20GenScript%20in%20ancient%20times%20and%20it%20supports%20only%20Visual%20Basic%20scripts%20%E2%80%93%20including%20Windows%20Server%202016.%20This%20means%20you%20can%E2%80%99t%20%3CEM%3E%20directly%20%3C%2FEM%3E%20configure%20PowerShell%20as%20GenScript%20resource.%20However%2C%20in%20this%20blog%20post%2C%20I%E2%80%99ll%20walk%20you%20through%20a%20sample%20Visual%20Basic%20script%20-%20and%20associated%20PS%20scripts%20-%20to%20build%20a%20custom%20GenScript%20resource%20that%20works%20well%20with%20PowerShell.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CEM%3E%20Pre-requisites%3A%20This%20blog%20assumes%20you%20have%20the%20basic%20understanding%20of%20Windows%20Server%20Failover%20Cluster%20%26amp%3B%20built-in%20resource%20types.%20%3C%2FEM%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CSTRONG%3E%3CEM%3EDisclaimer%3A%20%3C%2FEM%3E%20%3C%2FSTRONG%3E%20%3CEM%3E%20Microsoft%20does%20not%20intend%20to%20officially%20support%20any%20source%20code%2Fsample%20scripts%20provided%20as%20part%20of%20this%20blog.%20This%20blog%20is%20written%20only%20for%20a%20quick%20walk-through%20on%20how%20to%20run%20PowerShell%20scripts%20using%20GenScript%20resource.%20To%20make%20your%20application%20highly%20available%2C%20you%20are%20expected%20to%20modify%20all%20the%20scripts%20(Visual%20Basic%2FPowerShell)%20as%20per%20the%20needs%20of%20your%20application.%20%3C%2FEM%3E%20%3CBR%20%2F%3E%3CH2%20id%3D%22toc-hId-1679735492%22%20id%3D%22toc-hId-1709230725%22%3EVisual%20Basic%20Shell%3C%2FH2%3E%3CBR%20%2F%3E%20It%20so%20happens%20that%20Visual%20Basic%20Shell%20supports%20calling%20PowerShell%20script%2C%20then%20passing%20parameters%20and%20reading%20output.%20Here%E2%80%99s%20a%20Visual%20Basic%20Shell%20sample%20that%20uses%20some%20custom%20Private%20Properties%3A%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20'%3CYOUR%20application%3D%22%22%20name%3D%22%22%3E%20Resource%20Type%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Function%20Open(%20)%20%3CBR%20%2F%3E%20Resource.LogInformation%20%22Enter%20Open()%22%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20If%20Resource.PropertyExists(%22PSScriptsPath%22)%20%3D%20False%20Then%20%3CBR%20%2F%3E%20Resource.AddProperty(%22PSScriptsPath%22)%20%3CBR%20%2F%3E%20End%20If%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20If%20Resource.PropertyExists(%22Name%22)%20%3D%20False%20Then%20%3CBR%20%2F%3E%20Resource.AddProperty(%22Name%22)%20%3CBR%20%2F%3E%20End%20If%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20If%20Resource.PropertyExists(%22Data1%22)%20%3D%20False%20Then%20%3CBR%20%2F%3E%20Resource.AddProperty(%22Data1%22)%20%3CBR%20%2F%3E%20End%20If%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20If%20Resource.PropertyExists(%22Data2%22)%20%3D%20False%20Then%20%3CBR%20%2F%3E%20Resource.AddProperty(%22Data2%22)%20%3CBR%20%2F%3E%20End%20If%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20If%20Resource.PropertyExists(%22DataStorePath%22)%20%3D%20False%20Then%20%3CBR%20%2F%3E%20Resource.AddProperty(%22DataStorePath%22)%20%3CBR%20%2F%3E%20End%20If%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20'...Result...%20%3CBR%20%2F%3E%20Open%20%3D%200%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Resource.LogInformation%20%22Exit%20Open()%22%20%3CBR%20%2F%3E%20End%20Function%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Function%20Online(%20)%20%3CBR%20%2F%3E%20Resource.LogInformation%20%22Enter%20Online()%22%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20'...Check%20for%20required%20private%20properties...%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20If%20Resource.PropertyExists(%22PSScriptsPath%22)%20%3D%20False%20Then%20%3CBR%20%2F%3E%20Resource.LogInformation%20%22PSScriptsPath%20is%20a%20required%20private%20property.%22%20%3CBR%20%2F%3E%20Online%20%3D%201%20%3CBR%20%2F%3E%20Exit%20Function%20%3CBR%20%2F%3E%20End%20If%20%3CBR%20%2F%3E%20'...Resource.LogInformation%20%22PSScriptsPath%20is%20%22%20%26amp%3B%20Resource.PSScriptsPath%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20If%20Resource.PropertyExists(%22Name%22)%20%3D%20False%20Then%20%3CBR%20%2F%3E%20Resource.LogInformation%20%22Name%20is%20a%20required%20private%20property.%22%20%3CBR%20%2F%3E%20Online%20%3D%201%20%3CBR%20%2F%3E%20Exit%20Function%20%3CBR%20%2F%3E%20End%20If%20%3CBR%20%2F%3E%20Resource.LogInformation%20%22Name%20is%20%22%20%26amp%3B%20Resource.Name%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20If%20Resource.PropertyExists(%22Data1%22)%20%3D%20False%20Then%20%3CBR%20%2F%3E%20Resource.LogInformation%20%22Data1%20is%20a%20required%20private%20property.%22%20%3CBR%20%2F%3E%20Online%20%3D%201%20%3CBR%20%2F%3E%20Exit%20Function%20%3CBR%20%2F%3E%20End%20If%20%3CBR%20%2F%3E%20'...Resource.LogInformation%20%22Data1%20is%20%22%20%26amp%3B%20Resource.Data1%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20If%20Resource.PropertyExists(%22Data2%22)%20%3D%20False%20Then%20%3CBR%20%2F%3E%20Resource.LogInformation%20%22Data2%20is%20a%20required%20private%20property.%22%20%3CBR%20%2F%3E%20Online%20%3D%201%20%3CBR%20%2F%3E%20Exit%20Function%20%3CBR%20%2F%3E%20End%20If%20%3CBR%20%2F%3E%20'...Resource.LogInformation%20%22Data2%20is%20%22%20%26amp%3B%20Resource.Data2%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20If%20Resource.PropertyExists(%22DataStorePath%22)%20%3D%20False%20Then%20%3CBR%20%2F%3E%20Resource.LogInformation%20%22DataStorePath%20is%20a%20required%20private%20property.%22%20%3CBR%20%2F%3E%20Online%20%3D%201%20%3CBR%20%2F%3E%20Exit%20Function%20%3CBR%20%2F%3E%20End%20If%20%3CBR%20%2F%3E%20'...Resource.LogInformation%20%22DataStorePath%20is%20%22%20%26amp%3B%20Resource.DataStorePath%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20PScmd%20%3D%20%22powershell.exe%20-file%20%22%20%26amp%3B%20Resource.PSScriptsPath%20%26amp%3B%20%22%5CPS_Online.ps1%20%22%20%26amp%3B%20Resource.PSScriptsPath%20%26amp%3B%20%22%20%22%20%26amp%3B%20Resource.Name%20%26amp%3B%20%22%20%22%20%26amp%3B%20Resource.Data1%20%26amp%3B%20%22%20%22%20%26amp%3B%20Resource.Data2%20%26amp%3B%20%22%20%22%20%26amp%3B%20Resource.DataStorePath%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Dim%20WshShell%20%3CBR%20%2F%3E%20Set%20WshShell%20%3D%20CreateObject(%22WScript.Shell%22)%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Resource.LogInformation%20%22Calling%20Online%20PS%20script%3D%20%22%20%26amp%3B%20PSCmd%20%3CBR%20%2F%3E%20rv%20%3D%20WshShell.Run(PScmd%2C%20%2C%20True)%20%3CBR%20%2F%3E%20Resource.LogInformation%20%22PS%20return%20value%20is%3A%20%22%20%26amp%3B%20rv%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20'...Translate%20result%20from%20PowerShell%20...%20%3CBR%20%2F%3E%20'...1%20(True%20in%20PS)%20%3D%3D%200%20(True%20in%20VB)%20%3CBR%20%2F%3E%20'...0%20(False%20in%20PS)%20%3D%3D%201%20(False%20in%20VB)%20%3CBR%20%2F%3E%20If%20rv%20%3D%201%20Then%20%3CBR%20%2F%3E%20Resource.LogInformation%20%22Online%20Success%22%20%3CBR%20%2F%3E%20Online%20%3D%200%20%3CBR%20%2F%3E%20Else%20%3CBR%20%2F%3E%20Resource.LogInformation%20%22Online%20Error%22%20%3CBR%20%2F%3E%20Online%20%3D%201%20%3CBR%20%2F%3E%20End%20If%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Resource.LogInformation%20%22Exit%20Online()%22%20%3CBR%20%2F%3E%20End%20Function%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Function%20Offline(%20)%20%3CBR%20%2F%3E%20Resource.LogInformation%20%22Enter%20Offline()%22%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20'...Check%20for%20required%20private%20properties...%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20If%20Resource.PropertyExists(%22PSScriptsPath%22)%20%3D%20False%20Then%20%3CBR%20%2F%3E%20Resource.LogInformation%20%22PSScriptsPath%20is%20a%20required%20private%20property.%22%20%3CBR%20%2F%3E%20Offline%20%3D%201%20%3CBR%20%2F%3E%20Exit%20Function%20%3CBR%20%2F%3E%20End%20If%20%3CBR%20%2F%3E%20'...Resource.LogInformation%20%22PSScriptsPath%20is%20%22%20%26amp%3B%20Resource.PSScriptsPath%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20If%20Resource.PropertyExists(%22Name%22)%20%3D%20False%20Then%20%3CBR%20%2F%3E%20Resource.LogInformation%20%22Name%20is%20a%20required%20private%20property.%22%20%3CBR%20%2F%3E%20Offline%20%3D%201%20%3CBR%20%2F%3E%20Exit%20Function%20%3CBR%20%2F%3E%20End%20If%20%3CBR%20%2F%3E%20Resource.LogInformation%20%22Name%20is%20%22%20%26amp%3B%20Resource.Name%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20If%20Resource.PropertyExists(%22Data1%22)%20%3D%20False%20Then%20%3CBR%20%2F%3E%20Resource.LogInformation%20%22Data1%20is%20a%20required%20private%20property.%22%20%3CBR%20%2F%3E%20Offline%20%3D%201%20%3CBR%20%2F%3E%20Exit%20Function%20%3CBR%20%2F%3E%20End%20If%20%3CBR%20%2F%3E%20'...Resource.LogInformation%20%22Data1%20is%20%22%20%26amp%3B%20Resource.Data1%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20If%20Resource.PropertyExists(%22Data2%22)%20%3D%20False%20Then%20%3CBR%20%2F%3E%20Resource.LogInformation%20%22Data2%20is%20a%20required%20private%20property.%22%20%3CBR%20%2F%3E%20Offline%20%3D%201%20%3CBR%20%2F%3E%20Exit%20Function%20%3CBR%20%2F%3E%20End%20If%20%3CBR%20%2F%3E%20'...Resource.LogInformation%20%22Data2%20is%20%22%20%26amp%3B%20Resource.Data2%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20If%20Resource.PropertyExists(%22DataStorePath%22)%20%3D%20False%20Then%20%3CBR%20%2F%3E%20Resource.LogInformation%20%22DataStorePath%20is%20a%20required%20private%20property.%22%20%3CBR%20%2F%3E%20Offline%20%3D%201%20%3CBR%20%2F%3E%20Exit%20Function%20%3CBR%20%2F%3E%20End%20If%20%3CBR%20%2F%3E%20'...Resource.LogInformation%20%22DataStorePath%20is%20%22%20%26amp%3B%20Resource.DataStorePath%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20PScmd%20%3D%20%22powershell.exe%20-file%20%22%20%26amp%3B%20Resource.PSScriptsPath%20%26amp%3B%20%22%5CPS_Offline.ps1%20%22%20%26amp%3B%20Resource.PSScriptsPath%20%26amp%3B%20%22%20%22%20%26amp%3B%20Resource.Name%20%26amp%3B%20%22%20%22%20%26amp%3B%20Resource.Data1%20%26amp%3B%20%22%20%22%20%26amp%3B%20Resource.Data2%20%26amp%3B%20%22%20%22%20%26amp%3B%20Resource.DataStorePath%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Dim%20WshShell%20%3CBR%20%2F%3E%20Set%20WshShell%20%3D%20CreateObject(%22WScript.Shell%22)%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Resource.LogInformation%20%22Calling%20Offline%20PS%20script%3D%20%22%20%26amp%3B%20PSCmd%20%3CBR%20%2F%3E%20rv%20%3D%20WshShell.Run(PScmd%2C%20%2C%20True)%20%3CBR%20%2F%3E%20Resource.LogInformation%20%22PS%20return%20value%20is%3A%20%22%20%26amp%3B%20rv%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20'...Translate%20result%20from%20PowerShell%20...%20%3CBR%20%2F%3E%20'...1%20(True%20in%20PS)%20%3D%3D%200%20(True%20in%20VB)%20%3CBR%20%2F%3E%20'...0%20(False%20in%20PS)%20%3D%3D%201%20(False%20in%20VB)%20%3CBR%20%2F%3E%20If%20rv%20%3D%201%20Then%20%3CBR%20%2F%3E%20Resource.LogInformation%20%22Offline%20Success%22%20%3CBR%20%2F%3E%20Offline%20%3D%200%20%3CBR%20%2F%3E%20Else%20%3CBR%20%2F%3E%20Resource.LogInformation%20%22Offline%20Error%22%20%3CBR%20%2F%3E%20Offline%20%3D%201%20%3CBR%20%2F%3E%20End%20If%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Resource.LogInformation%20%22Exit%20Offline()%22%20%3CBR%20%2F%3E%20End%20Function%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Function%20LooksAlive(%20)%20%3CBR%20%2F%3E%20'...Result...%20%3CBR%20%2F%3E%20LooksAlive%20%3D%200%20%3CBR%20%2F%3E%20End%20Function%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Function%20IsAlive(%20)%20%3CBR%20%2F%3E%20Resource.LogInformation%20%22Entering%20IsAlive%22%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20'...Check%20for%20required%20private%20properties...%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20If%20Resource.PropertyExists(%22PSScriptsPath%22)%20%3D%20False%20Then%20%3CBR%20%2F%3E%20Resource.LogInformation%20%22PSScriptsPath%20is%20a%20required%20private%20property.%22%20%3CBR%20%2F%3E%20IsAlive%20%3D%201%20%3CBR%20%2F%3E%20Exit%20Function%20%3CBR%20%2F%3E%20End%20If%20%3CBR%20%2F%3E%20'...Resource.LogInformation%20%22PSScriptsPath%20is%20%22%20%26amp%3B%20Resource.PSScriptsPath%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20If%20Resource.PropertyExists(%22Name%22)%20%3D%20False%20Then%20%3CBR%20%2F%3E%20Resource.LogInformation%20%22Name%20is%20a%20required%20private%20property.%22%20%3CBR%20%2F%3E%20IsAlive%20%3D%201%20%3CBR%20%2F%3E%20Exit%20Function%20%3CBR%20%2F%3E%20End%20If%20%3CBR%20%2F%3E%20Resource.LogInformation%20%22Name%20is%20%22%20%26amp%3B%20Resource.Name%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20If%20Resource.PropertyExists(%22Data1%22)%20%3D%20False%20Then%20%3CBR%20%2F%3E%20Resource.LogInformation%20%22Data1%20is%20a%20required%20private%20property.%22%20%3CBR%20%2F%3E%20IsAlive%20%3D%201%20%3CBR%20%2F%3E%20Exit%20Function%20%3CBR%20%2F%3E%20End%20If%20%3CBR%20%2F%3E%20'...Resource.LogInformation%20%22Data1%20is%20%22%20%26amp%3B%20Resource.Data1%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20If%20Resource.PropertyExists(%22Data2%22)%20%3D%20False%20Then%20%3CBR%20%2F%3E%20Resource.LogInformation%20%22Data2%20is%20a%20required%20private%20property.%22%20%3CBR%20%2F%3E%20IsAlive%20%3D%201%20%3CBR%20%2F%3E%20Exit%20Function%20%3CBR%20%2F%3E%20End%20If%20%3CBR%20%2F%3E%20'...Resource.LogInformation%20%22Data2%20is%20%22%20%26amp%3B%20Resource.Data2%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20If%20Resource.PropertyExists(%22DataStorePath%22)%20%3D%20False%20Then%20%3CBR%20%2F%3E%20Resource.LogInformation%20%22DataStorePath%20is%20a%20required%20private%20property.%22%20%3CBR%20%2F%3E%20IsAlive%20%3D%201%20%3CBR%20%2F%3E%20Exit%20Function%20%3CBR%20%2F%3E%20End%20If%20%3CBR%20%2F%3E%20'...Resource.LogInformation%20%22DataStorePath%20is%20%22%20%26amp%3B%20Resource.DataStorePath%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20PScmd%20%3D%20%22powershell.exe%20-file%20%22%20%26amp%3B%20Resource.PSScriptsPath%20%26amp%3B%20%22%5CPS_IsAlive.ps1%20%22%20%26amp%3B%20Resource.PSScriptsPath%20%26amp%3B%20%22%20%22%20%26amp%3B%20Resource.Name%20%26amp%3B%20%22%20%22%20%26amp%3B%20Resource.Data1%20%26amp%3B%20%22%20%22%20%26amp%3B%20Resource.Data2%20%26amp%3B%20%22%20%22%20%26amp%3B%20Resource.DataStorePath%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Dim%20WshShell%20%3CBR%20%2F%3E%20Set%20WshShell%20%3D%20CreateObject(%22WScript.Shell%22)%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Resource.LogInformation%20%22Calling%20IsAlive%20PS%20script%3D%20%22%20%26amp%3B%20PSCmd%20%3CBR%20%2F%3E%20rv%20%3D%20WshShell.Run(PScmd%2C%20%2C%20True)%20%3CBR%20%2F%3E%20Resource.LogInformation%20%22PS%20return%20value%20is%3A%20%22%20%26amp%3B%20rv%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20'...Translate%20result%20from%20PowerShell%20...%20%3CBR%20%2F%3E%20'...1%20(True%20in%20PS)%20%3D%3D%200%20(True%20in%20VB)%20%3CBR%20%2F%3E%20'...0%20(False%20in%20PS)%20%3D%3D%201%20(False%20in%20VB)%20%3CBR%20%2F%3E%20If%20rv%20%3D%201%20Then%20%3CBR%20%2F%3E%20Resource.LogInformation%20%22IsAlive%20Success%22%20%3CBR%20%2F%3E%20IsAlive%20%3D%200%20%3CBR%20%2F%3E%20Else%20%3CBR%20%2F%3E%20Resource.LogInformation%20%22IsAlive%20Error%22%20%3CBR%20%2F%3E%20IsAlive%20%3D%201%20%3CBR%20%2F%3E%20End%20If%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Resource.LogInformation%20%22Exit%20IsAlive()%22%20%3CBR%20%2F%3E%20End%20Function%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Function%20Terminate(%20)%20%3CBR%20%2F%3E%20Resource.LogInformation%20%22Enter%20Terminate()%22%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20'...Check%20for%20required%20private%20properties...%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20If%20Resource.PropertyExists(%22PSScriptsPath%22)%20%3D%20False%20Then%20%3CBR%20%2F%3E%20Resource.LogInformation%20%22PSScriptsPath%20is%20a%20required%20private%20property.%22%20%3CBR%20%2F%3E%20Terminate%20%3D%201%20%3CBR%20%2F%3E%20Exit%20Function%20%3CBR%20%2F%3E%20End%20If%20%3CBR%20%2F%3E%20'...Resource.LogInformation%20%22PSScriptsPath%20is%20%22%20%26amp%3B%20Resource.PSScriptsPath%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20If%20Resource.PropertyExists(%22Name%22)%20%3D%20False%20Then%20%3CBR%20%2F%3E%20Resource.LogInformation%20%22Name%20is%20a%20required%20private%20property.%22%20%3CBR%20%2F%3E%20Terminate%20%3D%201%20%3CBR%20%2F%3E%20Exit%20Function%20%3CBR%20%2F%3E%20End%20If%20%3CBR%20%2F%3E%20Resource.LogInformation%20%22Name%20is%20%22%20%26amp%3B%20Resource.Name%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20If%20Resource.PropertyExists(%22Data1%22)%20%3D%20False%20Then%20%3CBR%20%2F%3E%20Resource.LogInformation%20%22Data1%20is%20a%20required%20private%20property.%22%20%3CBR%20%2F%3E%20Terminate%20%3D%201%20%3CBR%20%2F%3E%20Exit%20Function%20%3CBR%20%2F%3E%20End%20If%20%3CBR%20%2F%3E%20'...Resource.LogInformation%20%22Data1%20is%20%22%20%26amp%3B%20Resource.Data1%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20If%20Resource.PropertyExists(%22Data2%22)%20%3D%20False%20Then%20%3CBR%20%2F%3E%20Resource.LogInformation%20%22Data2%20is%20a%20required%20private%20property.%22%20%3CBR%20%2F%3E%20Terminate%20%3D%201%20%3CBR%20%2F%3E%20Exit%20Function%20%3CBR%20%2F%3E%20End%20If%20%3CBR%20%2F%3E%20'...Resource.LogInformation%20%22Data2%20is%20%22%20%26amp%3B%20Resource.Data2%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20If%20Resource.PropertyExists(%22DataStorePath%22)%20%3D%20False%20Then%20%3CBR%20%2F%3E%20Resource.LogInformation%20%22DataStorePath%20is%20a%20required%20private%20property.%22%20%3CBR%20%2F%3E%20Terminate%20%3D%201%20%3CBR%20%2F%3E%20Exit%20Function%20%3CBR%20%2F%3E%20End%20If%20%3CBR%20%2F%3E%20'...Resource.LogInformation%20%22DataStorePath%20is%20%22%20%26amp%3B%20Resource.DataStorePath%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20PScmd%20%3D%20%22powershell.exe%20-file%20%22%20%26amp%3B%20Resource.PSScriptsPath%20%26amp%3B%20%22%5CPS_Terminate.ps1%20%22%20%26amp%3B%20Resource.PSScriptsPath%20%26amp%3B%20%22%20%22%20%26amp%3B%20Resource.Name%20%26amp%3B%20%22%20%22%20%26amp%3B%20Resource.Data1%20%26amp%3B%20%22%20%22%20%26amp%3B%20Resource.Data2%20%26amp%3B%20%22%20%22%20%26amp%3B%20Resource.DataStorePath%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Dim%20WshShell%20%3CBR%20%2F%3E%20Set%20WshShell%20%3D%20CreateObject(%22WScript.Shell%22)%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Resource.LogInformation%20%22Calling%20Terminate%20PS%20script%3D%20%22%20%26amp%3B%20PSCmd%20%3CBR%20%2F%3E%20rv%20%3D%20WshShell.Run(PScmd%2C%20%2C%20True)%20%3CBR%20%2F%3E%20Resource.LogInformation%20%22PS%20return%20value%20is%3A%20%22%20%26amp%3B%20rv%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20'...Translate%20result%20from%20PowerShell%20...%20%3CBR%20%2F%3E%20'...1%20(True%20in%20PS)%20%3D%3D%200%20(True%20in%20VB)%20%3CBR%20%2F%3E%20'...0%20(False%20in%20PS)%20%3D%3D%201%20(False%20in%20VB)%20%3CBR%20%2F%3E%20If%20rv%20%3D%201%20Then%20%3CBR%20%2F%3E%20Terminate%20%3D%200%20%3CBR%20%2F%3E%20Else%20%3CBR%20%2F%3E%20Terminate%20%3D%201%20%3CBR%20%2F%3E%20End%20If%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Resource.LogInformation%20%22Exit%20Terminate()%22%20%3CBR%20%2F%3E%20End%20Function%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Function%20Close(%20)%20%3CBR%20%2F%3E%20'...Result...%20%3CBR%20%2F%3E%20Close%20%3D%200%20%3CBR%20%2F%3E%20End%20Function%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%3CH2%20id%3D%22toc-hId--872421469%22%20id%3D%22toc-hId--842926236%22%3EEntry%20Points%3C%2FH2%3E%3CBR%20%2F%3E%20In%20the%20above%20sample%20VB%20script%2C%20the%20following%20entry%20points%20are%20defined%3A%20%3CBR%20%2F%3E%3CUL%3E%3CBR%20%2F%3E%3CLI%3EOpen%20%E2%80%93%20Ensures%20all%20necessary%20steps%20complete%20before%20starting%20your%20application%3C%2FLI%3E%3CBR%20%2F%3E%3CLI%3EOnline%20%E2%80%93%20Function%20to%20start%20your%20application%3C%2FLI%3E%3CBR%20%2F%3E%3CLI%3EOffline%20%E2%80%93%20Function%20to%20stop%20your%20application%3C%2FLI%3E%3CBR%20%2F%3E%3CLI%3EIsAlive%20%E2%80%93%20Function%20to%20validate%20your%20application%20startup%20and%20monitor%20health%3C%2FLI%3E%3CBR%20%2F%3E%3CLI%3ETerminate%20%E2%80%93%20Function%20to%20forcefully%20cleanup%20application%20state%20(ex%3A%20Error%20during%20Online%2FOffline)%3C%2FLI%3E%3CBR%20%2F%3E%3CLI%3EClose%20%E2%80%93%20Ensures%20all%20necessary%20cleanup%20completes%20after%20stopping%20your%20application%3C%2FLI%3E%3CBR%20%2F%3E%3C%2FUL%3E%3CBR%20%2F%3E%20Each%20of%20the%20above%20entry%20points%20is%20defined%20as%20a%20function%20(ex%3A%20%E2%80%9CFunction%20Online(%20)%E2%80%9D).%20Failover%20Cluster%20then%20calls%20these%20entry%20point%20functions%20as%20part%20of%20the%20GenScript%20resource%20type%20definition.%20%3CBR%20%2F%3E%3CH2%20id%3D%22toc-hId-870388866%22%20id%3D%22toc-hId-899884099%22%3EPrivate%20Properties%3C%2FH2%3E%3CBR%20%2F%3E%20For%20resources%20of%20any%20type%2C%20Failover%20Cluster%20supports%20two%20types%20of%20properties%3A%20%3CBR%20%2F%3E%3CUL%3E%3CBR%20%2F%3E%3CLI%3ECommon%20Properties%20%E2%80%93%20Generic%20properties%20that%20can%20have%20unique%20value%20for%20each%20resource%3C%2FLI%3E%3CBR%20%2F%3E%3CLI%3EPrivate%20Properties%20%E2%80%93%20Custom%20properties%20that%20are%20unique%20to%20that%20resource%20type.%20Each%20resource%20of%20that%20resource%20type%20has%20these%20private%20properties.%3C%2FLI%3E%3CBR%20%2F%3E%3C%2FUL%3E%3CBR%20%2F%3E%20When%20writing%20a%20GenScript%20resource%2C%20you%20need%20to%20evaluate%20if%20you%20need%20private%20properties.%20In%20the%20above%20VB%20sample%20script%2C%20I%20have%20defined%20five%20sample%20private%20properties%20(only%20as%20an%20example)%3A%20%3CBR%20%2F%3E%3CUL%3E%3CBR%20%2F%3E%3CLI%3EPSScriptsPath%20%E2%80%93%20Path%20to%20the%20folder%20containing%20PS%20scripts%3C%2FLI%3E%3CBR%20%2F%3E%3CLI%3EName%3C%2FLI%3E%3CBR%20%2F%3E%3CLI%3EData1%20%E2%80%93%20some%20custom%20data%20field%3C%2FLI%3E%3CBR%20%2F%3E%3CLI%3EData2%20%E2%80%93%20another%20custom%20data%20field%3C%2FLI%3E%3CBR%20%2F%3E%3CLI%3EDataStorePath%20%E2%80%93%20path%20to%20a%20common%20backend%20store%20(if%20any)%3C%2FLI%3E%3CBR%20%2F%3E%3C%2FUL%3E%3CBR%20%2F%3E%20The%20above%20private%20properties%20are%20shown%20as%20example%20only%20%26amp%3B%20you%20are%20expected%20to%20modify%20the%20above%20VB%20script%20to%20customize%20it%20for%20your%20application.%20%3CBR%20%2F%3E%3CH2%20id%3D%22toc-hId--1681768095%22%20id%3D%22toc-hId--1652272862%22%3EPowerShell%20Scripts%3C%2FH2%3E%3CBR%20%2F%3E%20The%20Visual%20Basic%20script%20simply%20connects%20the%20Failover%20Clusters%E2%80%99%20RHS%20(Resource%20Hosting%20Service)%20to%20call%20PowerShell%20scripts.%20You%20may%20notice%20the%20%E2%80%9CPScmd%E2%80%9D%20parameter%20containing%20the%20actual%20PS%20command%20that%20will%20be%20called%20to%20perform%20the%20action%20(Online%2C%20Offline%20etc.)%20by%20calling%20into%20corresponding%20PS%20scripts.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20For%20this%20sample%2C%20here%20are%20four%20PowerShell%20scripts%3A%20%3CBR%20%2F%3E%3CUL%3E%3CBR%20%2F%3E%3CLI%3EOnline.ps1%20%E2%80%93%20To%20start%20your%20application%3C%2FLI%3E%3CBR%20%2F%3E%3CLI%3EOffline.ps1%20%E2%80%93%20To%20stop%20your%20application%3C%2FLI%3E%3CBR%20%2F%3E%3CLI%3ETerminate.ps1%20%E2%80%93%20To%20forcefully%20cleanup%20your%20application%3C%2FLI%3E%3CBR%20%2F%3E%3CLI%3EIsAlive.ps1%20%E2%80%93%20To%20monitor%20health%20of%20your%20application%3C%2FLI%3E%3CBR%20%2F%3E%3C%2FUL%3E%3CBR%20%2F%3E%20Example%20of%20PS%20scripts%3A%20%3CBR%20%2F%3E%3CH2%20id%3D%22toc-hId-61042240%22%20id%3D%22toc-hId-90537473%22%3EEntry%20Point%3A%20Online%3C%2FH2%3E%3CBR%20%2F%3E%20Param(%20%3CBR%20%2F%3E%20%23%20Sample%20properties%E2%80%A6%20%3CBR%20%2F%3E%20%5BParameter(Mandatory%3D%24true%2C%20Position%3D0)%5D%20%3CBR%20%2F%3E%20%5BValidateNotNullOrEmpty()%5D%20%3CBR%20%2F%3E%20%5Bstring%5D%20%3CBR%20%2F%3E%20%24PSScriptsPath%2C%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%23%20%3CBR%20%2F%3E%20%5BParameter(Mandatory%3D%24true%2C%20Position%3D1)%5D%20%3CBR%20%2F%3E%20%5BValidateNotNullOrEmpty()%5D%20%3CBR%20%2F%3E%20%5Bstring%5D%20%3CBR%20%2F%3E%20%24Name%2C%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%23%20%3CBR%20%2F%3E%20%5BParameter(Mandatory%3D%24true%2C%20Position%3D2)%5D%20%3CBR%20%2F%3E%20%5BValidateNotNullOrEmpty()%5D%20%3CBR%20%2F%3E%20%5Bstring%5D%20%3CBR%20%2F%3E%20%24Data1%2C%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%23%20%3CBR%20%2F%3E%20%5BParameter(Mandatory%3D%24true%2C%20Position%3D3)%5D%20%3CBR%20%2F%3E%20%5BValidateNotNullOrEmpty()%5D%20%3CBR%20%2F%3E%20%5Bstring%5D%20%3CBR%20%2F%3E%20%24Data2%2C%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%23%20%3CBR%20%2F%3E%20%5BParameter(Mandatory%3D%24true%2C%20Position%3D4)%5D%20%3CBR%20%2F%3E%20%5BValidateNotNullOrEmpty()%5D%20%3CBR%20%2F%3E%20%5Bstring%5D%20%3CBR%20%2F%3E%20%24DataStorePath%20%3CBR%20%2F%3E%20)%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%24filePath%20%3D%20Join-Path%20%24PSScriptsPath%20%22Output_Online.log%22%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%40%22%20%3CBR%20%2F%3E%20Starting%20Online...%20%3CBR%20%2F%3E%20Name%3D%20%24Name%20%3CBR%20%2F%3E%20Data1%3D%20%24Data1%20%3CBR%20%2F%3E%20Data2%3D%20%24Data2%20%3CBR%20%2F%3E%20DataStorePath%3D%20%24DataStorePath%20%3CBR%20%2F%3E%20%22%40%20%7C%20Out-File%20-FilePath%20%24filePath%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%24error.clear()%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%23%23%23%20Do%20your%20online%20script%20logic%20here%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20if%20(%24errorOut%20-eq%20%24true)%20%3CBR%20%2F%3E%20%7B%20%3CBR%20%2F%3E%20%22Error%20%24error%22%20%7C%20Out-File%20-FilePath%20%24filePath%20-Append%20%3CBR%20%2F%3E%20exit%20%24false%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%22Success%22%20%7C%20Out-File%20-FilePath%20%24filePath%20-Append%20%3CBR%20%2F%3E%20exit%20%24true%20%3CBR%20%2F%3E%3CH2%20id%3D%22toc-hId-1803852575%22%20id%3D%22toc-hId-1833347808%22%3EEntry%20Point%3A%20Offline%3C%2FH2%3E%3CBR%20%2F%3E%20Param(%20%3CBR%20%2F%3E%20%23%20Sample%20properties%E2%80%A6%20%3CBR%20%2F%3E%20%5BParameter(Mandatory%3D%24true%2C%20Position%3D0)%5D%20%3CBR%20%2F%3E%20%5BValidateNotNullOrEmpty()%5D%20%3CBR%20%2F%3E%20%5Bstring%5D%20%3CBR%20%2F%3E%20%24PSScriptsPath%2C%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%23%20%3CBR%20%2F%3E%20%5BParameter(Mandatory%3D%24true%2C%20Position%3D1)%5D%20%3CBR%20%2F%3E%20%5BValidateNotNullOrEmpty()%5D%20%3CBR%20%2F%3E%20%5Bstring%5D%20%3CBR%20%2F%3E%20%24Name%2C%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%23%20%3CBR%20%2F%3E%20%5BParameter(Mandatory%3D%24true%2C%20Position%3D2)%5D%20%3CBR%20%2F%3E%20%5BValidateNotNullOrEmpty()%5D%20%3CBR%20%2F%3E%20%5Bstring%5D%20%3CBR%20%2F%3E%20%24Data1%2C%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%23%20%3CBR%20%2F%3E%20%5BParameter(Mandatory%3D%24true%2C%20Position%3D3)%5D%20%3CBR%20%2F%3E%20%5BValidateNotNullOrEmpty()%5D%20%3CBR%20%2F%3E%20%5Bstring%5D%20%3CBR%20%2F%3E%20%24Data2%2C%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%23%20%3CBR%20%2F%3E%20%5BParameter(Mandatory%3D%24true%2C%20Position%3D4)%5D%20%3CBR%20%2F%3E%20%5BValidateNotNullOrEmpty()%5D%20%3CBR%20%2F%3E%20%5Bstring%5D%20%3CBR%20%2F%3E%20%24DataStorePath%20%3CBR%20%2F%3E%20)%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%24filePath%20%3D%20Join-Path%20%24PSScriptsPath%20%22Output_Offline.log%22%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%40%22%20%3CBR%20%2F%3E%20Starting%20Offline...%20%3CBR%20%2F%3E%20Name%3D%20%24Name%20%3CBR%20%2F%3E%20Data1%3D%20%24Data1%20%3CBR%20%2F%3E%20Data2%3D%20%24Data2%20%3CBR%20%2F%3E%20DataStorePath%3D%20%24DataStorePath%20%3CBR%20%2F%3E%20%22%40%20%7C%20Out-File%20-FilePath%20%24filePath%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%24error.clear()%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%23%23%23%20Do%20your%20offline%20script%20logic%20here%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20if%20(%24errorOut%20-eq%20%24true)%20%3CBR%20%2F%3E%20%7B%20%3CBR%20%2F%3E%20%22Error%20%24error%22%20%7C%20Out-File%20-FilePath%20%24filePath%20-Append%20%3CBR%20%2F%3E%20exit%20%24false%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%22Success%22%20%7C%20Out-File%20-FilePath%20%24filePath%20-Append%20%3CBR%20%2F%3E%20exit%20%24true%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%3CH2%20id%3D%22toc-hId--748304386%22%20id%3D%22toc-hId--718809153%22%3EEntry%20Point%3A%20Terminate%3C%2FH2%3E%3CBR%20%2F%3E%20Param(%20%3CBR%20%2F%3E%20%23%20Sample%20properties%E2%80%A6%20%3CBR%20%2F%3E%20%5BParameter(Mandatory%3D%24true%2C%20Position%3D0)%5D%20%3CBR%20%2F%3E%20%5BValidateNotNullOrEmpty()%5D%20%3CBR%20%2F%3E%20%5Bstring%5D%20%3CBR%20%2F%3E%20%24PSScriptsPath%2C%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%23%20%3CBR%20%2F%3E%20%5BParameter(Mandatory%3D%24true%2C%20Position%3D1)%5D%20%3CBR%20%2F%3E%20%5BValidateNotNullOrEmpty()%5D%20%3CBR%20%2F%3E%20%5Bstring%5D%20%3CBR%20%2F%3E%20%24Name%2C%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%23%20%3CBR%20%2F%3E%20%5BParameter(Mandatory%3D%24true%2C%20Position%3D2)%5D%20%3CBR%20%2F%3E%20%5BValidateNotNullOrEmpty()%5D%20%3CBR%20%2F%3E%20%5Bstring%5D%20%3CBR%20%2F%3E%20%24Data1%2C%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%23%20%3CBR%20%2F%3E%20%5BParameter(Mandatory%3D%24true%2C%20Position%3D3)%5D%20%3CBR%20%2F%3E%20%5BValidateNotNullOrEmpty()%5D%20%3CBR%20%2F%3E%20%5Bstring%5D%20%3CBR%20%2F%3E%20%24Data2%2C%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%23%20%3CBR%20%2F%3E%20%5BParameter(Mandatory%3D%24true%2C%20Position%3D4)%5D%20%3CBR%20%2F%3E%20%5BValidateNotNullOrEmpty()%5D%20%3CBR%20%2F%3E%20%5Bstring%5D%20%3CBR%20%2F%3E%20%24DataStorePath%20%3CBR%20%2F%3E%20)%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%24filePath%20%3D%20Join-Path%20%24PSScriptsPath%20%22Output_Terminate.log%22%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%40%22%20%3CBR%20%2F%3E%20Starting%20Terminate...%20%3CBR%20%2F%3E%20Name%3D%20%24Name%20%3CBR%20%2F%3E%20Data1%3D%20%24Data1%20%3CBR%20%2F%3E%20Data2%3D%20%24Data2%20%3CBR%20%2F%3E%20DataStorePath%3D%20%24DataStorePath%20%3CBR%20%2F%3E%20%22%40%20%7C%20Out-File%20-FilePath%20%24filePath%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%24error.clear()%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%23%23%23%20Do%20your%20terminate%20script%20logic%20here%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20if%20(%24errorOut%20-eq%20%24true)%20%3CBR%20%2F%3E%20%7B%20%3CBR%20%2F%3E%20%22Error%20%24error%22%20%7C%20Out-File%20-FilePath%20%24filePath%20-Append%20%3CBR%20%2F%3E%20exit%20%24false%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%22Success%22%20%7C%20Out-File%20-FilePath%20%24filePath%20-Append%20%3CBR%20%2F%3E%20exit%20%24true%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%3CH2%20id%3D%22toc-hId-994505949%22%20id%3D%22toc-hId-1024001182%22%3EEntry%20Point%3A%20IsAlive%3C%2FH2%3E%3CBR%20%2F%3E%20Param(%20%3CBR%20%2F%3E%20%23%20Sample%20properties%E2%80%A6%20%3CBR%20%2F%3E%20%5BParameter(Mandatory%3D%24true%2C%20Position%3D0)%5D%20%3CBR%20%2F%3E%20%5BValidateNotNullOrEmpty()%5D%20%3CBR%20%2F%3E%20%5Bstring%5D%20%3CBR%20%2F%3E%20%24PSScriptsPath%2C%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%23%20%3CBR%20%2F%3E%20%5BParameter(Mandatory%3D%24true%2C%20Position%3D1)%5D%20%3CBR%20%2F%3E%20%5BValidateNotNullOrEmpty()%5D%20%3CBR%20%2F%3E%20%5Bstring%5D%20%3CBR%20%2F%3E%20%24Name%2C%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%23%20%3CBR%20%2F%3E%20%5BParameter(Mandatory%3D%24true%2C%20Position%3D2)%5D%20%3CBR%20%2F%3E%20%5BValidateNotNullOrEmpty()%5D%20%3CBR%20%2F%3E%20%5Bstring%5D%20%3CBR%20%2F%3E%20%24Data1%2C%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%23%20%3CBR%20%2F%3E%20%5BParameter(Mandatory%3D%24true%2C%20Position%3D3)%5D%20%3CBR%20%2F%3E%20%5BValidateNotNullOrEmpty()%5D%20%3CBR%20%2F%3E%20%5Bstring%5D%20%3CBR%20%2F%3E%20%24Data2%2C%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%23%20%3CBR%20%2F%3E%20%5BParameter(Mandatory%3D%24true%2C%20Position%3D4)%5D%20%3CBR%20%2F%3E%20%5BValidateNotNullOrEmpty()%5D%20%3CBR%20%2F%3E%20%5Bstring%5D%20%3CBR%20%2F%3E%20%24DataStorePath%20%3CBR%20%2F%3E%20)%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%24filePath%20%3D%20Join-Path%20%24PSScriptsPath%20%22Output_IsAlive.log%22%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%40%22%20%3CBR%20%2F%3E%20Starting%20IsAlive...%20%3CBR%20%2F%3E%20Name%3D%20%24Name%20%3CBR%20%2F%3E%20Data1%3D%20%24Data1%20%3CBR%20%2F%3E%20Data2%3D%20%24Data2%20%3CBR%20%2F%3E%20DataStorePath%3D%20%24DataStorePath%20%3CBR%20%2F%3E%20%22%40%20%7C%20Out-File%20-FilePath%20%24filePath%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%24error.clear()%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%23%23%23%20Do%20your%20isalive%20script%20logic%20here%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20if%20(%24errorOut%20-eq%20%24true)%20%3CBR%20%2F%3E%20%7B%20%3CBR%20%2F%3E%20%22Error%20%24error%22%20%7C%20Out-File%20-FilePath%20%24filePath%20-Append%20%3CBR%20%2F%3E%20exit%20%24false%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%22Success%22%20%7C%20Out-File%20-FilePath%20%24filePath%20-Append%20%3CBR%20%2F%3E%20exit%20%24true%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%3CH2%20id%3D%22toc-hId--1557651012%22%20id%3D%22toc-hId--1528155779%22%3EParameters%3C%2FH2%3E%3CBR%20%2F%3E%20The%20private%20properties%20are%20passed%20in%20as%20arguments%20to%20the%20PS%20script.%20In%20the%20sample%20scripts%2C%20these%20are%20all%20string%20values.%20You%20can%20potentially%20pass%20in%20different%20value%20types%20with%20more%20advanced%20VB%20script%20magic.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CSTRONG%3ENote%3A%20%3C%2FSTRONG%3E%20Another%20way%20to%20simplify%20this%20is%20by%20writing%20only%20one%20PS%20script%2C%20such%20that%20the%20entry%20points%20are%20all%20functions%2C%20with%20only%20a%20single%20primary%20function%20called%20by%20the%20VB%20script.%20To%20achieve%20this%2C%20you%20can%20pass%20in%20additional%20parameters%20giving%20the%20context%20of%20the%20action%20expected%20(ex%3A%20Online%2C%20Offline%20etc.).%20%3CBR%20%2F%3E%3CH2%20id%3D%22toc-hId-185159323%22%20id%3D%22toc-hId-214654556%22%3EStep-By-Step%20Walk-Through%3C%2FH2%3E%3CBR%20%2F%3E%20Great!%20Now%20that%20you%20have%20the%20VB%20Shell%20%26amp%3B%20Entry%20Point%20Scripts%20ready%2C%20let%E2%80%99s%20make%20the%20application%20highly%20available%E2%80%A6%20%3CBR%20%2F%3E%3CH2%20id%3D%22toc-hId--1481721073%22%20id%3D%22toc-hId--1452225840%22%3ECopy%20VB%20%2B%20PS%20Scripts%20to%20Server%3C%2FH2%3E%3CBR%20%2F%3E%20It%20is%20important%20to%20copy%20the%20VB%20script%20%26amp%3B%20all%20PS%20scripts%20to%20a%20folder%20on%20each%20cluster%20node.%20Ensure%20that%20the%20scripts%20is%20copied%20to%20the%20same%20folder%20on%20all%20cluster%20nodes.%20In%20this%20walk-through%2C%20the%20VB%20%2B%20PS%20scripts%20are%20copied%20to%20%E2%80%9CC%3A%5CSampleScripts%E2%80%9D%20folder%3A%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F90622iBD762D88FC579137%22%20%2F%3E%20%3CBR%20%2F%3E%3CH2%20id%3D%22toc-hId-261089262%22%20id%3D%22toc-hId-290584495%22%3ECreate%20Group%20%26amp%3B%20Resource%3C%2FH2%3E%3CBR%20%2F%3E%20Using%20PowerShell%3A%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F90623iDD0E669809AFB69A%22%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20The%20%E2%80%9CScriptFilePath%E2%80%9D%20private%20property%20gets%20automatically%20added.%20This%20is%20the%20path%20to%20the%20VB%20script%20file.%20There%20are%20no%20other%20private%20properties%20which%20get%20added%20(see%20above).%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20You%20can%20also%20create%20Group%20%26amp%3B%20Resource%20using%20Failover%20Cluster%20Manager%20GUI%3A%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F90624i0168E7AC1CC6DCEA%22%20%2F%3E%20%3CBR%20%2F%3E%3CH2%20id%3D%22toc-hId-2003899597%22%20id%3D%22toc-hId-2033394830%22%3ESpecify%20VB%20Script%3C%2FH2%3E%3CBR%20%2F%3E%20To%20specify%20VB%20script%2C%20set%20the%20%E2%80%9CScriptFilePath%E2%80%9D%20private%20property%20as%3A%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F90626i5AA685036EFC168D%22%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20When%20the%20VB%20script%20is%20specified%2C%20cluster%20automatically%20calls%20the%20Open%20Entry%20Point%20(in%20VB%20script).%20In%20the%20above%20VB%20script%2C%20additional%20private%20properties%20are%20added%20as%20part%20of%20the%20Open%20Entry%20Point.%20%3CBR%20%2F%3E%3CH2%20id%3D%22toc-hId--548257364%22%20id%3D%22toc-hId--518762131%22%3EConfigure%20Private%20Properties%3C%2FH2%3E%3CBR%20%2F%3E%20You%20can%20configure%20the%20private%20properties%20defined%20for%20the%20Generic%20Script%20resource%20as%3A%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F90627i2EBD5D59F3FD61DB%22%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20In%20the%20above%20example%2C%20%E2%80%9CPSScriptsPath%E2%80%9D%20was%20specified%20as%20%E2%80%9CC%3A%5CSampleScripts%E2%80%9D%20which%20is%20the%20folder%20where%20all%20my%20PS%20scripts%20are%20stored.%20Additional%20example%20private%20properties%20like%20Name%2C%20Data1%2C%20Data2%2C%20DataStoragePath%20are%20set%20with%20custom%20values%20as%20well.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20At%20this%20point%2C%20the%20Generic%20Script%20resource%20using%20PS%20scripts%20is%20now%20ready!%20%3CBR%20%2F%3E%3CH2%20id%3D%22toc-hId-1194552971%22%20id%3D%22toc-hId-1224048204%22%3EStarting%20Your%20Application%3C%2FH2%3E%3CBR%20%2F%3E%20To%20start%20your%20application%2C%20you%20simply%20will%20need%20to%20start%20(aka%20online)%20the%20group%20(ex%3A%20SampleGroup)%20or%20resource%20(ex%3A%20SampleResUsingPS).%20You%20can%20start%20the%20group%20or%20resource%20using%20PS%20as%3A%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F90628i9CDED6CB78728F43%22%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20You%20can%20use%20Failover%20Cluster%20Manager%20GUI%20to%20start%20your%20Group%2FRole%20as%20well%3A%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F90629i971CF2CEC87748ED%22%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20To%20view%20your%20application%20state%20in%20Failover%20Cluster%20Manager%20GUI%3A%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F90630i4A05363A516BD61B%22%20%2F%3E%20%3CBR%20%2F%3E%3CH2%20id%3D%22toc-hId--1357603990%22%20id%3D%22toc-hId--1328108757%22%3EVerify%20PS%20script%20output%3A%3C%2FH2%3E%3CBR%20%2F%3E%20In%20the%20sample%20PS%20script%2C%20the%20output%20log%20is%20stored%20in%20the%20same%20directory%20as%20the%20PS%20script%20corresponding%20to%20each%20entry%20point.%20You%20can%20see%20the%20output%20of%20PS%20scripts%20for%20Online%20%26amp%3B%20IsAlive%20Entry%20Points%20below%3A%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F90631i4DA976E2B76A9D08%22%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Awesome!%20Now%2C%20let%E2%80%99s%20see%20what%20it%20takes%20to%20customize%20the%20generic%20scripts%20for%20your%20application.%20%3CBR%20%2F%3E%3CH2%20id%3D%22toc-hId-385206345%22%20id%3D%22toc-hId-414701578%22%3ECustomizing%20Scripts%20For%20Your%20Application%3C%2FH2%3E%3CBR%20%2F%3E%20The%20sample%20VB%20Script%20above%20is%20a%20generic%20shell%20that%20any%20application%20can%20reuse.%20There%20are%20few%20important%20things%20that%20you%20may%20need%20to%20edit%3A%20%3CBR%20%2F%3E%3COL%3E%3CBR%20%2F%3E%3CLI%3EDefining%20Custom%20Private%20Properties%3A%20The%20%E2%80%9CFunction%20Open%E2%80%9D%20in%20the%20VB%20script%20defines%20sample%20private%20properties.%20You%20will%20need%20to%20edit%20those%20add%2Fremove%20private%20properties%20for%20your%20application.%3C%2FLI%3E%3CBR%20%2F%3E%3CLI%3EValidating%20Custom%20Private%20Properties%3A%20The%20%E2%80%9CFunction%20Online%E2%80%9D%2C%20%E2%80%9CFunction%20Offline%E2%80%9D%2C%20%E2%80%9CFunction%20Terminate%E2%80%9D%2C%20%E2%80%9CFunction%20IsAlive%E2%80%9D%20validate%20private%20properties%20whether%20they%20are%20set%20or%20not%20(in%20addition%20to%20being%20required%20or%20not).%20You%20will%20need%20to%20edit%20the%20validation%20checks%20for%20any%20private%20properties%20added%2Fremoved.%3C%2FLI%3E%3CBR%20%2F%3E%3CLI%3ECalling%20the%20PS%20scripts%3A%20The%20%E2%80%9CPSCmd%E2%80%9D%20variable%20contains%20the%20exact%20syntax%20of%20the%20PS%20script%20which%20gets%20called.%20For%20any%20private%20properties%20added%2Fremoved%20you%20would%20need%20to%20edit%20that%20PS%20script%20syntax%20as%20well.%3C%2FLI%3E%3CBR%20%2F%3E%3CLI%3EPowerShell%20scripts%3A%20Parameters%20for%20the%20PowerShell%20scripts%20would%20need%20to%20be%20edited%20for%20any%20private%20properties%20added%2Fremoved.%20In%20addition%2C%20your%20application%20specific%20logic%20would%20need%20to%20be%20added%20as%20specified%20by%20the%20comment%20in%20the%20PS%20scripts.%3C%2FLI%3E%3CBR%20%2F%3E%3C%2FOL%3E%3CBR%20%2F%3E%3CH2%20id%3D%22toc-hId-2128016680%22%20id%3D%22toc-hId--2137455383%22%3ESummary%3C%2FH2%3E%3CBR%20%2F%3E%20Now%20you%20can%20use%20PowerShell%20scripts%20to%20make%20any%20application%20highly%20available%20with%20Failover%20Clusters!!!%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20The%20sample%20VB%20script%20%26amp%3B%20the%20corresponding%20PS%20scripts%20allow%20you%20to%20take%20any%20custom%20application%20%26amp%3B%20make%20it%20highly%20available%20using%20PowerShell%20scripts.%20%3CBR%20%2F%3E%20Thanks%2C%20%3CBR%20%2F%3E%20Amitabh%3C%2FYOUR%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-372101%22%20slang%3D%22en-US%22%3EFirst%20published%20on%20MSDN%20on%20Jun%2006%2C%202016%20Author%3AAmitabh%20Tamhane%20Senior%20Program%20Manager%20Windows%20Server%20MicrosoftOS%20releases%3A%20Applicable%20to%20Windows%20Server%202008%20R2%20or%20laterNow%20you%20can%20use%20PowerShell%20scripts%20to%20make%20any%20application%20highly%20available%20with%20Failover%20Clusters!!!The%20Generic%20Script%20is%20a%20built-in%20resource%20type%20included%20in%20Windows%20Server%20Failover%20Clusters.%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-372101%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3Eamitabh%20tamhane%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Egeneric%20script%20resource%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Epowershell%20script%20resource%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3C%2FLINGO-BODY%3E
Microsoft
First published on MSDN on Jun 06, 2016
Author:
Amitabh Tamhane
Senior Program Manager
Windows Server Microsoft

OS releases: Applicable to Windows Server 2008 R2 or later

Now you can use PowerShell scripts to make any application highly available with Failover Clusters!!!

The Generic Script is a built-in resource type included in Windows Server Failover Clusters. Its advantage is flexibility: you can make applications highly available by writing a simple script. For instance, you can make any PowerShell script highly available! Interested?

We created GenScript in ancient times and it supports only Visual Basic scripts – including Windows Server 2016. This means you can’t directly configure PowerShell as GenScript resource. However, in this blog post, I’ll walk you through a sample Visual Basic script - and associated PS scripts - to build a custom GenScript resource that works well with PowerShell.

Pre-requisites: This blog assumes you have the basic understanding of Windows Server Failover Cluster & built-in resource types.

Disclaimer: Microsoft does not intend to officially support any source code/sample scripts provided as part of this blog. This blog is written only for a quick walk-through on how to run PowerShell scripts using GenScript resource. To make your application highly available, you are expected to modify all the scripts (Visual Basic/PowerShell) as per the needs of your application.

Visual Basic Shell


It so happens that Visual Basic Shell supports calling PowerShell script, then passing parameters and reading output. Here’s a Visual Basic Shell sample that uses some custom Private Properties:


'<your application name> Resource Type

Function Open( )
Resource.LogInformation "Enter Open()"

If Resource.PropertyExists("PSScriptsPath") = False Then
Resource.AddProperty("PSScriptsPath")
End If

If Resource.PropertyExists("Name") = False Then
Resource.AddProperty("Name")
End If

If Resource.PropertyExists("Data1") = False Then
Resource.AddProperty("Data1")
End If

If Resource.PropertyExists("Data2") = False Then
Resource.AddProperty("Data2")
End If

If Resource.PropertyExists("DataStorePath") = False Then
Resource.AddProperty("DataStorePath")
End If

'...Result...
Open = 0

Resource.LogInformation "Exit Open()"
End Function


Function Online( )
Resource.LogInformation "Enter Online()"

'...Check for required private properties...

If Resource.PropertyExists("PSScriptsPath") = False Then
Resource.LogInformation "PSScriptsPath is a required private property."
Online = 1
Exit Function
End If
'...Resource.LogInformation "PSScriptsPath is " & Resource.PSScriptsPath

If Resource.PropertyExists("Name") = False Then
Resource.LogInformation "Name is a required private property."
Online = 1
Exit Function
End If
Resource.LogInformation "Name is " & Resource.Name

If Resource.PropertyExists("Data1") = False Then
Resource.LogInformation "Data1 is a required private property."
Online = 1
Exit Function
End If
'...Resource.LogInformation "Data1 is " & Resource.Data1

If Resource.PropertyExists("Data2") = False Then
Resource.LogInformation "Data2 is a required private property."
Online = 1
Exit Function
End If
'...Resource.LogInformation "Data2 is " & Resource.Data2

If Resource.PropertyExists("DataStorePath") = False Then
Resource.LogInformation "DataStorePath is a required private property."
Online = 1
Exit Function
End If
'...Resource.LogInformation "DataStorePath is " & Resource.DataStorePath

PScmd = "powershell.exe -file " & Resource.PSScriptsPath & "\PS_Online.ps1 " & Resource.PSScriptsPath & " " & Resource.Name & " " & Resource.Data1 & " " & Resource.Data2 & " " & Resource.DataStorePath

Dim WshShell
Set WshShell = CreateObject("WScript.Shell")

Resource.LogInformation "Calling Online PS script= " & PSCmd
rv = WshShell.Run(PScmd, , True)
Resource.LogInformation "PS return value is: " & rv

'...Translate result from PowerShell ...
'...1 (True in PS) == 0 (True in VB)
'...0 (False in PS) == 1 (False in VB)
If rv = 1 Then
Resource.LogInformation "Online Success"
Online = 0
Else
Resource.LogInformation "Online Error"
Online = 1
End If

Resource.LogInformation "Exit Online()"
End Function

Function Offline( )
Resource.LogInformation "Enter Offline()"

'...Check for required private properties...

If Resource.PropertyExists("PSScriptsPath") = False Then
Resource.LogInformation "PSScriptsPath is a required private property."
Offline = 1
Exit Function
End If
'...Resource.LogInformation "PSScriptsPath is " & Resource.PSScriptsPath

If Resource.PropertyExists("Name") = False Then
Resource.LogInformation "Name is a required private property."
Offline = 1
Exit Function
End If
Resource.LogInformation "Name is " & Resource.Name

If Resource.PropertyExists("Data1") = False Then
Resource.LogInformation "Data1 is a required private property."
Offline = 1
Exit Function
End If
'...Resource.LogInformation "Data1 is " & Resource.Data1

If Resource.PropertyExists("Data2") = False Then
Resource.LogInformation "Data2 is a required private property."
Offline = 1
Exit Function
End If
'...Resource.LogInformation "Data2 is " & Resource.Data2

If Resource.PropertyExists("DataStorePath") = False Then
Resource.LogInformation "DataStorePath is a required private property."
Offline = 1
Exit Function
End If
'...Resource.LogInformation "DataStorePath is " & Resource.DataStorePath

PScmd = "powershell.exe -file " & Resource.PSScriptsPath & "\PS_Offline.ps1 " & Resource.PSScriptsPath & " " & Resource.Name & " " & Resource.Data1 & " " & Resource.Data2 & " " & Resource.DataStorePath

Dim WshShell
Set WshShell = CreateObject("WScript.Shell")

Resource.LogInformation "Calling Offline PS script= " & PSCmd
rv = WshShell.Run(PScmd, , True)
Resource.LogInformation "PS return value is: " & rv

'...Translate result from PowerShell ...
'...1 (True in PS) == 0 (True in VB)
'...0 (False in PS) == 1 (False in VB)
If rv = 1 Then
Resource.LogInformation "Offline Success"
Offline = 0
Else
Resource.LogInformation "Offline Error"
Offline = 1
End If

Resource.LogInformation "Exit Offline()"
End Function

Function LooksAlive( )
'...Result...
LooksAlive = 0
End Function

Function IsAlive( )
Resource.LogInformation "Entering IsAlive"

'...Check for required private properties...

If Resource.PropertyExists("PSScriptsPath") = False Then
Resource.LogInformation "PSScriptsPath is a required private property."
IsAlive = 1
Exit Function
End If
'...Resource.LogInformation "PSScriptsPath is " & Resource.PSScriptsPath

If Resource.PropertyExists("Name") = False Then
Resource.LogInformation "Name is a required private property."
IsAlive = 1
Exit Function
End If
Resource.LogInformation "Name is " & Resource.Name

If Resource.PropertyExists("Data1") = False Then
Resource.LogInformation "Data1 is a required private property."
IsAlive = 1
Exit Function
End If
'...Resource.LogInformation "Data1 is " & Resource.Data1

If Resource.PropertyExists("Data2") = False Then
Resource.LogInformation "Data2 is a required private property."
IsAlive = 1
Exit Function
End If
'...Resource.LogInformation "Data2 is " & Resource.Data2

If Resource.PropertyExists("DataStorePath") = False Then
Resource.LogInformation "DataStorePath is a required private property."
IsAlive = 1
Exit Function
End If
'...Resource.LogInformation "DataStorePath is " & Resource.DataStorePath

PScmd = "powershell.exe -file " & Resource.PSScriptsPath & "\PS_IsAlive.ps1 " & Resource.PSScriptsPath & " " & Resource.Name & " " & Resource.Data1 & " " & Resource.Data2 & " " & Resource.DataStorePath

Dim WshShell
Set WshShell = CreateObject("WScript.Shell")

Resource.LogInformation "Calling IsAlive PS script= " & PSCmd
rv = WshShell.Run(PScmd, , True)
Resource.LogInformation "PS return value is: " & rv

'...Translate result from PowerShell ...
'...1 (True in PS) == 0 (True in VB)
'...0 (False in PS) == 1 (False in VB)
If rv = 1 Then
Resource.LogInformation "IsAlive Success"
IsAlive = 0
Else
Resource.LogInformation "IsAlive Error"
IsAlive = 1
End If

Resource.LogInformation "Exit IsAlive()"
End Function

Function Terminate( )
Resource.LogInformation "Enter Terminate()"

'...Check for required private properties...

If Resource.PropertyExists("PSScriptsPath") = False Then
Resource.LogInformation "PSScriptsPath is a required private property."
Terminate = 1
Exit Function
End If
'...Resource.LogInformation "PSScriptsPath is " & Resource.PSScriptsPath

If Resource.PropertyExists("Name") = False Then
Resource.LogInformation "Name is a required private property."
Terminate = 1
Exit Function
End If
Resource.LogInformation "Name is " & Resource.Name

If Resource.PropertyExists("Data1") = False Then
Resource.LogInformation "Data1 is a required private property."
Terminate = 1
Exit Function
End If
'...Resource.LogInformation "Data1 is " & Resource.Data1

If Resource.PropertyExists("Data2") = False Then
Resource.LogInformation "Data2 is a required private property."
Terminate = 1
Exit Function
End If
'...Resource.LogInformation "Data2 is " & Resource.Data2

If Resource.PropertyExists("DataStorePath") = False Then
Resource.LogInformation "DataStorePath is a required private property."
Terminate = 1
Exit Function
End If
'...Resource.LogInformation "DataStorePath is " & Resource.DataStorePath

PScmd = "powershell.exe -file " & Resource.PSScriptsPath & "\PS_Terminate.ps1 " & Resource.PSScriptsPath & " " & Resource.Name & " " & Resource.Data1 & " " & Resource.Data2 & " " & Resource.DataStorePath

Dim WshShell
Set WshShell = CreateObject("WScript.Shell")

Resource.LogInformation "Calling Terminate PS script= " & PSCmd
rv = WshShell.Run(PScmd, , True)
Resource.LogInformation "PS return value is: " & rv

'...Translate result from PowerShell ...
'...1 (True in PS) == 0 (True in VB)
'...0 (False in PS) == 1 (False in VB)
If rv = 1 Then
Terminate = 0
Else
Terminate = 1
End If

Resource.LogInformation "Exit Terminate()"
End Function

Function Close( )
'...Result...
Close = 0
End Function


Entry Points


In the above sample VB script, the following entry points are defined:

  • Open – Ensures all necessary steps complete before starting your application

  • Online – Function to start your application

  • Offline – Function to stop your application

  • IsAlive – Function to validate your application startup and monitor health

  • Terminate – Function to forcefully cleanup application state (ex: Error during Online/Offline)

  • Close – Ensures all necessary cleanup completes after stopping your application


Each of the above entry points is defined as a function (ex: “Function Online( )”). Failover Cluster then calls these entry point functions as part of the GenScript resource type definition.

Private Properties


For resources of any type, Failover Cluster supports two types of properties:

  • Common Properties – Generic properties that can have unique value for each resource

  • Private Properties – Custom properties that are unique to that resource type. Each resource of that resource type has these private properties.


When writing a GenScript resource, you need to evaluate if you need private properties. In the above VB sample script, I have defined five sample private properties (only as an example):

  • PSScriptsPath – Path to the folder containing PS scripts

  • Name

  • Data1 – some custom data field

  • Data2 – another custom data field

  • DataStorePath – path to a common backend store (if any)


The above private properties are shown as example only & you are expected to modify the above VB script to customize it for your application.

PowerShell Scripts


The Visual Basic script simply connects the Failover Clusters’ RHS (Resource Hosting Service) to call PowerShell scripts. You may notice the “PScmd” parameter containing the actual PS command that will be called to perform the action (Online, Offline etc.) by calling into corresponding PS scripts.

For this sample, here are four PowerShell scripts:

  • Online.ps1 – To start your application

  • Offline.ps1 – To stop your application

  • Terminate.ps1 – To forcefully cleanup your application

  • IsAlive.ps1 – To monitor health of your application


Example of PS scripts:

Entry Point: Online


Param(
# Sample properties…
[Parameter(Mandatory=$true, Position=0)]
[ValidateNotNullOrEmpty()]
[string]
$PSScriptsPath,

#
[Parameter(Mandatory=$true, Position=1)]
[ValidateNotNullOrEmpty()]
[string]
$Name,

#
[Parameter(Mandatory=$true, Position=2)]
[ValidateNotNullOrEmpty()]
[string]
$Data1,

#
[Parameter(Mandatory=$true, Position=3)]
[ValidateNotNullOrEmpty()]
[string]
$Data2,

#
[Parameter(Mandatory=$true, Position=4)]
[ValidateNotNullOrEmpty()]
[string]
$DataStorePath
)

$filePath = Join-Path $PSScriptsPath "Output_Online.log"

@"
Starting Online...
Name= $Name
Data1= $Data1
Data2= $Data2
DataStorePath= $DataStorePath
"@ | Out-File -FilePath $filePath

$error.clear()

### Do your online script logic here

if ($errorOut -eq $true)
{
"Error $error" | Out-File -FilePath $filePath -Append
exit $false
}

"Success" | Out-File -FilePath $filePath -Append
exit $true

Entry Point: Offline


Param(
# Sample properties…
[Parameter(Mandatory=$true, Position=0)]
[ValidateNotNullOrEmpty()]
[string]
$PSScriptsPath,

#
[Parameter(Mandatory=$true, Position=1)]
[ValidateNotNullOrEmpty()]
[string]
$Name,

#
[Parameter(Mandatory=$true, Position=2)]
[ValidateNotNullOrEmpty()]
[string]
$Data1,

#
[Parameter(Mandatory=$true, Position=3)]
[ValidateNotNullOrEmpty()]
[string]
$Data2,

#
[Parameter(Mandatory=$true, Position=4)]
[ValidateNotNullOrEmpty()]
[string]
$DataStorePath
)

$filePath = Join-Path $PSScriptsPath "Output_Offline.log"

@"
Starting Offline...
Name= $Name
Data1= $Data1
Data2= $Data2
DataStorePath= $DataStorePath
"@ | Out-File -FilePath $filePath

$error.clear()

### Do your offline script logic here

if ($errorOut -eq $true)
{
"Error $error" | Out-File -FilePath $filePath -Append
exit $false
}

"Success" | Out-File -FilePath $filePath -Append
exit $true


Entry Point: Terminate


Param(
# Sample properties…
[Parameter(Mandatory=$true, Position=0)]
[ValidateNotNullOrEmpty()]
[string]
$PSScriptsPath,

#
[Parameter(Mandatory=$true, Position=1)]
[ValidateNotNullOrEmpty()]
[string]
$Name,

#
[Parameter(Mandatory=$true, Position=2)]
[ValidateNotNullOrEmpty()]
[string]
$Data1,

#
[Parameter(Mandatory=$true, Position=3)]
[ValidateNotNullOrEmpty()]
[string]
$Data2,

#
[Parameter(Mandatory=$true, Position=4)]
[ValidateNotNullOrEmpty()]
[string]
$DataStorePath
)

$filePath = Join-Path $PSScriptsPath "Output_Terminate.log"

@"
Starting Terminate...
Name= $Name
Data1= $Data1
Data2= $Data2
DataStorePath= $DataStorePath
"@ | Out-File -FilePath $filePath

$error.clear()

### Do your terminate script logic here

if ($errorOut -eq $true)
{
"Error $error" | Out-File -FilePath $filePath -Append
exit $false
}

"Success" | Out-File -FilePath $filePath -Append
exit $true


Entry Point: IsAlive


Param(
# Sample properties…
[Parameter(Mandatory=$true, Position=0)]
[ValidateNotNullOrEmpty()]
[string]
$PSScriptsPath,

#
[Parameter(Mandatory=$true, Position=1)]
[ValidateNotNullOrEmpty()]
[string]
$Name,

#
[Parameter(Mandatory=$true, Position=2)]
[ValidateNotNullOrEmpty()]
[string]
$Data1,

#
[Parameter(Mandatory=$true, Position=3)]
[ValidateNotNullOrEmpty()]
[string]
$Data2,

#
[Parameter(Mandatory=$true, Position=4)]
[ValidateNotNullOrEmpty()]
[string]
$DataStorePath
)

$filePath = Join-Path $PSScriptsPath "Output_IsAlive.log"

@"
Starting IsAlive...
Name= $Name
Data1= $Data1
Data2= $Data2
DataStorePath= $DataStorePath
"@ | Out-File -FilePath $filePath

$error.clear()

### Do your isalive script logic here

if ($errorOut -eq $true)
{
"Error $error" | Out-File -FilePath $filePath -Append
exit $false
}

"Success" | Out-File -FilePath $filePath -Append
exit $true


Parameters


The private properties are passed in as arguments to the PS script. In the sample scripts, these are all string values. You can potentially pass in different value types with more advanced VB script magic.

Note: Another way to simplify this is by writing only one PS script, such that the entry points are all functions, with only a single primary function called by the VB script. To achieve this, you can pass in additional parameters giving the context of the action expected (ex: Online, Offline etc.).

Step-By-Step Walk-Through


Great! Now that you have the VB Shell & Entry Point Scripts ready, let’s make the application highly available…

Copy VB + PS Scripts to Server


It is important to copy the VB script & all PS scripts to a folder on each cluster node. Ensure that the scripts is copied to the same folder on all cluster nodes. In this walk-through, the VB + PS scripts are copied to “C:\SampleScripts” folder:


Create Group & Resource


Using PowerShell:



The “ScriptFilePath” private property gets automatically added. This is the path to the VB script file. There are no other private properties which get added (see above).

You can also create Group & Resource using Failover Cluster Manager GUI:


Specify VB Script


To specify VB script, set the “ScriptFilePath” private property as:



When the VB script is specified, cluster automatically calls the Open Entry Point (in VB script). In the above VB script, additional private properties are added as part of the Open Entry Point.

Configure Private Properties


You can configure the private properties defined for the Generic Script resource as:



In the above example, “PSScriptsPath” was specified as “C:\SampleScripts” which is the folder where all my PS scripts are stored. Additional example private properties like Name, Data1, Data2, DataStoragePath are set with custom values as well.

At this point, the Generic Script resource using PS scripts is now ready!

Starting Your Application


To start your application, you simply will need to start (aka online) the group (ex: SampleGroup) or resource (ex: SampleResUsingPS). You can start the group or resource using PS as:



You can use Failover Cluster Manager GUI to start your Group/Role as well:



To view your application state in Failover Cluster Manager GUI:


Verify PS script output:


In the sample PS script, the output log is stored in the same directory as the PS script corresponding to each entry point. You can see the output of PS scripts for Online & IsAlive Entry Points below:



Awesome! Now, let’s see what it takes to customize the generic scripts for your application.

Customizing Scripts For Your Application


The sample VB Script above is a generic shell that any application can reuse. There are few important things that you may need to edit:

  1. Defining Custom Private Properties: The “Function Open” in the VB script defines sample private properties. You will need to edit those add/remove private properties for your application.

  2. Validating Custom Private Properties: The “Function Online”, “Function Offline”, “Function Terminate”, “Function IsAlive” validate private properties whether they are set or not (in addition to being required or not). You will need to edit the validation checks for any private properties added/removed.

  3. Calling the PS scripts: The “PSCmd” variable contains the exact syntax of the PS script which gets called. For any private properties added/removed you would need to edit that PS script syntax as well.

  4. PowerShell scripts: Parameters for the PowerShell scripts would need to be edited for any private properties added/removed. In addition, your application specific logic would need to be added as specified by the comment in the PS scripts.


Summary


Now you can use PowerShell scripts to make any application highly available with Failover Clusters!!!

The sample VB script & the corresponding PS scripts allow you to take any custom application & make it highly available using PowerShell scripts.
Thanks,
Amitabh