Onedrive login with windows credentials

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);

This is not a PS native cmdlet as pointed to by your links. Thus you really need to ask the author about what you are trying to do.

If you are on your PC, and already enabled OD, then you are already logged on.
The cmdlet is using your logged on identity to connect to OD, by design. The author’s help info specifically says that.

How to use:

• Open PowerShell is normal mode (it will not work in Elevated mode for OneDrive
own design)

• Import the module OneDriveLib.dll
• Run Get-ODStatus

There is no credential parameter to pass…

Get-ODStatus | Get-Member

There is little to this DLL feature set to leverage.

# get function / cmdlet details
(Get-Command -Name Get-ODStatus).Parameters
Get-help -Name Get-ODStatus -Full
Get-help -Name Get-ODStatus -Online
Get-help -Name Get-ODStatus -Examples

# Get parameter that accepts pipeline input
Get-Help Get-ODStatus -Parameter * | 
Where-Object {$_.pipelineInput -match 'true'} | 
Select * 


# List of all parameters that a given cmdlet supports along with a short description:
Get-Help Get-ODStatus -para * | 
Format-Table Name, { $_.Description[0].Text } -wrap

…so you cannot do that. You are trying to do something the cmdlet is not designed to do / provide. So, yep you are going to get prompt, unless you are will to re-engineer the authors code. He does provide the source, so, there is nothing stopping you from trying.