Skip to content

PowerShell execution policies

PowerShell execution policies

https://www.sqlshack.com/choosing-and-setting-a-powershell-execution-policy/
You may hear that the PowerShell execution policies are a security feature; it is not.
The PowerShell Execution Policies are a safety belt in PowerShell, like a child lock in cars.
The PowerShell Execution Policies protects the non-PowerShell-savvy end users from inadvertently harming themselves. It does not necessarily protect the system, but makes one jump through a few hoops to do something potentially dangerous.

  • First things to do
Get-ExecutionPolicy -List
Set-ExecutionPolicy  Unrestricted  -Scope LocalMachine

Get-Help    # will ask for update the first time
  • check PS version , modules and
    (Get-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine -Name ‘PowerShellVersion’).PowerShellVersion

Get-Module
lists moduled imported in the current session
Get-Module -ListAvailable
list all installed PowerShell modules.

Get-Command
list all commands ( cmdlets , functions alias etc)
Get-Command -ListImported
only commands that have been imported into the current session
Get-Command -Module Microsoft.PowerShell.Security, Microsoft.PowerShell.Utility
commands from the 2 modules
Get-Command -Module dbatools

config

disable right-click to paste in PowerShell
In almost all other programs right-clicking equals context menu

This is a feature called QuickEdit of the console, not PowerShell.
In some versions of cmd it’s turned off by default.
To disable that feature open the console menu :
- right clicking on the console title bar
- pressing Alt+Space
- or left clicking on the title bar logo
then select Properties or Defaults depending on whether you want to set the options for that sessions or for all further execution. In the Options tab, Edit Options group uncheck the QuickEdit Mode

Now you can’t paste by right click anymore
but you also lose the ability to select text by mouse or by Shift+Arrow keys and must switch to mark mode by opening the context menu > Edit > Mark to select