Yeah - I’m lovin’ the powerhell goodness…

But I need a way to remember all of these bits and bobs of snippets.
I guess this is what the internet is for!

This will obviously update as I find more



Basics

ExecutionPolicy

Get-ExecutionPolicy -?  

Set-ExecutionPolicy -? 

#Unrestricted 
#Default 

Install Chocolatey

Just do it, ok?

chocolatey - install

Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) 

Working with SqlServer

I think this part will end up as its own post…
Install SQL Server Powershell module

Install-Module -Name SqlServer -AllowClobber

Change password

I think this could be useful in docker instances…?

Pureinfotech - Change account password with powershell

$Password = Read-Host "Enter the new password" -AsSecureString

$UserAccount = Get-LocalUser -Name "admin"
$UserAccount | Set-LocalUser -Password $Password

Comments and more

Comments and more in powershell

This only works at the start of scripts, but is pretty cool

#Requires -RunAsAdministrator
#Requires -Version 5.0 

Filesystem basics

Delete a folder

if (Test-Path -Path $Folder) {
    Remove-Item $Folder -Recurse -Force
}

Test Net Framework installed

This is a bit crap

https://docs.microsoft.com/en-us/dotnet/framework/migration-guide/versions-and-dependencies

Get-Childitem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full'

#461814 is for Net472

Can test with mcr.microsoft.com/dotnet/framework/runtime:4.8


Persistent profile

This is for all those snippets I want to always be available, like my user secrets stuff

Adding a profile

To make a new profile for CurrentUserAllHosts
This is at %USERPROFILE%\Documents\WindowsPowerShell\profile.ps1 (but not really because my Documents folder isn’t on my home drive…)

if (!(Test-Path $Profile.CurrentUserAllHosts)) {
    New-Item -Type file -Path $Profile.CurrentUserAllHosts -Force }

Don’t forget about the executionpolicy

Profile locations

Profile Location
AllUsersAllHosts $PsHome\profile.ps1
AllUsersCurrentHost $PsHome\HostId_profile.ps1
CurrentUserAllHosts $Home\Documents\WindowsPowerShell\profile.ps1
CurrentUserCurrentHost $Home\Documents\WindowsPowerShell\HostId_profile.ps1

Credits

Pester

Secrets

Cheers!