powershell-profile icon indicating copy to clipboard operation
powershell-profile copied to clipboard

Cannot bind parameter 'NewerThan'

Open rtonerii opened this issue 2 years ago • 2 comments

I watched your video and I never knew what I was missing, really cool.

I tried to install it on PS 5.1 and I am getting the below error:

Cannot bind parameter 'NewerThan'. Cannot convert value "True" to type "System.DateTime". Error: "The string was not recognized as a valid DateTime. There is an unknown word starting at index 0."

Not sure if anyone else is getting this.

rtonerii avatar Nov 07 '22 14:11 rtonerii

Ok, I am already doing some digging, a few things I am noticing.

  1. I have OneDrive mapped to my profile path $PROFILE E:\OD\OneDrive - [company]\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

In the code you are querying a different path: $env:userprofile + "\Documents\WindowsPowerShell" Which returns "C:\Users[user]\Documents\WindowsPowerShell"

  1. Note sure whey you are using: If ((Test-Path -Path ($env:userprofile + "\Documents\WindowsPowerShell") -ne "True")) {

Wouldn't: If (-not (Test-Path -Path ($env:userprofile + "\Documents\WindowsPowerShell"))) { work the same? I know it does not throw the error above

rtonerii avatar Nov 07 '22 15:11 rtonerii

Here is how I addressed the issue

#If the file does not exist, create it.
if (-not(Test-Path -Path $PROFILE -PathType Leaf)) {
    #check to see if OneDrive Profile is registered
    if ($PROFILE.StartsWith($ENV:OneDrive + "\Documents\WindowsPowerShell")) {
        $varProfilePath = $ENV:OneDrive
    }
    elseif($PROFILE.StartsWith($ENV:OneDriveConsumer + "\Documents\WindowsPowerShell")){
        $varProfilePath = $ENV:OneDriveConsumer
    }else{
        $varProfilePath = $env:userprofile
    }


    try {
        # Detect Version of Powershell & Create Profile directories if they do not exist.
        if ($PSVersionTable.PSEdition -eq "Core" ) {
            If (-not (Test-Path -Path ($varProfilePath + "\Documents\Powershell"))) {
                New-Item -Path ($varProfilePath + "\Documents\Powershell") -ItemType "directory"
            }
        } elseif ($PSVersionTable.PSEdition -eq "Desktop") {
            If (-not (Test-Path -Path ($varProfilePath + "\Documents\WindowsPowerShell"))) {
                New-Item -Path ($varProfilePath + "\Documents\WindowsPowerShell") -ItemType "directory"
            }
        }

rtonerii avatar Nov 07 '22 15:11 rtonerii