Test-Admin utility
This commit is contained in:
parent
85582483ed
commit
153185ba84
22
README.md
22
README.md
|
@ -31,26 +31,24 @@ New-Item -Path $PROFILE.CurrentUserAllHosts -ItemType "file" -Force
|
||||||
notepad $PROFILE.CurrentUserAllHosts
|
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
|
```powershell
|
||||||
function prompt {
|
function Test-Admin {
|
||||||
$prompt = "> "
|
$currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
|
||||||
$current_user = New-Object Security.Principal.WindowsPrincipal(
|
$currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
|
||||||
[Security.Principal.WindowsIdentity]::GetCurrent()
|
|
||||||
)
|
|
||||||
|
|
||||||
If ($current_user.IsInRole(
|
|
||||||
[Security.Principal.WindowsBuiltinRole]::Administrator
|
|
||||||
)) {
|
|
||||||
$prompt = "Admin$prompt"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function prompt {
|
||||||
|
$prompt = "> "
|
||||||
|
If (Test-Admin -eq $true) {
|
||||||
|
$prompt = "Admin$prompt"
|
||||||
|
}
|
||||||
$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`
|
# `$env:PATH`
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,5 @@
|
||||||
param([switch]$Elevated)
|
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 ((Test-Admin) -eq $false) {
|
||||||
if ($elevated) {
|
if ($elevated) {
|
||||||
# tried to elevate, did not work, aborting
|
# tried to elevate, did not work, aborting
|
||||||
|
|
22
profile.ps1
22
profile.ps1
|
@ -1,29 +1,27 @@
|
||||||
# Scripts in this $PROFILE folder are added to the PATH
|
# Scripts in this $PROFILE folder are added to the PATH
|
||||||
$env:path += ";$(Split-Path -Parent $MyInvocation.MyCommand.Path)"
|
$env:path += ";$(Split-Path -Parent $MyInvocation.MyCommand.Path)"
|
||||||
|
|
||||||
function prompt {
|
function Test-Admin {
|
||||||
$prompt = "> "
|
$current_user = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
|
||||||
$current_user = New-Object Security.Principal.WindowsPrincipal(
|
$current_user.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
|
||||||
[Security.Principal.WindowsIdentity]::GetCurrent()
|
|
||||||
)
|
|
||||||
|
|
||||||
If ($current_user.IsInRole(
|
|
||||||
[Security.Principal.WindowsBuiltinRole]::Administrator
|
|
||||||
)) {
|
|
||||||
$prompt = "Admin$prompt"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function prompt {
|
||||||
|
$prompt = "> "
|
||||||
|
If (Test-Admin -eq $true) {
|
||||||
|
$prompt = "Admin$prompt"
|
||||||
|
}
|
||||||
$prompt
|
$prompt
|
||||||
}
|
}
|
||||||
|
|
||||||
function install_scoop {
|
function Install-Scoop {
|
||||||
# You can read the script before executing it here:
|
# You can read the script before executing it here:
|
||||||
# https://raw.githubusercontent.com/scoopinstaller/install/master/install.ps1
|
# https://raw.githubusercontent.com/scoopinstaller/install/master/install.ps1
|
||||||
Invoke-RestMethod get.scoop.sh | Invoke-Expression
|
Invoke-RestMethod get.scoop.sh | Invoke-Expression
|
||||||
# (un)install docs: https://github.com/ScoopInstaller/Install
|
# (un)install docs: https://github.com/ScoopInstaller/Install
|
||||||
}
|
}
|
||||||
|
|
||||||
function install_bleachbit {
|
function Install-BleachBit {
|
||||||
scoop bucket add extras
|
scoop bucket add extras
|
||||||
scoop install bleachbit
|
scoop install bleachbit
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue