Commit d4d1b813 authored by Jos Lieben's avatar Jos Lieben

smarter x64 elevation and single fire task

parent 66f6cae8
......@@ -14,17 +14,6 @@
#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
......@@ -37,10 +26,26 @@ $listOfFoldersToRedirectToOnedriveForBusiness = @(#One line for each folder you
#OPTIONAL CONFIGURATION:
$xmlDownloadURL = "https://g.live.com/1rewlive5skydrive/ODSUInsider"
$temporaryInstallerPath = Join-Path $Env:TEMP -ChildPath "OnedriveInstaller.EXE"
$logFile = Join-Path $Env:TEMP -ChildPath "OnedriveAutoConfig.log"
$logFileX64 = Join-Path $Env:TEMP -ChildPath "OnedriveAutoConfigx64.log"
$logFileX86 = Join-Path $Env:TEMP -ChildPath "OnedriveAutoConfigx86.log"
#LOG TO FILE
Start-Transcript -Path $logFile
#Restart self in x64
If (!([Environment]::Is64BitProcess)){
Start-Transcript -Path $logFileX86
if([Environment]::Is64BitOperatingSystem){
Write-Output "Running 32 bit Powershell on 64 bit OS, restarting as 64 bit process..."
$arguments = "-NoProfile -ExecutionPolicy ByPass -WindowStyle Hidden -File `"" + $myinvocation.mycommand.definition + "`""
$path = (Join-Path $Env:SystemRoot -ChildPath "\sysnative\WindowsPowerShell\v1.0\powershell.exe")
Start-Process $path -ArgumentList $arguments -Verb Open -Wait
Write-Output "finished x64 version of PS"
Stop-Transcript
Exit
}else{
Write-Output "Running 32 bit Powershell on 32 bit OS"
}
}else{
Start-Transcript -Path $logFileX64
}
#CREATE SILENT RUNNER (SO USER DOESN'T SEE A PS WINDOW)
$desiredBootScriptFolder = Join-Path $Env:ProgramData -ChildPath "Lieben.nu"
......@@ -163,12 +168,11 @@ try{
Write-Error $_ -ErrorAction Continue
}
# Create a scheduled task to run the script at logon
# Create a scheduled task to run the script once
$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
$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -Compatibility Win8
$principal = New-ScheduledTaskPrincipal -GroupId "BUILTIN\Users"
$task = New-ScheduledTask -Action $action -Trigger $trigger -Settings $settings -Principal $principal
$task = New-ScheduledTask -Action $action -Settings $settings -Principal $principal
Register-ScheduledTask -InputObject $task -TaskName "OnedriveAutoConfig"
$localScriptContent = "
......
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