Start Azure VM and Open Bastion
The following snippet will check if a VM is turned on, and if not start it, then launch the Bastion connection window in Edge. $VM = Get-AzVM -Name 'LN-TCTester-01' -Status if($VM.PowerState -eq 'VM deallocated'){ $VM | Start-AzVM } Start-Process -Path msedge -ArgumentList "https://portal.azure.com/#/resource$($VM.Id)/bastionHost"
Find Java Based Azure App Services
A quick Azure PowerShell command to locate any Java based Azure App Services and Functions so you can check if they are vulnerable to the CVE-2021-44228 Apache Log4j2 vulnerability. Get-AzWebApp | ForEach-Object{ Get-AzWebApp -ResourceGroupName $_.ResourceGroup -Name $_.Name | Select-Object -Property Name, @{l='JavaVersion';e={$_.SiteConfig.JavaVersion}}, ResourceGroup, Id } | Format-Table
Resubmit Azure Automation Runbook Job
This snippet will allow you to re-run any Azure Automation Runbook job with the same parameters and in the same context (Azure or Hybrid Worker Group). # Set the variables from the previous job $AutomationAccountName = '' $ResourceGroupName = '' $JobId = '' # Get the previous job $AutoAccount = @{ AutomationAccountName = $AutomationAccountName ResourceGroupName = $ResourceGroupName } $PreviousJob =...
Copy Azure Permissions
I was replacing an old service account with a service principal, and needed to replicate the permissions in Azure. I was able to do that without missing anything, using the command below. $CopyFrom = 'Object to copy from' $CopyTo = 'Object to copy to' Get-AzRoleAssignment -ObjectId $CopyFrom | ForEach-Object{ New-AzRoleAssignment -ObjectId $CopyTo -RoleDefinitionId $_.RoleDefinitionId -Scope $_.Scope }
Testing and Deploying ARM Templates
I often find that when building an ARM template, I need to test it multiple times. So, I created the script below that will create the resource group (is it doesn’t exist), run the test cmdlet (and stop if there is a problem), and deploy the template to Azure. It will create a new name for the deployment each time...
Quickly Switch Azure Subscriptions with PSNotes
If you are now aware, PSNotes is a PowerShell module I developed that allows you save code snippets, and recall them right in you PowerShell using an alias. One great use for this I have found is for switching between Azure subscriptions. I work in multiple different subscriptions throughout the day. Some are in the same tenant, but some require...
Search Intune for Devices with Application Installed
This script uses the GraphAPI to check all devices in Intune to see if they have a particular application installed. $Application = "*PuTTY*" $Username = '[email protected]' Function Get-AuthToken { <# .SYNOPSIS This function is used to authenticate with the Graph API REST interface .DESCRIPTION The function authenticate with the Graph API Interface with the tenant name .EXAMPLE Get-AuthToken Authenticates you...
Encrypt All Azure Automation Variables
$ResourceGroupName = '' $AutomationAccountName = '' # Get all variables $variables = Get-AzureRMAutomationVariable -ResourceGroupName $ResourceGroupName -AutomationAccountName $AutomationAccountName # parse through each unencrypted variable Foreach($var in $variables | Where-Object{$_.Encrypted -ne $True}){ # remove the unencrypted variable Remove-AzureRMAutomationVariable -ResourceGroupName $var.ResourceGroupName -AutomationAccountName $var.AutomationAccountName -Name $var.Name # recreate the variable, with the same values and encrypt it New-AzureRMAutomationVariable -ResourceGroupName $var.ResourceGroupName -AutomationAccountName $var.AutomationAccountName -Name $var.Name...
Get All Azure Virtual Machine IP Addresses
[System.Collections.Generic.List[PSObject]] $IPAddresses = @() $VMs = Get-AzureRMVM foreach($VM in $VMs){ foreach($interface in $VM.NetworkProfile.NetworkInterfaces){ $resource = Get-AzureRMResource -id $interface.Id $nic = Get-AzureRmNetworkInterface -Name $resource.Name -ResourceGroupName $resource.ResourceGroupName Get-AzureRmNetworkInterfaceIpConfig -NetworkInterface $nic | Select-Object @{l='VM';e={$VM.Name}}, PrivateIpAddress, PrivateIpAllocationMethod | ForEach-Object{ $IPAddresses.Add($_) } } } $IPAddresses
Find and Load the Azure Automation Hybrid Registration Module
$installPath = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\System Center Operations Manager\12\Setup\Agent").InstallDirectory $modulePath = Get-ChildItem (Join-Path $installPath "AzureAutomation") -Recurse -Include 'HybridRegistration.psd1' | Select-Object -ExpandProperty FullName Import-Module $modulePath