ChrisTitusTech / powershell-profile

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

Showing Error after entering One Line Install. #16

Closed itsRealGray closed 1 year ago

itsRealGray commented 1 year ago

Annotation 2022-11-14 210616

As instructed Elevated PowerShell pasting the One Line Install line this error is popping up every time. -

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." At line:19 char:10

ZanzyTHEbar commented 1 year ago

so, this is an easy fix

You can either fix this yourself - or use this pull request

Download the scrpt, or copy the contents into a .ps1 file onto your machine and modify the script with the below code

Completely replace the first if-statement with this:

#If the file does not exist, create it.
if (!(Test-Path -Path $PROFILE -PathType Leaf)) {
    try {
        # Detect Version of Powershell & Create Profile directories if they do not exist.
        if ($PSVersionTable.PSEdition -eq "Core" ) { 
            if (!(Test-Path -Path ($env:userprofile + "\Documents\Powershell"))) {
                New-Item -Path ($env:userprofile + "\Documents\Powershell") -ItemType "directory"
            }
        }
        elseif ($PSVersionTable.PSEdition -eq "Desktop") {
            if (!(Test-Path -Path ($env:userprofile + "\Documents\WindowsPowerShell"))) {
                New-Item -Path ($env:userprofile + "\Documents\WindowsPowerShell") -ItemType "directory"
            }
        }

        Invoke-RestMethod https://github.com/ChrisTitusTech/powershell-profile/raw/main/Microsoft.PowerShell_profile.ps1 -o $PROFILE
        Write-Host "The profile @ [$PROFILE] has been created."
    }
    catch {
        throw $_.Exception.Message
    }
}

Then simply call the script ./setup.ps1 or whatever you called it.

ZanzyTHEbar commented 1 year ago

@ChrisTitusTech the -ne "True" is not required at all and breaks on most peoples setups (including mine)

So, instead you should remove those args and then do a boolean negation with the ! operator instead.

You should also lowercase the If to if. Then, your logic will work flawlessly on all machines :)

itsRealGray commented 1 year ago

Thanks

ChrisTitusTech commented 1 year ago

Merged #17