Skip to content

Instantly share code, notes, and snippets.

@elovelan
Created May 5, 2017 17:52
Show Gist options
  • Save elovelan/ecc51ed6c5f1cb1b252acb4b7c611cca to your computer and use it in GitHub Desktop.
Save elovelan/ecc51ed6c5f1cb1b252acb4b7c611cca to your computer and use it in GitHub Desktop.
Convert MOF 2.0 to MOF 1.0 for PowerShell 4.0
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