cancel
Showing results for 
Search instead for 
Did you mean: 
Disclaimer
JUMPCLOUD EXPRESSLY DISCLAIMS ALL REPRESENTATIONS, WARRANTIES, CONDITIONS, AND LIABILITIES OF ANY KIND ARISING FROM OR RELATED TO THIRD-PARTY SOFTWARE, SCRIPTS, REPOSITORIES, AND APIS. JUMPCLOUD IS NOT REQUIRED TO SUPPORT ANY SUCH THIRD-PARTY MATERIALS AND ALL RISKS RELATED TO THIRD-PARTY MATERIALS ARE YOUR RESPONSIBILITY. PLEASE ALSO REVIEW THE JUMPCLOUD TOS.

The Script (GUI) for install JumpCloud agent and bind the user to device (Windows)

boon
New Member

This is the script (GUI) for installing the JumpCloud agent to a Windows device and binding the user to the device.

 

##Include
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope LocalMachine -Force -Confirm:$False
$identity = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = New-Object Security.Principal.WindowsPrincipal $identity
$output = $principal.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
$nettest = Test-Netconnection -Port 443 cdn02.jumpcloud.com | Select-Object -Property TcpTestSucceeded -ExpandProperty TcpTestSucceeded

#Object
$Formobject = [System.Windows.Forms.Form]
$Labelobject = [System.Windows.Forms.Label]
$Buttonobject = [System.Windows.Forms.Button]
$TextBoxobject = [System.Windows.Forms.TextBox]
$Barobject = [System.Windows.Forms.StatusBar]
$Iconobject = [System.Drawing.Icon]
$Pointobject = [System.Drawing.Point]

##Config
$title = "Onboarding Service (JumpCloud)"
$systext = "If the JumpCloud Agent install have ERROR, Please Restart Computer OR Run as administrator"
#### ENTER THE KEY ####
$JumpCloudConnectKey = "ENTER_YOUR_CONNECT_KEY"
$JumpCloudAPIKey = "ENTER_YOUR_API_KEY"
#### THE KEY ####
$versioninfo = "Version 1.3.3"
$textaboutus = "$versioninfo`r`n`r`nHOW TO USE Onboarding Service Tool:`r`n 1. Enter the Computer Name provided by the Admin, Click OK.
2. System will prompt to restart, Click YES.
3. Re-Run the tool, Enter the Username of the employee (without domain) who will use the computer, Click OK.
4. Click Yes to assign the account and install the jumpcloud agent.
5. Click OK. The machine will reboot to complete the account setup.

====================
By Boon - Remote Cloud Engineer
boon.suchathit@techdirect.net"
if($output -ne $true){
[System.Windows.Forms.MessageBox]::Show(" Must run by 'Run as administrator' ",'ADMINISTRATOR!','Ok','Warning')
$outputexit = "1"
}
if($nettest -ne $true){
[System.Windows.Forms.MessageBox]::Show(" Must connect the Internet ",'INTERNET','Ok','Warning')
$outputexit = "1"
}

##Main form Seting
$MainForm = New-Object $Formobject
$MainForm.TopMost = $false
$MainForm.ClientSize = '800,320'
$MainForm.Text = $title
$MainForm.BackColor = "LightSteelBlue"
$MainForm.FormBorderStyle = 'Fixed3D'
$MainForm.MaximizeBox = $false

##Bar
$bar = New-Object $Barobject
$bar.Name = "statusBar"
$bar.Text = $versioninfo
$bar.Font='Consolas,14'

##Button
$btnHelpInfo = New-Object $Buttonobject
$btnHelpInfo.Text = ' Help '
$btnHelpInfo.AutoSize = $true
$btnHelpInfo.Location = New-Object $Pointobject (620,230)
$btnHelpInfo.Font='Segoe UI,12'
$btnHelpInfo.BackColor = "LightCyan"

$btnrenamecomputer = New-Object $Buttonobject
$btnrenamecomputer.Text = 'OK'
$btnrenamecomputer.AutoSize = $true
$btnrenamecomputer.Location = New-Object $Pointobject (483,115)
$btnrenamecomputer.Font='Segoe UI,11'
$btnrenamecomputer.BackColor = "LightCyan"
if($outputexit -eq "1"){$btnrenamecomputer.Enabled = $false}

$btnusername = New-Object $Buttonobject
$btnusername.Text = 'OK'
$btnusername.AutoSize = $true
$btnusername.Location = New-Object $Pointobject (483,175)
$btnusername.Font='Segoe UI,11'
$btnusername.BackColor = "LightCyan"
if($outputexit -eq "1"){$btnusername.Enabled = $false}

##Text
$lbltitle = New-Object $Labelobject
$lbltitle.Text = $title
$lbltitle.AutoSize = $true
$lbltitle.Location = New-Object $Pointobject (90,33)
$lbltitle.Font='Times New Roman,16'
$lbltitle.ForeColor = "MidnightBlue"

$computernametext = New-Object $Labelobject
$computernametext.Text = 'Computer Name:'
$computernametext.AutoSize = $true
$computernametext.Location = New-Object $Pointobject (85,120)
$computernametext.Font='Times New Roman,11'

$usernametext = New-Object $Labelobject
$usernametext.Text = 'Enter Username:'
$usernametext.AutoSize = $true
$usernametext.Location = New-Object $Pointobject (85,180)
$usernametext.Font='Times New Roman,11'

##Textbox
$computernameinput = New-Object $TextBoxobject
$computernameinput.AutoSize = $true
$computernameinput.Location = New-Object $Pointobject (255,120)
$computernameinput.Font = 'Consolas,14'
$computernameinput.Size = '220,35'
$computernameinput.MaxLength = "15"
$readcomname = Get-ComputerInfo | select CsDNSHostName
$computernameinput.Text = $readcomname.CsDNSHostName

$usernameinput = New-Object $TextBoxobject
$usernameinput.AutoSize = $true
$usernameinput.Location = New-Object $Pointobject (255,180)
$usernameinput.Font = 'Consolas,14'
$usernameinput.Size = '220,35'
$usernameinput.MaxLength = "20"


##Add
$MainForm.Controls.AddRange(@($lbltitle))
$MainForm.Controls.AddRange(@($btnHelpInfo))
$MainForm.Controls.AddRange(@($bar))
$MainForm.Controls.AddRange(@($computernametext))
$MainForm.Controls.AddRange(@($computernameinput))
$MainForm.Controls.AddRange(@($btnrenamecomputer))
$MainForm.Controls.AddRange(@($usernameinput))
$MainForm.Controls.AddRange(@($btnusername))
$MainForm.Controls.AddRange(@($usernametext))

##Logic Functions
function info{
$msgBoxInput = [System.Windows.Forms.MessageBox]::Show("$textaboutus",'Help','Ok','None')
}

function renamecomputer{
$msgBoxInput = [System.Windows.Forms.MessageBox]::Show(" Do you confirm to Rename and Restart Computer?",'RENAME','YesNo','Warning')
switch ($msgBoxInput) {
'Yes' {
$cuttext = $computernameinput -replace "System.Windows.Forms.TextBox, Text: ",""
Rename-Computer -NewName $cuttext -Force -Restart
}

'No' {
}

}
}

function usernametext{
$msgBoxInput = [System.Windows.Forms.MessageBox]::Show(" Do you confirm JumpCloud Username account and Install JumpCloud Agent?`r`nThe system will restart after install Agent and assign Username.`r`nThis will take 4 - 5 minutes.`r`n`r`nIf it ask install NuGet, please type Y and enter.`r`nIf it have red error text (in console), please read HELP.",'RENAME','YesNo','Warning')
switch ($msgBoxInput) {
'Yes' {
Write-Host "Install JumpCloud agent" -BackgroundColor Black -ForegroundColor Cyan
# JumpCloud Agent Installation Variables
$msvc2013x64File = 'vc_redist.x64.exe'
$msvc2013x86File = 'vc_redist.x86.exe'
$msvc2013x86Link = 'https://download.microsoft.com/download/0/5/6/056dcda9-d667-4e27-8001-8a0c6971d6b1/vcredist_x86.exe'
$msvc2013x64Link = 'https://download.microsoft.com/download/0/5/6/056dcda9-d667-4e27-8001-8a0c6971d6b1/vcredist_x64.exe'
$TempPath = 'C:\Windows\Temp\'
$msvc2013x86Install = "$TempPath$msvc2013x86File /install /quiet /norestart"
$msvc2013x64Install = "$TempPath$msvc2013x64File /install /quiet /norestart"
$AGENT_PATH = "${env:ProgramFiles}\JumpCloud"
$AGENT_BINARY_NAME = "jcagent-msi-signed.msi"
$AGENT_INSTALLER_URL = "https://cdn02.jumpcloud.com/production/jcagent-msi-signed.msi"
$AGENT_INSTALLER_PATH = "C:\windows\Temp\jcagent-msi-signed.msi"

# JumpCloud Agent Installation Functions
Function AgentIsOnFileSystem() {
Test-Path -Path:(${AGENT_PATH} + '/' + ${AGENT_BINARY_NAME})
}
Function InstallAgent() {
msiexec /i $AGENT_INSTALLER_PATH /quiet JCINSTALLERARGUMENTS=`"-k $JumpCloudConnectKey /VERYSILENT /NORESTART /NOCLOSEAPPLICATIONS /L*V "C:\Windows\Temp\jcUpdate.log"`"
}
Function DownloadAgentInstaller() {
(New-Object System.Net.WebClient).DownloadFile("${AGENT_INSTALLER_URL}", "${AGENT_INSTALLER_PATH}")
}

Function CheckProgramInstalled($programName) {
$installed = (Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Where-Object { $_.DisplayName -match $programName })
if (-not [System.String]::IsNullOrEmpty($installed)) {
return $true
} else {
return $false
}
}

Function DownloadLink($Link, $Path) {
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$WebClient = New-Object -TypeName:('System.Net.WebClient')
$WebClient.DownloadFile("$Link", "$Path")
$WebClient.Dispose()
}


Function DownloadAndInstallAgent(
[System.String]$msvc2013x64Link
, [System.String]$TempPath
, [System.String]$msvc2013x64File
, [System.String]$msvc2013x64Install
, [System.String]$msvc2013x86Link
, [System.String]$msvc2013x86File
, [System.String]$msvc2013x86Install
) {
If (!(CheckProgramInstalled("Microsoft Visual C\+\+ 2013 x64"))) {
Write-Output "Installing JCAgent prereq Visual C++ 2013 x64"
DownloadLink -Link:($msvc2013x64Link) -Path:($TempPath + $msvc2013x64File)
Invoke-Expression -Command:($msvc2013x64Install)
Write-Output "JCAgent Visual C++ 2013 x64 prereq installed"
}
If (!(CheckProgramInstalled("Microsoft Visual C\+\+ 2013 x86"))) {
Write-Output 'Installing JCAgent prereq Visual C++ 2013 x86'
DownloadLink -Link:($msvc2013x86Link) -Path:($TempPath + $msvc2013x86File)
Invoke-Expression -Command:($msvc2013x86Install)
Write-Output 'JCAgent prereq installed'
}
If (!(AgentIsOnFileSystem)) {
Write-Output 'Downloading JCAgent Installer'
# Download Installer
DownloadAgentInstaller
Write-Output 'JumpCloud Agent Download Complete'
Write-Output 'Running JCAgent Installer'
# Run Installer
InstallAgent

}
If (CheckProgramInstalled("Microsoft Visual C\+\+ 2013 x64") -and CheckProgramInstalled("Microsoft Visual C\+\+ 2013 x86") -and AgentIsOnFileSystem) {
Write-Output 'JumpCloud Agent Installer Completed' -BackgroundColor Black -ForegroundColor Cyan
} Else {
Write-Output 'JumpCloud Agent Installer Failed' -BackgroundColor Black -ForegroundColor Red
}
}

#Flush DNS Cache Before Install

ipconfig /FlushDNS

# JumpCloud Agent Installation Logic

DownloadAndInstallAgent -msvc2013x64link:($msvc2013x64Link) -TempPath:($TempPath) -msvc2013x64file:($msvc2013x64File) -msvc2013x64install:($msvc2013x64Install) -msvc2013x86link:($msvc2013x86Link) -msvc2013x86file:($msvc2013x86File) -msvc2013x86install:($msvc2013x86Install)

#########
# Assign User to Device
$username = $usernameinput -replace "System.Windows.Forms.TextBox, Text: ",""

if ((Get-PackageProvider -Name NuGet).version -lt 2.8.5.201 ) {
try {
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Confirm:$False -Force
}
catch [Exception]{
$_.message
exit
}
}
# Install and import the JumpCloud Powershell Module
Write-Host "Installing and Enable the JumpCloud PowerShell Module." -BackgroundColor Black -ForegroundColor Cyan
if (Get-Module -ListAvailable -Name JumpCloud) {
Import-Module -Name JumpCloud -Force
}
else {
try {
Install-Module -Name JumpCloud -Confirm:$False -Force
Import-Module -Name JumpCloud -Force
}
catch [Exception] {
$_.message
exit
}
}
Write-Host "Connecting to AEM JumpCloud tenant." -BackgroundColor Black -ForegroundColor Cyan
Connect-JCOnline -JumpCloudApiKey $JumpCloudAPIKey -Force
Get-JCUser -username $Username -returnProperties email

Start-Sleep -Seconds 60
$agentconf = Get-Content "C:\Program Files\JumpCloud\Plugins\Contrib\jcagent.conf" | ConvertFrom-Json
$agentconf.systemKey
Write-Host "Acquiring the System ID" -BackgroundColor Black -ForegroundColor Cyan
$agentconf = Get-Content "C:\Program Files\JumpCloud\Plugins\Contrib\jcagent.conf" | ConvertFrom-Json
$agentconf.systemKey

Start-Sleep -Seconds 30
Write-Host "Assigning $username to this system as a Standard User" -BackgroundColor Black -ForegroundColor Cyan
Add-JCSystemUser -Username $username -SystemID $agentconf.systemKey -Administrator $False

[System.Windows.Forms.MessageBox]::Show(" You have successfully Onboarded. Click OK to continue. The device will reboot and you're able to login with your JumpCloud credentials. ", "Successfully")

Set-ExecutionPolicy -ExecutionPolicy Undefined -Scope LocalMachine -Force -Confirm:$False
Start-Sleep -Seconds 10
Restart-Computer -Force

}

'No' {
}

}
}
##Add the functions to the form
$btnHelpInfo.Add_Click({info})
$btnrenamecomputer.Add_Click({renamecomputer})
$btnusername.Add_Click({usernametext})

#Display the form
$MainForm.ShowDialog()

#Cleans up the form
$MainForm.Dispose()

 

0 REPLIES 0