ChrisTitusTech / powershell-profile

Pretty PowerShell that looks good and functions almost as good as Linux terminal
551 stars 320 forks source link

Cannot bind parameter 'NewerThan' #11

Closed rtonerii closed 1 year ago

rtonerii commented 1 year ago

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 commented 1 year ago

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"

2) 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 commented 1 year ago

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"
            }
        }