Hi - attempting to call onedrive.exe using test-path and start-process command. The below script is used when users VPN connect to autoload teams and onedrive. This works for some users but the majority it fails with cannot find file ( see below ). The powershell.exe is called from a VBS logon script ( maps network drives and then calls powershell )
objShell.run(“powershell.exe -ExecutionPolicy bypass -windowstyle hidden -file c:\XXXXXX\admin_scripts\Script_PS_VPN2_Logon_GITDIR.ps1”)
below that then calls this powershell script.
Note the teams component is loaded ok for all users
cd $env:localappdata
.\Microsoft\Teams\Update.exe --processStart “Teams.exe”
if (test-path “c:\Program Files\Microsoft OneDrive\onedrive.exe”) {
cd ${env:ProgramFiles}'Microsoft OneDrive’
start-process -FilePath “OneDrive.exe” -argumentlist ‘/background’
}
elseif
(test-path “c:\Program Files (x86)\Microsoft OneDrive\onedrive.exe”) {
cd ${env:ProgramFiles(x86)}'Microsoft OneDrive’
start-process -FilePath “OneDrive.exe” -argumentlist ‘/background’
}
elseif
(test-path “$env:LOCALAPPDATA\Microsoft\OneDrive\onedrive.exe”) {
cd ${env:LOCALAPPDATA}'Microsoft\OneDrive’
start-process -Filepath “OneDrive.exe” -argumentlist ‘/background’
}
Error that presents is
PS>CommandInvocation(Out-String): “Out-String”
ParameterBinding(Out-String): name=“InputObject”; value=“Cannot find path ‘C:\Program Files (x86)\Microsoft OneDrive’ because it does not exist.”
cd : Cannot find path ‘C:\Program Files (x86)\Microsoft OneDrive’ because it does not exist.
At C:\Zurich\admin_scripts\Script_PS_VPN2_Logon_GITDIR.ps1:8 char:1
- cd ${env:ProgramFiles}'Microsoft OneDrive’
-
+ CategoryInfo : ObjectNotFound: (C:\Program File...rosoft OneDrive:String) [Set-Location],
ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetLocationCommand
cd : Cannot find path ‘C:\Program Files (x86)\Microsoft OneDrive’ because it does not exist.
At C:\Zurich\admin_scripts\Script_PS_VPN2_Logon_GITDIR.ps1:8 char:1
- cd ${env:ProgramFiles}'Microsoft OneDrive’
-
+ CategoryInfo : ObjectNotFound: (C:\Program File...rosoft OneDrive:String) [Set-Location],
ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetLocationCommand
cd : Cannot find path ‘C:\Program Files (x86)\Microsoft OneDrive’ because it does not exist.
At C:\Zurich\admin_scripts\Script_PS_VPN2_Logon_GITDIR.ps1:8 char:1
- cd ${env:ProgramFiles}'Microsoft OneDrive’
-
+ CategoryInfo : ObjectNotFound: (C:\Program File...rosoft OneDrive:String) [Set-Location], ItemNotFoundE xception + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetLocationCommand
PS>TerminatingError(Start-Process): “This command cannot be run due to the error: The system cannot find the file specified.”
Note: the logon vbscript is being called from the netlogon share. I have also tried running the powershell script to load onedrive from the netlogon share also but decided to copy the PS script to the users endpoint device to be called.
the script runs fine and loads onedrive if the user right clicks and selects run with powershell from the script on the users device
thanks for your assistance
Steve