Advertisement
Guest User

Create DaRT Shortcut

a guest
Jan 27th, 2016
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Set share location and credentials
  2. $shortcutShare = "\\FileServer1.ad.contoso.com\Share$\DaRT Remoting"
  3. $username = "ad\ShareUsername"
  4. $pass = ConvertTo-SecureString -String (Get-Content -Path "X:\Windows\System32\shortcutmap.txt") -AsPlainText -Force
  5. Remove-Item -Path "X:\Windows\System32\shortcutmap.txt" -Force
  6. $cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username, $pass
  7.  
  8. # Create new drive
  9. New-PSDrive -Name "Z" -Root $shortcutShare -PSProvider FileSystem -Persist -Credential $cred
  10.  
  11. # Start Remote Recovery
  12. $remoteRecovery = Start-Process "X:\Windows\System32\RemoteRecovery.exe" -ArgumentList "-nomessage" -WindowStyle Minimized -PassThru
  13.  
  14. # Wait until the inv32.xml file exists
  15. While (!(Test-Path -Path "X:\Windows\System32\inv32.xml")) {
  16.     Start-Sleep -Seconds 1
  17. }
  18.  
  19. # Get data from inv32.xml file
  20. [XML]$inv32XML = Get-Content -Path "X:\Windows\System32\inv32.xml"
  21. $ticketID = $inv32XML.SelectSingleNode("//A").ID
  22. $connections = $inv32XML.SelectNodes("//L")
  23. $port = "3389"
  24.  
  25. $connections | ForEach-Object {
  26.     if (($_.N -match "\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}") -and ($_.N -notmatch "169\..+")) {
  27.         $ip = $_.N
  28.     }
  29. }
  30.  
  31. # Check if system is a dell and get service tag, if not, use IP address
  32. $wmi = Get-WmiObject -Class Win32_ComputerSystem
  33.  
  34. if ($wmi.Manufacturer -match "Dell") {
  35.     $idName = "$($ip -replace "\.", "_")-" + (Get-WmiObject -Class Win32_Bios).SerialNumber
  36. } else {
  37.     $idName = $ip -replace "\.", "_"
  38. }
  39.  
  40. # Set file names
  41. $filenameDart10 = "DaRT10_$($idName).lnk"
  42. $filenameDart8 = "DaRT81_$($idName).lnk"
  43. $filenameDart7 = "DaRT7_$($idName).lnk"
  44. $targetPathDart10 = "C:\Program Files\Microsoft DaRT\v10\DartRemoteViewer.exe"
  45. $targetPathDart8 = "C:\Program Files\Microsoft DaRT\v8.1\DartRemoteViewer.exe"
  46. $targetPathDart7 = "C:\Program Files\Microsoft DaRT 7\v7\DartRemoteViewer.exe"
  47.  
  48. # Link C: to X:
  49. cmd /c subst C: X:\
  50.  
  51. # Create temp dart files
  52. New-Item -Path $targetPathDart10 -ItemType File -Force
  53. New-Item -Path $targetPathDart8 -ItemType File -Force
  54. New-Item -Path $targetPathDart7 -ItemType File -Force
  55.  
  56. # Create shortcuts
  57. $shell = New-Object -ComObject WScript.Shell
  58.  
  59. $shortcut = $shell.CreateShortcut($filenameDart8)
  60. $shortcut.TargetPath = $targetPathDart8
  61. $shortcut.Arguments = "-ticket=$($ticketID) -ipaddress=$($ip) -port=$($port)"
  62. $shortcut.Save()
  63.  
  64. Move-Item -Path $shortcut.FullName -Destination "Z:\" -Force
  65.  
  66. $shortcut = $shell.CreateShortcut($filenameDart7)
  67. $shortcut.TargetPath = $targetPathDart7
  68. $shortcut.Arguments = "-ticket=$($ticketID) -ipaddress=$($ip) -port=$($port)"
  69. $shortcut.Save()
  70.  
  71. Move-Item -Path $shortcut.FullName -Destination "Z:\" -Force
  72.  
  73. $shortcut = $shell.CreateShortcut($filenameDart10)
  74. $shortcut.TargetPath = $targetPathDart10
  75. $shortcut.Arguments = "-ticket=$($ticketID) -ipaddress=$($ip) -port=$($port)"
  76. $shortcut.Save()
  77.  
  78. Move-Item -Path $shortcut.FullName -Destination "Z:\" -Force
  79.  
  80. # Remove drive link
  81. cmd /c subst C: /d
  82.  
  83. Remove-PSDrive -Name "Z" -Force
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement