I think this is what you're trying to do. However, I think in your script you have the "Program Data" and "AppData" directories reversed. I did not correct that in my version of your code. Please verify that the correct values are placed into the "$Directory" variable.
$InstallationType = ""
$Directory = ""
if (Test-Path -Path "C:\Program Files\Microsoft OneDrive\OneDrive.exe") {
$Directory = "%LOCALAPPDATA%\Local\Microsoft\OneDrive\OneDrive.exe" # Program Files
$InstallationType = "Program Files"
}
else{
$Directory = "C:\Program Files\Microsoft OneDrive\OneDrive.exe" # AppData
$InstallationType = "AppData"
}
Start-Process -FilePath $Directory -Wait
Write-Host "Installation Type: $InstallationType"
#Start-Sleep -Seconds 5 # Why wait????
if ($null -eq (Get-Process "OneDrive" -ea SilentlyContinue)) { # always put $null on the left side!!
Write-Host "OneDrive is Not Running"
}
else {
Write-Host "OneDrive is Running"
}