Skip to content

⭐ Tips and tricks for when you don't have local admin rights 💜

License

Notifications You must be signed in to change notification settings

sassdawe/no-admin-powershell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

no-admin-powershell

Security people read this first: For-Security-People

Tips and tricks for when we don't have local admin rights

image

First presented at PowerShell Conference Europe 2022

Opening PowerShell

When we are on Windows we don't need to install anything to get it started. Just search for/type ISE into the Start menu to find Windows PowerShell ISE. ISE stands for Integrated Scripting Environment

image

ISE is perfectly enough!

Protect ourselves!

When we experiment in ISE we could run stuff accidentally and that could be bad.

ISE has two really great buttons:

  • Run Script (shortcut F5)
  • Run Selection, or current line (shortcut F8)

image

Time to time we will end up with lots of things in our file, and accidentally executing everything could be bad.

Solution: add throw 'no no' to the first line and by doing this the current script cannot be executed anymore as a whole:

image

Profile file

The Profile file is really great because it enables us to customize our PowerShell console in a persistent way.

Note: Most things we can do in PowerShell will be related to the current process, the current PowerShell session. When we close the window they will get lost. So to get persist things we can use the profile file.

The $profile file will get executed every time when we start PowerShell, so this is where we can store our 'things'. (But this file does not exists by default, so we need to create it.)

Write-Host $profile

Test-Path $profile

New-Item $profile -ItemType File

New-Item $profile -ItemType File -Force

Let's try it!

Execution Policy

Execution policy in PowerShell is like something eveyone runs into and turns off...

Get-ExecutionPolicy

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned

# Try scoping it to us

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

# if RemoteSigned does not work, just use Bypass

Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope CurrentUser

NOTE the use of -Scope CurrentUser

Error message color

As others have already said it, color red is bad, so let's use something nicer

$host.PrivateData.ErrorForegroundColor = 'Green'

# and try it
1/0

Also, save this into our profile, because this is not a persistent setting.

PowerShell Gallery

The PowerShell Gallery is from where we can get the goodies, like QR code generator

Find-Module QRCodeGenerator
Find-Module QR*

Install-Module QRCodeGenerator

Install-Module QRCodeGenerator -Scope CurrentUser

New-QRCodeURI https://github.com/sassdawe/no-admin-powershell -Show 

NOTE the use of -Scope CurrentUser

Help system

PowerShell has the most awesome extensible help system

Get-Help

But sadly by default it comes empty, and we need to download the help with admin rights so here we need to ask help from our - hopefully - friendly neighbourhood IT admin, or help desk person to run this command as a local admin on our machine

Update-Help -Force -ErrorAction SilentlyContinue

So we can use Get-Help without any errors.

Important commands

Get-Help

Get-Member

Get-Command

Get-Command Get-*

Get-Command Set-*

Get-Command *-Computer

Also add these to our profile

$ProgressPreference = 'SilentlyContinue'
$PSDefaultParameterValues["Install-Module:Scope"] = "CurrentUser"

TO-DO: Add more stuff

Add more things later.

Feel free to submit pull request with your goodies!

Credit

Influenced by Mike F Robbins

http://mikefrobbins.com

PowerShell 101: The No-Nonsense Beginner’s Guide to PowerShell

And also by Chrissy LeMaire's Tweet

About

⭐ Tips and tricks for when you don't have local admin rights 💜

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published