Commit 66f6cae8 authored by Jos Lieben's avatar Jos Lieben

automatically restart in x64 (intune runs x86 by default)

parent 34a74fb8
......@@ -2,9 +2,10 @@
#Author: Jos Lieben (OGD)
#Author Company: OGD (http://www.ogd.nl)
#Author Blog: http://www.lieben.nu
#Date: 12-02-2018
#Date: 13-02-2018
#Purpose: Configure Onedrive for Business (Onedrive.exe) to silently link to the user's business tenant, and optionally redirect known folders to desired subfolders
#Requirements: Windows 10, Powershell script should run as an Admin if O4B wasn't installed yet
#Requirements: Windows 10
#Instructions: http://www.lieben.nu/liebensraum/o4bclientautoconfig/
#Mentions / articles used:
#@Per Larsen for writing on silent auto config: https://osddeployment.dk/2017/12/18/how-to-silently-configure-onedrive-for-business-with-intune/
......@@ -13,6 +14,17 @@
#https://support.office.com/en-us/article/deploy-the-new-onedrive-sync-client-in-an-enterprise-environment-3f3a511c-30c6-404a-98bf-76f95c519668
#http://www.lieben.nu/liebensraum/o4bclientautoconfig/
Param(
[Switch]$in64Bit #Intune starts Powershell processes in 32 bit mode, can't have that!
)
#Restart self in x64
If (!$in64Bit){
$arguments = "-NoProfile -ExecutionPolicy ByPass -WindowStyle Hidden -File `"" + $myinvocation.mycommand.definition + "`" -in64Bit"
$path = (Join-Path $Env:SystemRoot -ChildPath "\sysnative\WindowsPowerShell\v1.0\powershell.exe")
Start-Process $path -ArgumentList $arguments
Exit
}
#REQUIRED CONFIGURATION:
$copyExistingFiles = $False #use with caution! Could take a long time and does not resist a reboot
$redirectFoldersToOnedriveForBusiness = $True #if enabled, the next array needs to be configured as well
......@@ -139,16 +151,26 @@ try{
Write-Error $_ -ErrorAction Continue
}
#REGISTER SCHEDULED TASK
$createTask = "schtasks /Create /SC ONLOGON /TN OnedriveAutoConfig /IT /RL LIMITED /RU BUILTIN\Users /F /TR `"Wscript.exe '$desiredVBSScriptPath' '$desiredBootScriptPath'`""
$res = Invoke-Expression $createTask
if($res -NotMatch "ERROR"){
Write-Output "Scheduled task created"
}else{
Write-Error "Failed to create scheduled task" -ErrorAction SilentlyContinue
Write-Error $res -ErrorAction Stop
#REGISTER SCRIPT TO RUN AT LOGON
$wscriptPath = Join-Path $env:SystemRoot -ChildPath "System32\wscript.exe"
$fullRunPath = "$wscriptPath `"$desiredVBSScriptPath`" `"$desiredBootScriptPath`""
try{
Write-Output "Adding logon registry key"
New-ItemProperty -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Run" -Name OnedriveAutoConfig -Value $fullRunPath -PropertyType String -Force -ErrorAction Stop
Write-Output "logon registry key added"
}catch{
Write-Error "Failed to add logon registry keys, user config will likely fail" -ErrorAction Continue
Write-Error $_ -ErrorAction Continue
}
# Create a scheduled task to run the script at logon
$action = New-ScheduledTaskAction -Execute $wscriptPath -Argument "`"$desiredVBSScriptPath`" `"$desiredBootScriptPath`""
$trigger = New-ScheduledTaskTrigger -AtLogon -RandomDelay (New-TimeSpan -Minutes 1)
$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -Hidden -DontStopIfGoingOnBatteries -Compatibility Win8
$principal = New-ScheduledTaskPrincipal -GroupId "BUILTIN\Users"
$task = New-ScheduledTask -Action $action -Trigger $trigger -Settings $settings -Principal $principal
Register-ScheduledTask -InputObject $task -TaskName "OnedriveAutoConfig"
$localScriptContent = "
#Module name: O4BClientAutoConfig
#Author: Jos Lieben (OGD)
......@@ -219,8 +241,8 @@ try{
while(`$true){
if(get-process | where {`$_.ProcessName -like `"onedrivesetup*`"}){
Write-Output `"Installer still running in the background..`"
Sleep -S 10
`$waited += 10
Sleep -S 30
`$waited += 30
if(`$waited -gt 600){
break
}
......@@ -406,21 +428,14 @@ if(`$detectedFolderPath -and `$redirectFoldersToOnedriveForBusiness){
}
}
}
Stop-Transcript
Exit
"
$localScriptContent | Out-File $desiredBootScriptPath -Force
Write-Output "Running first time"
Stop-Transcript
$runTask = "SCHTASKS /Run /TN `"OnedriveAutoConfig`""
$res = Invoke-Expression $runTask
if($res -NotMatch "ERROR"){
Write-Output "Scheduled task ran"
}else{
Write-Error "Failed to run scheduled task" -ErrorAction SilentlyContinue
Write-Error $res -ErrorAction Stop
}
Start-ScheduledTask -TaskName "OnedriveAutoConfig"
Exit
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment