From d087e6d0401788d8e4fa25a3043f6576f4ac147f Mon Sep 17 00:00:00 2001 From: Anthony Perkins Date: Fri, 8 Mar 2024 14:09:35 +0000 Subject: [PATCH] Add PowerShell Get-Uptime function --- roles/home-cli/files/Microsoft.PowerShell_profile.ps1 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/roles/home-cli/files/Microsoft.PowerShell_profile.ps1 b/roles/home-cli/files/Microsoft.PowerShell_profile.ps1 index c472648..c12a19c 100644 --- a/roles/home-cli/files/Microsoft.PowerShell_profile.ps1 +++ b/roles/home-cli/files/Microsoft.PowerShell_profile.ps1 @@ -72,6 +72,12 @@ if ($IsWindows -or ($env:OS -eq "Windows_NT")) { $env:__COMPAT_LAYER = "RunAsInvoker" } +if (!(Get-Command Get-Uptime -ErrorAction SilentlyContinue)) { + function Get-Uptime { + Get-WmiObject Win32_OperatingSystem | Select-Object @{LABEL='LastBootUpTime';EXPRESSION={$_.ConvertToDateTime($_.LastBootUpTime)}} + } +} + # Force UTF-8 output. $OutputEncoding = [System.Text.Encoding]::UTF8