Category: Azure

Azure

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"
AzureSecurity

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
Azure

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 =...
Azure

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 }
AzureIntune

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...
Azure

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...
Azure

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