1

I don't even know where to begin, but what powershell cmdlet can I used that can read in a a MDT xml (OperatingSystem.xml) in the following format, and grab just the GUID value (or values) $captureGUID = "{1a65f870-2247-410a-be71-75b6b975b3d5}"

<oss>
  <os guid="{1a65f870-2247-410a-be71-75b6b975b3d5}" enable="True">
  <Name>Windows 7 ENTERPRISE in Windows 7 Ent x64 install.wim</Name> 
  <CreatedTime>7/21/2014 8:51:10 PM</CreatedTime> 
  <CreatedBy>W2K8R2\Administrator</CreatedBy> 
  <LastModifiedTime>7/21/2014 8:51:10 PM</LastModifiedTime> 
  <LastModifiedBy>W2K8R2\Administrator</LastModifiedBy> 
  <Description>Windows 7 ENTERPRISE</Description> 
  <Platform>x64</Platform> 
  <Build>6.1.7601.17514</Build> 
  <OSType>Windows IBS</OSType> 
  <Source>.\Operating Systems\Windows 7 Ent x64</Source> 
  <IncludesSetup>True</IncludesSetup> 
  <SMSImage>False</SMSImage> 
  <ImageFile>.\Operating Systems\Windows 7 Ent x64\Sources\install.wim</ImageFile> 
  <ImageIndex>1</ImageIndex> 
  <ImageName>Windows 7 ENTERPRISE</ImageName> 
  <Flags>Enterprise</Flags> 
  <HAL>acpiapic</HAL> 
  <Size>11566</Size> 
  <Language>en-US</Language> 
  </os>
<os guid="{67ee1204-ba8f-47d4-9e6c-34a7bb24dd4d}" enable="True">

Take the captured value from earlier and replace it on another xml file in a different format (e.g. update the OSGUID here)

  <?xml version="1.0" encoding="utf-8" ?> 
  <sequence version="3.00" name="Standard Client Task Sequence" description="A complete task sequence for deploying a client operating system">
    <globalVarList>
      <variable name="OSGUID" property="OSGUID">{bc8e6992-5890-4be2-88af-29208f9ab0d5}</variable> 
      <variable name="DestinationDisk" property="DestinationDisk">0</variable> 
      <variable name="DestinationPartition" property="DestinationPartition">1</variable> 
      <variable name="DestinationOSVariable" property="DestinationOSVariable" /> 
Dominic
  • 11
  • 1

2 Answers2

0

PowerShell is the wrong tool for the job. You should create an XSLT transformation. Using XSLT you can find a specific node and easily write it to another XML sheet --- or any other kind of document for that matter.

Here is just one of several examples you can find on StackOverflow:
XSLT or XPath: how to find a node with a specific tag and text then extract it into a new xml file?

Community
  • 1
  • 1
Jason Enochs
  • 1,436
  • 1
  • 13
  • 20
0

You can do this in Powershell, do you need only the first guid? Because your first and second guid are different. You would need to use Regex. Something like this should work.

$OSXML = Get-Content OperatingSystem.xml
$regex = 'guid=\"(\{\w+\-\w+\-\w+\-\w+\-\w+\})\"'
ForEach ($Line in $OSXML)
{   $Line -match $regex
}
$captureGUID = $Matches[1]

$ReplacementXML = [xml](Get-Content "NewXML.xml")

($ReplacementXML.sequence.globalVarList.variable | Where-Object { $_.Name -eq "OSGUID" }).'#text' = $captureGUID

$ReplacementXML.Save("C:\Test\NewXML2.xml")

You will need to change The Get-Content part of $ReplacementXML to be the name of your second xml file that you want to import the GUID to. And then the same for the last line, change the name of the Save location to the name of the same file, I used 2 separate names to verify the import with the output.

chamele0n
  • 95
  • 3
  • 11