Skip to content

documents in onedrive #160

@paprika27

Description

@paprika27

PROBLEM IDENTIFIED:

The script uses: [Environment]::GetFolderPath("MyDocuments") + "\PowerShell\LastExecutionTime.txt"
This always points to C:\Users\Username\Documents\PowerShell\LastExecutionTime.txt
But when the profile is in OneDrive, it should be in the same directory as the profile

CORRECT FIX - Replace the $timeFilePath definition with:

Use the same directory where the PowerShell profile is located

$profileDirectory = Split-Path -Parent $PROFILE
$timeFilePath = Join-Path $profileDirectory "LastExecutionTime.txt"

This way, the LastExecutionTime.txt file will be created in the same directory
as the profile, whether it's in local Documents, OneDrive, or anywhere else

===== ALTERNATIVE APPROACHES =====

Option 1: Keep it in PowerShell directory relative to profile location

$timeFilePath = Join-Path (Split-Path -Parent $PROFILE) "LastExecutionTime.txt"

Option 2: Create a PowerShell subdirectory in the profile's parent directory

$profileParent = Split-Path -Parent (Split-Path -Parent $PROFILE)
$timeFilePath = Join-Path $profileParent "PowerShell\LastExecutionTime.txt"

Ensure directory exists

if (!(Test-Path -Path (Split-Path -Parent $timeFilePath))) {
New-Item -Path (Split-Path -Parent $timeFilePath) -ItemType Directory -Force | Out-Null
}

Option 3: Use temp directory as fallback if needed

$profileDir = Split-Path -Parent $PROFILE
if (Test-Path $profileDir) {
$timeFilePath = Join-Path $profileDir "LastExecutionTime.txt"
} else {
$timeFilePath = Join-Path $env:TEMP "PowerShell_LastExecutionTime.txt"
}

===== RECOMMENDED FIX FOR PULL REQUEST =====

Replace this line:
$timeFilePath = [Environment]::GetFolderPath("MyDocuments") + "\PowerShell\LastExecutionTime.txt"

With this line:
$timeFilePath_Override = Join-Path (Split-Path -Parent $PROFILE.CurrentUserCurrentHost) "LastExecutionTime.txt"

or do edit-profile and put the above definition in the new profile.ps1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions