Hi Team, Hope you are doing well. I am facing the issue related to get the Onedrive sync status via Powershell. Like my concern is before unlinking the account from onedrive need to check the Onedrive sync status, means if any files or folders are still syncing or status is Up to date. So, I need help to automate the process of checking sync status of onedrive, then stop onedrive process and unlink the account from Onedrive.
Below is the script, I am working on -
Check if the OneDrive process is running and stop it forcibly if it is
$onedriveProcess = Get-Process -Name "OneDrive" -ErrorAction SilentlyContinue
if ($onedriveProcess) {
$onedriveProcess | Stop-Process -Force
Write-Host "OneDrive process stopped successfully."
```} else {
Write-Host "OneDrive process not found or already stopped."
# Only attempt to check sync status if the process was found
if ($onedriveProcess) {
try {
$syncing = $true
while ($syncing) {
$syncStatus = $onedriveProcess.Process.MainWindowTitle
if ($syncStatus -eq "OneDrive is up to date") {
$syncing = $false
} else {
Start-Sleep -Seconds 5
Break
}
}
} catch {
Write-Host "Could not retrieve OneDrive sync status. Assuming syncing is complete or not required."
}
When running this variable $syncStatus only, I don't see any out.
$syncStatus = $onedriveProcess.Process.MainWindowTitle
Can you help me to figure this out?
Thanks!