Getting help for a command, e.g. Get-ChildItem
:
Get-Help Get-ChildItem
Using behind corporate proxy - suggest putting in your profile script (see below):
[System.Net.WebRequest]::DefaultWebProxy = New-Object System.Net.WebProxy('<address>:<port>')
[System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
[System.Net.WebRequest]::DefaultWebProxy.BypassProxyOnLocal = $true
Registering the PSGallery repository:
Register-PSRepository -Default
Get-PSRepository
Which version are we running?
$PSVersionTable
Create new profile script:
New-Item $Profile -Type File -Force
Reload profile script:
Invoke-Expression $Profile
# Or use the alias:
iex $Profile
Check if path exists:
Test-Path <path>
List aliases:
Get-Alias
List commands:
Get-Command
List modules:
Get-Module
Get-Module -ListAvailable
Install a module, e.g. Azure:
Install-Module -Name Azure -Repository PSGallery -Force
# Run `Get-Module -ListAvailable` after it's installed to see all related modules.
Import-Module AzureRM.profile
Import-Module Azure.Storage
Import-Module Azure
# Now `Get-Module` (on its own) shows the Azure modules you just imported.
Pipelines and object filtering:
Get-Module | Where-Object { $_.Name -Match "^Azure.*" } | Remove-Module
Managing output:
Get-Command | Out-Host # The default, same as running `Get-Command` with no piping
Get-Command | Out-Host -Paging
<some command> | Out-Null # Analogous to sending output to /dev/null
Get-Command | Out-File ".\commands.txt" # Must specify the "."
Showing specific properties:
(Get-Command).Name # For single property
Get-Command | Select-Object -Property Name # Does the same
Get-Command | Select-Object -Property Name,Source # For multiple properties
Getting and setting environment variables:
$env:FOO # getting
$env:FOO = "bar" # setting