Advertisement
easternnl

Using XML in PowerShell together with SCCM task sequence var

May 10th, 2016
519
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $tsenv = New-Object -COMObject Microsoft.SMS.TSEnvironment
  2.  
  3. # inline xml:
  4. $xml = [xml]@"
  5. <workplaces>
  6.   <computer id="F">
  7.      <ou></ou>
  8.      <title>Flexible</title>      
  9.   </computer>
  10.   <computer id="B">
  11.       <ou></ou>  
  12.      <title>Business</title>      
  13.   </computer>
  14. </workplaces>
  15. "@
  16.  
  17. # xml in file:
  18. $xml = [xml](gc "testfile.xml")
  19.  
  20. # read computer type from the task sequence
  21. $workplace= $tsenv.Value("Workplace")
  22.  
  23. # query the xml
  24. $title = ($xml.workplaces.computer | where { $_.id -ieq "B" }).title
  25. $ou = ($xml.workplaces.computer | where { $_.id -ieq "$workplace" }).ou
  26.  
  27. # write SCCM task sequence variabele
  28. $tsenv.Value("OU") = $ou
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement