2014-07-22 40 views
1

我甚至不知道從哪裏開始,但可以使用哪些powershell cmdlet可以在MDT xml(OperatingSystem.xml)中讀取下面的格式,只是搶GUID值(或值)$ captureGUID =「{1a65f870-2247-410a-be71-75b6b975b3d5}」PowerShell命令在xml文件中選取一個值並將其替換爲另一個xml

<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"> 

從以捕獲值早,更換上另一個XML文件以不同的格式(例如,在此更新OSGUID)

<?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" /> 

回答

0

爲此,您可以在PowerShell中,你只需要在第一個GUID?因爲你的第一和第二個GUID是不同的。你需要使用正則表達式。像這樣的東西應該工作。

$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") 

您需要更改$ ReplacementXML的獲取內容部分是要導入的GUID你的第二個XML文件的名稱。然後對最後一行也一樣,將Save位置的名稱更改爲同一文件的名稱,我使用了2個獨立的名稱來驗證輸出的輸入。

相關問題