Name = "Acme Server Location"
Start Group
Name = "Acme Server Location"
ID = 1
Class = "Acme Server Location"
Start Attribute
Name = "Admin Contact"
ID = 4
Type = String(50)
Value = "Chad Miller"
End Attribute
Start Attribute
Name = "Admin Phone"
ID = 5
Type = String(40)
Value = "55500"
End Group
End Component
#######################
function ConvertTo-MIFXml
{
param ($mifFile)
$mifText = gc $mifFile |
#Remove illegal XML characters
% { $_ -replace "&", "&" } |
% { $_ -replace"'", "'" } |
% { $_ -replace "<", "<" } |
% { $_ -replace ">", ">" } |
#Create Component attribute
% { $_ -replace 'Start Component','<Component' } |
#Create Group attribute
% { $_ -replace 'Start Group','><Group' } |
#Create Attribute attribute
% { $_ -replace 'Start Attribute','><Attribute' } |
#Create closing tags
% { $_ -replace 'End Attribute','></Attribute>' } |
% { $_ -replace 'End Group','</Group>' } |
% { $_ -replace 'End Component','</Component>'} |
#Remove all quotes
% { $_ -replace '"' } |
#Remove MIF comments. MIF Comments start with //
% { $_ -replace "(\s*//\s*.*)" } |
#Extract name/value and quote value
% { $_ -replace "\s*([^\s]+)\s*=\s*(.+$)",'$1="$2"' } |
#Replace tabs with spaces
% { $_ -replace "\t", " " } |
#Replace 2 spaces with 1
% { $_ -replace "\s{2,}", " " }
#Join the array, cleanup some spacing and extra > signs
[xml]$mifXml = [string]::Join(" ", $mifText) -replace ">\s*>",">" -replace "\s+>",">"
return $mifXml
} #ConvertTo-MIFXml
#######################
ConvertTo-MIFXml $fileName | foreach {$_.component} | foreach {$_.Group} | foreach {$_.Attribute} | select @{n='SystemName';e={$computerName}}, `
@{n='Component';e={$($_.psbase.ParentNode).psbase.ParentNode.name}}, @{n='Group';e={$_.psbase.ParentNode.name}}, `
@{n='FileName';e={[System.IO.Path]::GetFileName($FileName)}}, ID, Name, Value
DISTINCT SMS_R_System.Name0,
CASE
WHEN SMS_G_System_OS.Name0 LIKE '%x64%' THEN '\\' + SMS_R_System.Name0 + '\c$\WINDOWS\SysWOW64\CCM\Inventory\noidmifs\*.mif'
ELSE '\\' + SMS_R_System.Name0 + '\c$\WINDOWS\System32\CCM\Inventory\noidmifs\*.mif'
END AS OS
FROM SMS_Acme.dbo.System_DISC AS SMS_R_System
JOIN SMS_Acme.dbo.Operating_System_DATA AS SMS_G_System_OS
ON SMS_G_System_OS.MachineID = SMS_R_System.ItemKey
[SystemName] [varchar](1000) NULL,
[Component] [varchar](1000) NULL,
[Group] [varchar](1000) NULL,
[FileName] [varchar](1000) NULL,
[ID] [varchar](1000) NULL,
[Name] [varchar](1000) NULL,
[Value] [varchar](1000) NULL
);
FROM 'C:\Users\u00\Desktop\mif.csv'
WITH ( FIELDTERMINATOR =',',
ROWTERMINATOR ='\n')