Security people read this first: For-Security-People
First presented at PowerShell Conference Europe 2022
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
ISE is perfectly enough!
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
)
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:
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 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
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.
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
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.
Get-Help
Get-Member
Get-Command
Get-Command Get-*
Get-Command Set-*
Get-Command *-Computer
$ProgressPreference = 'SilentlyContinue'
$PSDefaultParameterValues["Install-Module:Scope"] = "CurrentUser"
Add more things later.
Feel free to submit pull request with your goodies!
Influenced by Mike F Robbins
PowerShell 101: The No-Nonsense Beginner’s Guide to PowerShell
And also by Chrissy LeMaire's Tweet