Giter Site home page Giter Site logo

Comments (20)

TheyCallMeZ avatar TheyCallMeZ commented on July 4, 2024 2

@SHJordan

Corrected Both

function uptime {
         # Needed to split the offset because of wmi reporting it in minutes instead of hours and minutes
        $bootUpTime = Get-WmiObject win32_operatingsystem | Select-Object lastbootuptime
        $plusMinus = $bootUpTime.lastbootuptime.SubString(21,1)
        $plusMinusMinutes = $bootUpTime.lastbootuptime.SubString(22, 3)
        $hourOffset = [int]$plusMinusMinutes/60
        $minuteOffset = 00
        if ($hourOffset -contains '.') { $minuteOffset = [int](60*[decimal]('.' + $hourOffset.ToString().Split('.')[1]))}       
	  if ([int]$hourOffset -lt 10 ) { $hourOffset = "0" + $hourOffset + $minuteOffset.ToString().PadLeft(2,'0') } else { $hourOffset = $hourOffset + $minuteOffset.ToString().PadLeft(2,'0') }
        $leftSplit = $bootUpTime.lastbootuptime.Split($plusMinus)[0]
        $upSince = [datetime]::ParseExact(($leftSplit + $plusMinus + $hourOffset), 'yyyyMMddHHmmss.ffffffzzz', $null)
        Get-WmiObject win32_operatingsystem | Select-Object @{LABEL='Machine Name'; EXPRESSION={$_.csname}}, @{LABEL='Last Boot Up Time'; EXPRESSION={$upsince}}
}
function uptime {
net statistics workstation | Select-String "since" | foreach-object {$_.ToString().Replace('Statistics since ', '')}
}

from powershell-profile.

TheyCallMeZ avatar TheyCallMeZ commented on July 4, 2024 1

@SHJordan
You can fix this in one of two ways, if you want to have the alias of "vim" in your powershell you can edit the large if block to look something like this. Or you can Comment out the line setting the alias for vim.

    $EDITOR='nvim'
} elseif (Test-CommandExists pvim) {
    $EDITOR='pvim'
} elseif (Test-CommandExists vim) {
    $EDITOR='vim'
} elseif (Test-CommandExists vi) {
    $EDITOR='vi'
} elseif (Test-CommandExists code) {
    $EDITOR='code'
} elseif (Test-CommandExists notepad) {
    $EDITOR='notepad'
} elseif (Test-CommandExists notepad++) {
    $EDITOR='notepad++'
} elseif (Test-CommandExists sublime_text) {
    $EDITOR='sublime_text'
}
Set-Alias -Name vim -Value $EDITOR```

from powershell-profile.

TheyCallMeZ avatar TheyCallMeZ commented on July 4, 2024

The correct install command is
irm "https://github.com/ChrisTitusTech/powershell-profile/raw/main/setup.ps1" | iex

this goes to the raw script on github rather than the Blob page with all the html

from powershell-profile.

PMJeffery avatar PMJeffery commented on July 4, 2024

Good call @TheyCallMeZ

I tried that and now got this:

PS C:\Users\susername\Downloads> irm "https://github.com/ChrisTitusTech/powershell-profile/raw/main/setup.ps1" | iex
Exception:
Line |
   8 |           throw $_.Exception.Message
     |           ~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Could not find a part of the path 'C:\Users\username\Documents\PowerShell\Microsoft.PowerShell_profile.ps1'.

I do not have that folder in my Documents folder. I added it, but created the folder and reran the command and it seems to work.

from powershell-profile.

TheyCallMeZ avatar TheyCallMeZ commented on July 4, 2024

@PMJeffery
That's interesting. The script successfully detected that you did not have an existing profile, but what's more interesting to me is that you didn't have the folder that would contain the profile. Either way you should be good to go from here.

from powershell-profile.

SHJordan avatar SHJordan commented on July 4, 2024

Still getting the error message when powershell opens:

Set-Alias : Não é possível associar o argumento ao parâmetro 'Value' porque ele é nulo.
No C:\Users\iopdev\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1:142 caractere:28
+ Set-Alias -Name vim -Value $EDITOR
+                            ~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Set-Alias], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.SetAliasCommand

from powershell-profile.

SHJordan avatar SHJordan commented on July 4, 2024

@SHJordan You can fix this in one of two ways, if you want to have the alias of "vim" in your powershell you can edit the large if block to look something like this. Or you can Comment out the line setting the alias for vim.

    $EDITOR='nvim'
} elseif (Test-CommandExists pvim) {
    $EDITOR='pvim'
} elseif (Test-CommandExists vim) {
    $EDITOR='vim'
} elseif (Test-CommandExists vi) {
    $EDITOR='vi'
} elseif (Test-CommandExists code) {
    $EDITOR='code'
} elseif (Test-CommandExists notepad) {
    $EDITOR='notepad'
} elseif (Test-CommandExists notepad++) {
    $EDITOR='notepad++'
} elseif (Test-CommandExists sublime_text) {
    $EDITOR='sublime_text'
}
Set-Alias -Name vim -Value $EDITOR```

that worked for me. thank you

from powershell-profile.

SHJordan avatar SHJordan commented on July 4, 2024

Also, is there a way to make it work on powershell 7?

from powershell-profile.

TheyCallMeZ avatar TheyCallMeZ commented on July 4, 2024

@SHJordan

You can run the setup on Powershell 7 but a number of the functions in Chris's script do not work such as uptime.
If you just want the themed shell without all the extras Chris has baked in, I suggest installing oh my posh by following the installation guide on their website.
https://ohmyposh.dev/

from powershell-profile.

SHJordan avatar SHJordan commented on July 4, 2024

@SHJordan

You can run the setup on Powershell 7 but a number of the functions in Chris's script do not work such as uptime. If you just want the themed shell without all the extras Chris has baked in, I suggest installing oh my posh by following the installation guide on their website. https://ohmyposh.dev/

i see... thats too bad... the looks are ok to get but i was more into the scripts.

from powershell-profile.

TheyCallMeZ avatar TheyCallMeZ commented on July 4, 2024

@SHJordan
Which parts of the script are not working for you in powershell 7?

You can replace the uptime function with either of these.

function uptime {
         # Needed to split the offset because of wmi reporting it in minutes instead of hours and minutes
        $bootUpTime = Get-WmiObject win32_operatingsystem | Select-Object lastbootuptime
        $plusMinus = $bootUpTime.lastbootuptime.SubString(21,1)
        $plusMinusMinutes = $bootUpTime.lastbootuptime.SubString(22, 3)
        $hourOffset = [int]$plusMinusMinutes/60
        $minuteOffset = 00
        if ($hourOffset -contains '.') { $minuteOffset = [int](60*[decimal]('.' + $hourOffset.ToString().Split('.')[1]))}       
        if ($hourOffset -lt 10 ) { $hourOffset = "0" + $hourOffset + $minuteOffset } else { $hourOffset = $hourOffset + $minuteOffset }
        $leftSplit = $bootUpTime.lastbootuptime.Split($plusMinus)[0]
        $upSince = [datetime]::ParseExact(($leftSplit + $plusMinus + $hourOffset), 'yyyyMMddHHmmss.ffffffzzz', $null)
        Get-WmiObject win32_operatingsystem | Select-Object @{LABEL='Machine Name'; EXPRESSION={$_.csname}}, @{LABEL='Last Boot Up Time'; EXPRESSION={$upsince}}
}
function uptime {
net statistics workstation | Select-String "since" | foreach-object {$_.ToString().Replace('Statistics since ', '')}

from powershell-profile.

SHJordan avatar SHJordan commented on July 4, 2024

When i run the script on pwsh 7.2.7 i get:

PS C:\Windows\System32> irm "https://github.com/ChrisTitusTech/powershell-profile/raw/main/setup.ps1" | iex
Exception:
Line |
   8 |           throw $_.Exception.Message
     |           ~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Could not find a part of the path 'C:\Users\iopdev\Documents\PowerShell\Microsoft.PowerShell_profile.ps1'.

from powershell-profile.

TheyCallMeZ avatar TheyCallMeZ commented on July 4, 2024

@SHJordan do you have the Powershell folder in your Documents folder? I saw this on someone else's issue as well.

Alternatively you can open your profile and paste the whole or parts of the profile script in to gain those features.

from powershell-profile.

SHJordan avatar SHJordan commented on July 4, 2024

I think i do, but i might be wrong?

PS C:\Windows\System32> $profile
C:\Users\iopdev\Documents\PowerShell\Microsoft.PowerShell_profile.ps1

from powershell-profile.

TheyCallMeZ avatar TheyCallMeZ commented on July 4, 2024

@SHJordan You need to actually check, $PROFILE is a system variable that reports where it should be, it doesn't actually check for existence.

I had to create a dummy account to get a clean slate and see if the folder is there by default and it is not.

image

Create that Powershell Folder in your Documents folder, run the setup after that and you should be good to go.

from powershell-profile.

SHJordan avatar SHJordan commented on July 4, 2024

Indeed. I had to create the folder and fix the editor alias, other than that all seems good to go now. ty for your patience.
image

from powershell-profile.

SHJordan avatar SHJordan commented on July 4, 2024

@SHJordan Which parts of the script are not working for you in powershell 7?

You can replace the uptime function with either of these.

function uptime {
         # Needed to split the offset because of wmi reporting it in minutes instead of hours and minutes
        $bootUpTime = Get-WmiObject win32_operatingsystem | Select-Object lastbootuptime
        $plusMinus = $bootUpTime.lastbootuptime.SubString(21,1)
        $plusMinusMinutes = $bootUpTime.lastbootuptime.SubString(22, 3)
        $hourOffset = [int]$plusMinusMinutes/60
        $minuteOffset = 00
        if ($hourOffset -contains '.') { $minuteOffset = [int](60*[decimal]('.' + $hourOffset.ToString().Split('.')[1]))}       
        if ($hourOffset -lt 10 ) { $hourOffset = "0" + $hourOffset + $minuteOffset } else { $hourOffset = $hourOffset + $minuteOffset }
        $leftSplit = $bootUpTime.lastbootuptime.Split($plusMinus)[0]
        $upSince = [datetime]::ParseExact(($leftSplit + $plusMinus + $hourOffset), 'yyyyMMddHHmmss.ffffffzzz', $null)
        Get-WmiObject win32_operatingsystem | Select-Object @{LABEL='Machine Name'; EXPRESSION={$_.csname}}, @{LABEL='Last Boot Up Time'; EXPRESSION={$upsince}}
}
function uptime {
net statistics workstation | Select-String "since" | foreach-object {$_.ToString().Replace('Statistics since ', '')}

This actually isnt displaying the time, and the second version is actually broken.

from powershell-profile.

SHJordan avatar SHJordan commented on July 4, 2024

all good now ty

from powershell-profile.

TheyCallMeZ avatar TheyCallMeZ commented on July 4, 2024

all good now ty

Glad to help!

from powershell-profile.

ChrisTitusTech avatar ChrisTitusTech commented on July 4, 2024

Merged fix from @TheyCallMeZ
commit dd1a411

from powershell-profile.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.