Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Set share location and credentials
- $shortcutShare = "\\FileServer1.ad.contoso.com\Share$\DaRT Remoting"
- $username = "ad\ShareUsername"
- $pass = ConvertTo-SecureString -String (Get-Content -Path "X:\Windows\System32\shortcutmap.txt") -AsPlainText -Force
- Remove-Item -Path "X:\Windows\System32\shortcutmap.txt" -Force
- $cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username, $pass
- # Create new drive
- New-PSDrive -Name "Z" -Root $shortcutShare -PSProvider FileSystem -Persist -Credential $cred
- # Start Remote Recovery
- $remoteRecovery = Start-Process "X:\Windows\System32\RemoteRecovery.exe" -ArgumentList "-nomessage" -WindowStyle Minimized -PassThru
- # Wait until the inv32.xml file exists
- While (!(Test-Path -Path "X:\Windows\System32\inv32.xml")) {
- Start-Sleep -Seconds 1
- }
- # Get data from inv32.xml file
- [XML]$inv32XML = Get-Content -Path "X:\Windows\System32\inv32.xml"
- $ticketID = $inv32XML.SelectSingleNode("//A").ID
- $connections = $inv32XML.SelectNodes("//L")
- $port = "3389"
- $connections | ForEach-Object {
- if (($_.N -match "\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}") -and ($_.N -notmatch "169\..+")) {
- $ip = $_.N
- }
- }
- # Check if system is a dell and get service tag, if not, use IP address
- $wmi = Get-WmiObject -Class Win32_ComputerSystem
- if ($wmi.Manufacturer -match "Dell") {
- $idName = "$($ip -replace "\.", "_")-" + (Get-WmiObject -Class Win32_Bios).SerialNumber
- } else {
- $idName = $ip -replace "\.", "_"
- }
- # Set file names
- $filenameDart10 = "DaRT10_$($idName).lnk"
- $filenameDart8 = "DaRT81_$($idName).lnk"
- $filenameDart7 = "DaRT7_$($idName).lnk"
- $targetPathDart10 = "C:\Program Files\Microsoft DaRT\v10\DartRemoteViewer.exe"
- $targetPathDart8 = "C:\Program Files\Microsoft DaRT\v8.1\DartRemoteViewer.exe"
- $targetPathDart7 = "C:\Program Files\Microsoft DaRT 7\v7\DartRemoteViewer.exe"
- # Link C: to X:
- cmd /c subst C: X:\
- # Create temp dart files
- New-Item -Path $targetPathDart10 -ItemType File -Force
- New-Item -Path $targetPathDart8 -ItemType File -Force
- New-Item -Path $targetPathDart7 -ItemType File -Force
- # Create shortcuts
- $shell = New-Object -ComObject WScript.Shell
- $shortcut = $shell.CreateShortcut($filenameDart8)
- $shortcut.TargetPath = $targetPathDart8
- $shortcut.Arguments = "-ticket=$($ticketID) -ipaddress=$($ip) -port=$($port)"
- $shortcut.Save()
- Move-Item -Path $shortcut.FullName -Destination "Z:\" -Force
- $shortcut = $shell.CreateShortcut($filenameDart7)
- $shortcut.TargetPath = $targetPathDart7
- $shortcut.Arguments = "-ticket=$($ticketID) -ipaddress=$($ip) -port=$($port)"
- $shortcut.Save()
- Move-Item -Path $shortcut.FullName -Destination "Z:\" -Force
- $shortcut = $shell.CreateShortcut($filenameDart10)
- $shortcut.TargetPath = $targetPathDart10
- $shortcut.Arguments = "-ticket=$($ticketID) -ipaddress=$($ip) -port=$($port)"
- $shortcut.Save()
- Move-Item -Path $shortcut.FullName -Destination "Z:\" -Force
- # Remove drive link
- cmd /c subst C: /d
- Remove-PSDrive -Name "Z" -Force
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement