Skip to content

Commit

Permalink
Merge pull request #38 from TheJumpCloud/AD-Migration-Windows-Scripts
Browse files Browse the repository at this point in the history
Ad migration tool-kit
  • Loading branch information
scottd3v authored Aug 24, 2018
2 parents ce06d6a + 43d590f commit 96dd54d
Show file tree
Hide file tree
Showing 5 changed files with 186 additions and 0 deletions.
Binary file modified scripts/.DS_Store
Binary file not shown.
4 changes: 4 additions & 0 deletions scripts/windows/AD_migration_toolkit/AccountMigration.Bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
REM This .Bat file launches the AccountMigration.ps1 file as administrtor. Right click and select Run-As Administrator to launch.
REM When migrating a Windows machine from Active Directory to JumpCloud the AccountMigration.bat should be run prior to launching the SystemMigration.Bat
@ECHO OFF
PowerShell.exe -NoProfile -ExecutionPolicy Bypass -Command "& {Start-Process PowerShell.exe -ArgumentList '-ExecutionPolicy Bypass -File ""%~dpn0.ps1""' -Verb RunAs}"
22 changes: 22 additions & 0 deletions scripts/windows/AD_migration_toolkit/AccountMigration.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Domain account migration to local account migration workflow using ProfWiz.msi

# Step 1 create new local user account. This is the account that domain account will be migrated to in 'Step 2'.
# **IMPORTANT** the temp password for new local user account is 'Temp123!'. Update the $TempPassword variable if you wish to change this.

$Username = Read-Host "Enter desired local account username. Users temp password will be 'Temp123!'"
$TempPassword = "Temp123!"
net user /add $Username $TempPassword

# Step 2 download and launch Profwiz
Function DownloadProfwiz($Link, $Path)
{
(New-Object System.Net.WebClient).DownloadFile("$Link", "$Path")
}

$Link = "https://www.forensit.com/Downloads/Profwiz.msi"
$Path = "$PWD\Profwiz.msi"

DownloadProfwiz -Link $Link -Path $Path

# Install Profwiz.msi and use the GUI to migrate the domain account to local user account created in 'Step 1'
Invoke-Item $Path
5 changes: 5 additions & 0 deletions scripts/windows/AD_migration_toolkit/SystemMigration.Bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
REM When migrating a Windows machine from Active Directory to JumpCloud the AccountMigration.bat should be run prior to launching the SystemMigration.Bat
@ECHO OFF
start /B /W wmic.exe /interactive:off ComputerSystem Where "Name='%computername%'" Call UnJoinDomainOrWorkgroup FUnjoinOptions=0
start /B /W wmic.exe /interactive:off ComputerSystem Where "Name='%computername%'" Call JoinDomainOrWorkgroup name="WORKGROUP"
PowerShell.exe -NoProfile -ExecutionPolicy Bypass -Command "& {Start-Process PowerShell.exe -ArgumentList '-ExecutionPolicy Bypass -File ""%~dpn0.ps1""' -Verb RunAs}"
155 changes: 155 additions & 0 deletions scripts/windows/AD_migration_toolkit/SystemMigration.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
# Silent JumpCloud Agent Installation Script

$CONNECT_KEY = "" # <--- paste your organizations connect key between the " ". This key can be found within the JumpCloud admin console on the 'Systems' tab by clicking the green (+) in the top left corner.

# ------- DO NOT MODIFY BELOW THIS LINE ------------------------

# JumpCloud Agent Installation Variables
$AGENT_PATH = "${env:ProgramFiles(x86)}\JumpCloud"
$AGENT_CONF_FILE = "\Plugins\Contrib\jcagent.conf"
$AGENT_BINARY_NAME = "jumpcloud-agent.exe"
$AGENT_SERVICE_NAME = "jumpcloud-agent"
$AGENT_INSTALLER_URL = "https://s3.amazonaws.com/jumpcloud-windows-agent/production/JumpCloudInstaller.exe"
$AGENT_INSTALLER_PATH = "$env:TEMP\JumpCloudInstaller.exe"
$AGENT_UNINSTALLER_NAME = "unins000.exe"
$EVENT_LOGGER_KEY_NAME = "hklm:\SYSTEM\CurrentControlSet\services\eventlog\Application\jumpcloud-agent"
$INSTALLER_BINARY_NAMES = "JumpCloudInstaller.exe,JumpCloudInstaller.tmp"


# Agent Install Helper Functions
Function AgentIsInstalled()
{
$inServiceMgr = AgentIsInServiceManager
$onFileSystem = AgentIsOnFileSystem

$inServiceMgr -Or $onFileSystem
}

Function AgentIsInServiceManager()
{
try
{
$services = Get-Service -Name "${AGENT_SERVICE_NAME}" -ErrorAction Stop
$true
}
catch
{
$false
}
}

Function AgentIsOnFileSystem()
{
Test-Path ${AGENT_PATH}/${AGENT_BINARY_NAME}
}

Function AgentInstallerExists()
{
Test-Path ${AGENT_INSTALLER_PATH}
}

Function InstallAgent()
{
$params = ("${AGENT_INSTALLER_PATH}", "-k ${CONNECT_KEY}", "/VERYSILENT", "/NORESTART", "/SUPRESSMSGBOXES", "/NOCLOSEAPPLICATIONS", "/NORESTARTAPPLICATIONS", "/LOG=$env:TEMP\jcUpdate.log")
Invoke-Expression "$params"
}

Function AgentIsInstalled()
{
$inServiceMgr = AgentIsInServiceManager
$onFileSystem = AgentIsOnFileSystem

$inServiceMgr -Or $onFileSystem
}

Function DownloadAgentInstaller()
{
(New-Object System.Net.WebClient).DownloadFile("${AGENT_INSTALLER_URL}", "${AGENT_INSTALLER_PATH}")
}

# JumpCloud Agent Install
Function DownloadAndInstallAgent()
{
$agentIsInstalled = AgentIsInstalled
if (-Not $agentIsInstalled)
{
Write-Host -nonewline "Downloading agent installer..."

DownloadAgentInstaller

if (AgentInstallerExists)
{
Write-Host " complete."

Write-Host -nonewline "Installing agent..."
InstallAgent
Start-Sleep -s 5
$exitCode = $?
$agentIsInstalled = AgentIsInstalled

Write-Host " complete. (exit code=$exitCode)"

if ($exitCode -ne $true)
{
Write-Error "Agent installation failed. Please rerun this script,`nand if that doesn't work, please reboot and try again.`nIf neither work, please contact support@jumpcloud.com"
exit 1
}
else
{
Write-Host "`n* * * SUCCESS! Agent installation complete. * * *"
Start-Sleep -s 2
}
}
else
{
Write-Error "Could not download agent installer from ${AGENT_INSTALLER_URL}. Install FAILED."
exit 1
}
}
else
{
Write-Host "Agent is already installed, not installing again."
}
}

Function ForceRebootComputerWithDelay
{
Param(
[int]$TimeOut = 5
)
$continue = $true

while ($continue)
{
if ([console]::KeyAvailable)
{
Write-Host "Restart Canceled by key press"
Exit
}
else
{
Write-Host "Press any key to cancel... restarting in $TimeOut" -NoNewLine
Start-Sleep -Seconds 1
$TimeOut = $TimeOut - 1
Clear-Host
if ($TimeOut -eq 0)
{
$continue = $false
$Restart = $true
}
}
}
if ($Restart -eq $True)
{
Write-Host "Restarting Computer..."
Restart-Computer -ComputerName $env:COMPUTERNAME -Force
}
}

DownloadAndInstallAgent

if ($?)
{
ForceRebootComputerWithDelay
}

0 comments on commit 96dd54d

Please sign in to comment.