Hi,
There is a possibility to automatically logon into Onedrive with user windows credentials for the first time.
# Target check # Module from: https://blogs.msdn.microsoft.com/rodneyviana/2017/06/06/powershell-cmdlet-to-check-onedrive-for-business-or-onedrive-personal-status/ Import-Module -Name "$sScriptPath\OneDriveLib.dll" $oOneDriveStatus = Get-ODStatus ForEach ($oOneDriveState in $oOneDriveStatus) { If ($oOneDriveState.UserName.EndsWith($sUserName)) { If ($oOneDriveState.LocalPath -eq "$($sUserProfile)\OneDrive - $($sTenantName)") { Add-Content $sLogFile "$(Get-Date -Format "yyyy-MM-dd HH:mm:ss") OneDrive for tenant [$($sTenantName)] is configured."; If ($sOneDriveSyncFolder -ne "$($sUserProfile)\OneDrive - $($sTenantName)") { [Environment]::SetEnvironmentVariable("OneDriveSyncFolder","$($sUserProfile)\OneDrive - $($sTenantName)","User"); $sOneDriveSyncFolder = "$($sUserProfile)\OneDrive - $($sTenantName)" Add-Content $sLogFile "$(Get-Date -Format "yyyy-MM-dd HH:mm:ss") Set environment variable OneDriveSyncFolder to $($sOneDriveSyncFolder)."; } $bConfigureOneDrive = $false; } } Else { Add-Content $sLogFile "$(Get-Date -Format "yyyy-MM-dd HH:mm:ss") [$($oOneDriveState.UserName)] not equal to [D40\$($sUserName)]."; } } # Configure OneDrive if needed If ($bConfigureOneDrive) { Start-Process -FilePath odopen://Sync?useremail=$($sUserName)@$($sTenantDomain); $bWaiting = $true; $i = 60; # max wait is 10 minutes (60 x 10s) Start-Sleep -Seconds 10;
The following gives me a logon window ( Note: I use an Okta environment )
Start-Process -FilePath odopen://Sync?useremail=$($sUserName)@$($sTenantDomain);