Skip to content

Commit

Permalink
Added another update 🥼
Browse files Browse the repository at this point in the history
  • Loading branch information
blakedrumm authored Oct 23, 2023
1 parent 1c87607 commit 127317f
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions Powershell/Export-ScriptsFromMPXML.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,24 @@ function Export-ScriptsFromMPXML

[xml]$xmlcontent = Get-Content $SourceXML

$ExportFullPath = "$ExportLocation\$($SourceXML | Split-Path -Leaf)"
if (Test-Path $ExportFullPath -ErrorAction SilentlyContinue)
{
Write-Host "Found Path"
$ExportLocation = $ExportFullPath
}
else
{
Write-Host "Not found Path"
if (New-Item -ItemType Directory -Path $ExportFullPath -ErrorAction SilentlyContinue)
{
$ExportLocation = $ExportFullPath
}
}


Write-Host "Exporting to folder: $ExportLocation\" -ForegroundColor Cyan

#region Dump-DS-ProbeAction
#This will dump only the scripts which are defined inside Data Source ProbeAction
$probeactions = $xmlcontent.selectnodes('//ManagementPack/TypeDefinitions/ModuleTypes/DataSourceModuleType/ModuleImplementation/Composite/MemberModules/ProbeAction')
Expand Down Expand Up @@ -95,6 +113,44 @@ function Export-ScriptsFromMPXML
}
#endregion Dump-DS-ProbeAction

#region Dump-DS-ProbeAction2
#This will dump only the scripts which are defined inside Data Source ProbeAction
$probeactions = $xmlcontent.selectnodes('//ManagementPack/TypeDefinitions/MonitorTypes/UnitMonitorType/MonitorImplementation/MemberModules/ProbeAction')
if ($probeactions)
{
foreach ($probeaction in $probeactions)
{

if ($probeaction.TypeID -match "PowerShell")
{
$scriptname = $probeaction.ScriptName
Write-Host "Script found. Dumping Script.... " $scriptname -ForegroundColor Green
#write this condition because in some case the developers has added the script extension in the script name itself

if ($scriptname -match ".ps1")
{

$probeaction.scriptbody | Out-File $ExportLocation\$scriptname
}
elseif ($scriptname -match ".vbs")
{
$probeaction.scriptbody | Out-File $ExportLocation\$scriptname
}
elseif ($scriptname -match ".js")
{
$probeaction.scriptbody | Out-File $ExportLocation\$scriptname
}
else
{
$scripttype = $probeaction.ID + "1"
$probeaction.scriptbody | Out-File $ExportLocation\$scriptname.$scripttype
}
}

}
}
#endregion Dump-DS-ProbeAction2

#region Dump-DS-Files
#This script will dump only the scripts which are defined inside Data Source Files/File
$files = $xmlcontent.selectnodes('//ManagementPack/TypeDefinitions/ModuleTypes/DataSourceModuleType/ModuleImplementation/Composite/MemberModules/DataSource/Files/File')
Expand Down

0 comments on commit 127317f

Please sign in to comment.