asafgb

getData-powershell

Feb 23rd, 2021 (edited)
541
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $list = Get-AdComputer -Filter *
  2. #Get-Content "path/to/list.txt"
  3.  
  4.  
  5. foreach($computer in $list.name)
  6. {
  7.     Invoke-Command -ComputerName $computer  -ScriptBlock {
  8.        cmd /c 'DXDIAG /dontskip /X C:\temp\DeviceData.xml'
  9.     }
  10.  
  11.  
  12.     [xml] $xml = Get-Content -Path "\\$($computer)\c$\temp\DeviceData.xml"
  13.     <#
  14.     כאן אתה כבר בתוך הקובץ עצמו
  15.     כלומר יש לך את כל המידע החומרתי של המחשב
  16.     אם ה
  17.     xml
  18.     לא ברור
  19.     אתה יכול לעשות לו formatter
  20.     https://www.freeformatter.com/xml-formatter.html#ad-output
  21.     הוא יראה יותר נחמד
  22.     ואז אתה יכול לגשת לכל הפרמטרים דרך ה $xml
  23.  
  24.     דוגמה
  25.     $xml.DxDiag.SystemInformation.BIOS
  26.     #>
  27.  
  28.     $officeData=Invoke-Command -ComputerName $computer  -ScriptBlock {
  29.         $folder = Get-ChildItem 'C:\Program Files (x86)\Microsoft Office\Office*'
  30.         cscript "$($folder.FullName)\ospp.vbs" /dstatus
  31.     }
  32.  
  33.      $string=for($i=3;$i -lt $officeData.Count;$i++)
  34.      {
  35.             if($officeData[$i] -like "*:*")
  36.             {
  37.                 $split = $officeData[$i].split(":")
  38.                 "`"$($split[0].Trim())`":`"$($split[1].Trim())`","
  39.             }
  40.             else
  41.             {
  42.                 $officeData[$i]
  43.             }
  44.      }
  45.  
  46.     $string=$string | Out-String
  47.     $string=$string.Replace("---Processing--------------------------
  48. ---------------------------------------","[{").Replace("---------------------------------------
  49. ---------------------------------------
  50. ---Exiting-----------------------------","}]")
  51.     $string=$string.Replace("---------------------------------------","},{")
  52.    $string=$string.Replace(",
  53. }","}")
  54.    
  55.    $json = $string | ConvertFrom-Json
  56.  
  57.    <#
  58.    כאן יש לך את כל המוצרי office
  59.    שיש לך על העמדה
  60.    #>
  61.  
  62.    # product key
  63.     $WindowsActivationKey=Invoke-Command -ComputerName $computer  -ScriptBlock {
  64.         powershell "(Get-WmiObject -query ‘select * from SoftwareLicensingService’).OA3xOriginalProductKey"
  65.     }
  66.  
  67.    
  68.  
  69. }
Add Comment
Please, Sign In to add comment