diff --git a/README.md b/README.md index 97cd40d..0944e5e 100644 --- a/README.md +++ b/README.md @@ -31,26 +31,24 @@ New-Item -Path $PROFILE.CurrentUserAllHosts -ItemType "file" -Force notepad $PROFILE.CurrentUserAllHosts ``` -A very simple first customization one can do is update the prompt. This will indicate whether or not you're running as an Adminsitrator. +A very simple first customization one can do is update the prompt. This will indicate whether or not you're running as an Administrator. ```powershell +function Test-Admin { + $currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent()) + $currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator) +} + function prompt { $prompt = "> " - $current_user = New-Object Security.Principal.WindowsPrincipal( - [Security.Principal.WindowsIdentity]::GetCurrent() - ) - - If ($current_user.IsInRole( - [Security.Principal.WindowsBuiltinRole]::Administrator - )) { + If (Test-Admin -eq $true) { $prompt = "Admin$prompt" } - $prompt } ``` -I also added `install_scoop` and `install_bleachbit` utility functions. They are totally optional but, I think, useful. +Note the `Test-Admin` function, which is now available globally, will be used again in the `full_update.ps1` script and is generally a nice utility to have. I also added `Install-Scoop` and `Install-BleachBit` utility functions. They are totally optional but, I think, useful. # `$env:PATH` diff --git a/full_update.ps1 b/full_update.ps1 index eb002f1..f41a3d1 100644 --- a/full_update.ps1 +++ b/full_update.ps1 @@ -1,10 +1,5 @@ param([switch]$Elevated) -function Test-Admin { - $currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent()) - $currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator) -} - if ((Test-Admin) -eq $false) { if ($elevated) { # tried to elevate, did not work, aborting diff --git a/profile.ps1 b/profile.ps1 index 36df8d1..af3e3ad 100644 --- a/profile.ps1 +++ b/profile.ps1 @@ -1,29 +1,27 @@ # Scripts in this $PROFILE folder are added to the PATH $env:path += ";$(Split-Path -Parent $MyInvocation.MyCommand.Path)" +function Test-Admin { + $current_user = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent()) + $current_user.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator) +} + function prompt { $prompt = "> " - $current_user = New-Object Security.Principal.WindowsPrincipal( - [Security.Principal.WindowsIdentity]::GetCurrent() - ) - - If ($current_user.IsInRole( - [Security.Principal.WindowsBuiltinRole]::Administrator - )) { + If (Test-Admin -eq $true) { $prompt = "Admin$prompt" } - $prompt } -function install_scoop { +function Install-Scoop { # You can read the script before executing it here: # https://raw.githubusercontent.com/scoopinstaller/install/master/install.ps1 Invoke-RestMethod get.scoop.sh | Invoke-Expression # (un)install docs: https://github.com/ScoopInstaller/Install } -function install_bleachbit { +function Install-BleachBit { scoop bucket add extras scoop install bleachbit }