Oct 01 2019 09:56 AM
Very simple PowerShell example that writes the current date and time to a readme file:
"Backed up $(Get-Date)" > "$OneDrive\Readme.txt"
$OneDrive is the path to the root of the local OneDrive folder. If Readme.txt exists but isn't downloaded, this command fails with:
out-file : The cloud operation was unsuccessful.
OneDrive and Windows 10 is obviously still not integrated tightly enough. One assumes that out-file performs a pretty standard Windows file open command. One assumes that it shouldn't return until the file is downloaded.
Oct 01 2019 10:02 AM
The sketchy workaround is to use a function like this to force OneDrive to download the file first:
Function GetFile($Path) {
If (Test-Path $Path) {
$File = [System.IO.File]::OpenRead($Path)
$File.ReadByte() | Out-Null
$File.Close()
}
}
Not ideal! And means a lot of re-working of PowerShell scripts that happen to be expected to work on OneDrive file systems.
Oct 01 2019 11:43 PM
I've reported a similar issue with PowerShell 7 and the fix has already been released in one of the preview builds IIRC. But yeah, don't expect the different teams at Microsoft to talk to each other :D
Oct 02 2019 03:02 AM