Splitting the path

$env:path.split(";")

Get All environment variables

gci env:

Powershell version

$PSVersionTable.PSVersion
$PSVersionTable

Powershell History using PSReadline

(Get-PSReadlineOption).HistorySavePath

Get Profile path

$profile
$PROFILE | Get-Member -MemberType noteproperty
$PROFILE | Get-Member -MemberType noteproperty | select name

Calling the powershell functions

Source link

Get Powershell modules path

$env:PSModulePath
$env:PSModulePath.split(";")

Get/Set Reqiestry Keys

List all the drives including the registy Keys

Get-PSDrive

Change to a drives

CD HKCU:\

To set a Keys

Set-ItemProperty -path 'HKCU:\Control Panel\Colors' -Name 'ActiveBorder' -value '0 255 255'

Setting Execution Policy

Get-ExecutionPolicy -List
Set-ExecutionPolicy -ExecutionPolicy Unrestricted
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope LocalMachine

Get the file abosulte file path

get-childitem -recurse | where {$_.extension -like ".xls*"} | % { Write-Host $_.FullName }

Power shell history location

  • By default command history is saved in %userprofile%AppData\Roaming\Microsoft\Windows\PowerShell\PSReadline\ConsoleHost_history.txt
  • By default cmder history is saved in cmder-directory\config.history

Power shell command to find the assemble target framework

# Get .net framework runtime verion
[Reflection.Assembly]::ReflectionOnlyLoadFrom(<assembly path>).ImageRuntimeVersion

# Get assemble target framework
[Reflection.Assembly]::ReflectionOnlyLoadFrom(<assembly path>).CustomAttributes |
Where-Object {$_.AttributeType.Name -eq "TargetFrameworkAttribute" } |
Select-Object -ExpandProperty ConstructorArguments |
Select-Object -ExpandProperty value

Az cli commands


# Login into Azure
az login

# List accounts
az account list --query '[].[name, id]' -o tsv

# Set context account
az account set --subscription '[Subscription Name]'

# Start lab VM
az lab vm start --name [VMName] --resource-group [Resour Group Name] --lab-name [Lab Name]

# List webapps
az webapp list --query '[].{rg: resourceGroup, url:defaultHostName, name:name}' | ConvertFrom-Json -AsHashtable

# List VMs in L

az lab vm list --lab-name [lab name] --resource-group [resource group name]
az lab vm list --lab-name [lab name] --resource-group [resource group name] --query '[].{VMName:fqdn}' | ConvertFrom-Json -AsHashtable

Get Path of the exe or command

# This gets the command
get-command ws
# This gets the path of the command
(get-command ws).path

Get all the wifi passwords

$array = netsh wlan show profiles |
    ForEach-Object {
        if ($_ -match "\s*All User Profile\s*:\s*(.*)") { $($matches[1]) }
    }

foreach ($wn in $array) {
    Write-Host "Profile: $wn"
    netsh wlan show profile name=$wn key=clear | find "Key Content"
}