Last active
June 11, 2018 06:24
-
-
Save danjpadgett/40db174ffef01032dde10285ad48082c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#requires -version 2 | |
<# | |
.SYNOPSIS | |
Creates dart shortcuts in SCCM Share | |
.DESCRIPTION | |
Creates dart shortcuts in SCCM Share | |
.PARAMETER <Parameter_Name> | |
None | |
.INPUTS | |
None | |
.OUTPUTS | |
None | |
.NOTES | |
Version: 4.0 | |
Author: dpadgett | |
Creation Date: 270617 | |
Purpose/Change: Initial script development | |
.EXAMPLE | |
Edit lines 23,42 - include AES.key and password.txt file as seen in line 34&35. | |
See here for info on pw encryption: https://www.pdq.com/blog/secure-password-with-powershell-encrypting-credentials-part-2/ | |
#> | |
$siteserver = "sccmserver.contoso.com" | |
#Wait for network | |
do { | |
Write-Host "Starting Dart - Waiting for Network To Be Ready....". -ForegroundColor Yellow | |
sleep 3 | |
} until(Test-Connection -computer $siteserver | ? { $_.StatusCode -like "0" } ) | |
#Get Credentials | |
$User = "DOMAIN\<accountname>" | |
$PasswordFile = ".\WinPE_DarT-PasswordAES.txt" | |
$KeyFile = ".\WinPE_DarT-AES.key" | |
$key = Get-Content $KeyFile | |
$cred = New-Object -TypeName System.Management.Automation.PSCredential ` | |
-ArgumentList $User, (Get-Content $PasswordFile | ConvertTo-SecureString -Key $key) | |
# Set share location and credentials | |
$shortcutShare = "\\servershare.contoso.com\RemoteControl" | |
Remove-Item -Path $KeyFile -Force -ErrorAction SilentlyContinue | |
#$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username, $pass | |
# Create new drive | |
Write-Host "Connecting to share..." -ForegroundColor Yellow | |
New-PSDrive -Name "Z" -Root $shortcutShare -PSProvider FileSystem -Persist -Credential $cred | |
# Start Remote Recovery | |
Write-Host "Launching Dart" -ForegroundColor Yellow | |
$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 system for name formatting | |
Write-Host "Creating Shortcuts" -ForegroundColor Yellow | |
$wmi = Get-WmiObject -Class Win32_ComputerSystem | |
if (($wmi.Manufacturer -match "Hewlett-Packard") -or ($wmi.Manufacturer -match "HP")) { | |
$idName = "HP-"+(Get-WmiObject -Class Win32_Bios).SerialNumber.substring(3)+"-"+$(get-date -uformat "%d%m%y-%H%M")} | |
elseif ($wmi.Manufacturer -match "Dell Inc.") { | |
$idName = "Dell-"+(Get-WmiObject -Class Win32_Bios).SerialNumber+"-"+$(get-date -uformat "%d%m%y-%H%M")} | |
elseif ($wmi.Manufacturer -match "Microsoft") { | |
$idName = "Microsoft-"+(Get-WmiObject -Class Win32_Bios).SerialNumber+"-"+$(get-date -uformat "%d%m%y-%H%M")} | |
elseif ($wmi.Manufacturer -match "VMware") { | |
$idName = "VMWare-"+$(get-date -uformat "%d%m%y-%H%M")} | |
else { | |
$idName = "Unknown-"+$($ip -replace "\.", "-")} | |
Write-Host "Shortcut name will be $idName" -ForegroundColor Yellow | |
# Set file names | |
$filenameDart10 = "$($idName).lnk" | |
$targetPathDart10 = "C:\Program Files\Microsoft DaRT\v10\DartRemoteViewer.exe" | |
# Link C: to X: | |
cmd /c subst C: X:\ | |
# Create temp dart files | |
New-Item -Path $targetPathDart10 -ItemType File -Force | |
#Create shortcuts | |
$shell = New-Object -ComObject WScript.Shell | |
#Dart10 Code | |
$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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment