URLGenie.DisableWatcherNode.POSH.Write.DS (WriteActionModuleType)

Element properties:

TypeWriteActionModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
InputTypeSystem.BaseData
OutputTypeMicrosoft.Windows.SerializedObjectData

Member Modules:

ID Module Type TypeId RunAs 
POSH WriteAction Microsoft.Windows.PowerShellWriteAction Default

Source Code:

<WriteActionModuleType ID="URLGenie.DisableWatcherNode.POSH.Write.DS" Accessibility="Internal" Batching="false">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="KeyName" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="TimeoutSeconds" type="xsd:integer"/>
</Configuration>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<WriteAction ID="POSH" TypeID="Windows!Microsoft.Windows.PowerShellWriteAction">
<ScriptName>DisableURLGenieWatcher.ps1</ScriptName>
<ScriptBody><Script>#========================================================================
# Created on: 5/14/2013 6:23 PM
# Created by: Tyson Paul ( https://blogs.msdn.microsoft.com/tysonpaul/ )
# Organization:
# Filename: DisableURLGenieWatcher.ps1
# Version: 2018.08.07: Small formatting changes.
# 2013.5.14.1823: Original
# Description: Will remove registry key and value/data so host will NOT be detected as URLGenie watcher node
#========================================================================

Param(
[string]$Keyname='SOFTWARE\Microsoft\Microsoft Operations Manager\MP\URLGenie\MgmtGroups\$Target/ManagementGroup/Name$' # Name/path of registry key under which to create the entry/string for the config file folder path.
)

###############################################################################
# Function: Test-RegSubKey
# Description: Test the existence of the registry key
# Return Value: True/false respectively

Function Test-RegSubKey{
Param(
[string]$server = ".",
[string]$hive,
[string]$keyName
)

$hives = [enum]::getnames([Microsoft.Win32.RegistryHive])

If($hives -notcontains $hive){
write-error "Invalid hive value";
Return;
}
$regHive = [Microsoft.Win32.RegistryHive]$hive;
$regKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($regHive,$server);
$subKey = $regKey.OpenSubKey($keyName);

If(!$subKey){$false} else {$true}
}
###############################################################################
Function Get-RegString{
Param(
[string]$server = ".",
[string]$hive,
[string]$keyName,
[string]$valueName,
[object]$defaultValue="Your default value"
)
$hives = [enum]::getnames([Microsoft.Win32.RegistryHive])
If($hives -notcontains $hive){
write-error "Invalid hive value";
Return;
}
$regHive = [Microsoft.Win32.RegistryHive]$hive;
$regKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($regHive,$server);
$subKey = $regKey.OpenSubKey($keyName);

If(!$subKey){
write-error "The specified registry key does not exist.";
Return;
}
$subKey.GetValue($valueName,$defaultValue);
}
###############################################################################
# Function: New-RegSubKey
# Description: Create the registry key
# Return Value: True/false respectively

Function New-RegSubKey{
Param(
[string]$server = ".",
[string]$hive,
[string]$keyName
)

$hives = [enum]::getnames([Microsoft.Win32.RegistryHive])

If($hives -notcontains $hive){
write-error "Invalid hive value";
Return;
}
$regHive = [Microsoft.Win32.RegistryHive]$hive;
$regKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($regHive,$server);
[void]$regKey.CreateSubKey($keyName);
If($?) {$true} else {$false}
}
###############################################################################
# Function: Set-RegString
# Description: Create/Update the registry value (REG_SZ)
# Return Value: True/false respectively

Function Remove-RegKey{
Param(
[string]$server = ".",
[string]$hive,
[string]$Keyname
)

$hives = [enum]::getnames([Microsoft.Win32.RegistryHive])

If($hives -notcontains $hive){
write-error "Invalid hive value";
Return;
}
$regHive = [Microsoft.Win32.RegistryHive]$hive;
$regKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($regHive,$server);
$regKey.DeleteSubKey($Keyname,$True)

If($?) {$true} else {$false}
}
###############################################################################
Function LogIt ([int]$EventID, [int]$Type=2, [string]$Message="No message specified.",[string]$Proceed ) {
#Types: 0:Info, 1:Error, 2:Warning

$TimeStamp = (get-date -format "yyyy-MM-dd-HHmmss")
$oEvent.LogScriptEvent("$ThisScript",$EventID,$Type,"$ThisScript
Message: $Message
Hive: $Hive
Key: $Keyname
Valuename: $ConfigFilesPath
Valuedata: $Result ")
}
###############################################################################

$Valuename = "ConfigFilesPath"
$Hive = "LocalMachine"
[string]$ThisScript=$($myinvocation.mycommand.name)
$api = New-Object -comObject 'MOM.ScriptAPI'
$oEvent = New-Object -comObject "MOM.ScriptAPI"

If (Test-RegSubKey -hive $Hive -keyName $Keyname ) {
Write-Output "Key found: $Hive , $Keyname"
}
Else{
Write-Output "Key not found in registry: $Hive , $Keyname"
Exit
}

$result = Remove-RegKey -hive $Hive -keyName $Keyname

If (-NOT(Test-RegSubKey -hive $Hive -keyName $Keyname) ) {
Write-Output "Success! Key removed from registry: $Hive , $Keyname"
LogIt -EventID 9995 -Type 2 -Proceed "true" -Message "Registry key has been removed: $hive , $keyname"
}
Else{
Write-Output "Failure! Key still exists in registry: $Hive , $Keyname"
LogIt -EventID 9995 -Type 2 -Proceed "true" -Message "URLGenie Watcher Node registry key removal failed:"
}</Script></ScriptBody>
<Parameters>
<Parameter>
<Name>KeyName</Name>
<Value>$Config/KeyName$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</WriteAction>
</MemberModules>
<Composition>
<Node ID="POSH"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>Windows!Microsoft.Windows.SerializedObjectData</OutputType>
<InputType>System!System.BaseData</InputType>
</WriteActionModuleType>