Powershell Basics
# Secure string
$SecureString = Read-Host "Enter a password for user account" -AsSecureString
# Secure string
$SecureString = Read-Host "Enter a password for user account" -AsSecureString
Convert secure string to plain text
# Secure string
$SecureString = Read-Host "Enter a password for user account" -AsSecureString
# Convert to plain text
$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecureString)
$PlainPassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
List modules and dll's loaded​
# List modules and dll's loaded:
$LoadedAssemblies = [System.AppDomain]::CurrentDomain.GetAssemblies() | Where-Object Location -like '*Az.Storage*'
$LoadedAssemblies | Select-Object Location
Invoke-RestMethod​
# API Uri
$ApiUri = "https://management.azure.com/locations?api-version=2020-01-01"
# Get the current Token
$AccessToken = (Get-AzAccessToken).Token
# Build Header
$Headers = @{
'Authorization' = "Bearer $($AccessToken)"
'Accept' = "application/json"
}
# Execute Query
(Invoke-RestMethod -Method Get -Uri $ApiUri -Headers $Headers).value
Check Latest PS Modules versions​
Get-Module -Name az* -ListAvailable |
ForEach-Object {
write-host "Checking $($_.Name)"
$currentVersion = [Version] $_.Version
$newVersion = [Version] (Find-Module -Name $_.Name).Version
if ($newVersion -gt $currentVersion) {
Write-Host -Object "New version available $_ Module from $currentVersion to $newVersion" -ForegroundColor Green
}
Else
{
Write-Host -Object "No new version available $_ Module from $currentVersion" -ForegroundColor Yellow
}
}
Uninstall modules​
Get-Module -Name az* -ListAvailable |
ForEach-Object {
write-host "Checking $($_.Name)"
# Clean Up
Uninstall-Module -Name $_.Name -AllVersions -Force -Verbose
}
Update module​
Get-Module -Name az* -ListAvailable |
ForEach-Object {
write-host "Checking $($_.Name)"
$currentVersion = [Version] $_.Version
$newVersion = [Version] (Find-Module -Name $_.Name).Version
if ($newVersion -gt $currentVersion) {
Write-Host -Object "Updating $_ Module from $currentVersion to $newVersion" -ForegroundColor Green
Update-Module -Name $_.Name -RequiredVersion $newVersion -Force
Uninstall-Module -Name $_.Name -RequiredVersion $currentVersion -Force
}
}