Created
May 5, 2017 17:52
-
-
Save elovelan/ecc51ed6c5f1cb1b252acb4b7c611cca to your computer and use it in GitHub Desktop.
Convert MOF 2.0 to MOF 1.0 for PowerShell 4.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param ( | |
$filename | |
) | |
$instanceReplace = @{} | |
$instanceRemove = @("ConfigurationName") | |
$metadataReplace = @{ | |
'Version="[0-9.]*"' = 'Version="1.0.0"' | |
} | |
$metadataRemove = @( | |
"MinimumCompatibleVersion", | |
"CompatibleVersionAdditionalProperties", | |
"Name" | |
) | |
$inInstance = $false; | |
$isMetadata = $false; | |
Get-Content $filename | % { | |
$line = $_ | |
if ($line -match '^ *instance of ([^ ]*)') { | |
$isMetadata = $Matches[1] -eq 'OMI_ConfigurationDocument' | |
$isInstance = $true | |
} elseif ($line -match '^ *}; *$') { | |
$isInstance = $isMetadata = $false | |
} elseif ($isInstance) { | |
$removals = if ($isMetadata) { $metadataRemove } else { $instanceRemove } | |
$replacements = if ($isMetadata) { $metadataReplace } else { $instanceReplace } | |
if (($removals | ? { $line -match "^ *$_ *= *" }).Count -gt 0) { | |
$line = $null | |
} else { | |
$replacements.Keys | % { $line = $line -replace $_, $metadataReplace[$_] } | |
} | |
} | |
$line | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment