My Azure Profile Script

If you like me I work in a lot of virtual lab environments (mostly Azure) and need a way I start them up. I have all my VM's on Auto Shutdown to save some money and only need them when I test. 

I wrote a profile script that allows me to do this. This script does not have a UI for it (however now that I mention it, I might make one), but it does display nicely in PowerShell's console window. 

When its time to play, I just run one command:

  • Start-MyAzureEnvironment
This kick off  a series of prompts. The first is a list of the sites that I manage in Azure. This list if hardcoded in the first few lines of the script and should be changed based on your environments. 

The next prompts are for resource group within those sites. However it will only come up if there are multiple RG and your not loaded a default one, otherwise it will continue the process.

Once it has analyzed my environment, it will start the virtual machines. This is setup to start all VM's within that RG group. 

Update 03/01/2021: the JIT access request only is working if the entire subnet is enabled. if its per VM, then it does not see it. I will have to look into this

Update 05/20/2021: the JIT access request now works with individual VM's network securoty groups. 

I've added a ton more functionality in the script for my personal benefit. Here is a list of functions:
  • Set-MyAzureEnvironment
  • Get-ParameterOption
  • Test-IsISE
  • Test-VSCode
  • Get-VolumeLevel
  • Set-VolumeLevel
  • Test-IsAdmin
  • Elevate-Process
  • Out-Voice
  • Open-File
  • Install-LatestModule
  • Connect-MyAzureEnvironment
  • Get-MyAzureNSGRules
  • Get-MyAzureVM
  • Start-MyAzureVM
  • Extract-MaxDuration
  • Set-MyJitAccess
  • Enable-JitPolicy
  • Start-MyAzureEnvironment
  • Convert-XMLtoPSObject
  • Get-RemoteDesktopData
  • Get-MyAzureUserName
  • Get-RandomAlphanumericString
  • Generate-HyperVMSerialNumber
  • Create-MyAzureVM (Not working)
  • Get-MyHyperVM
  • Kill-MyHyperVM
  • Restart-MyHyperV
  • Control-MyWindow
  • Start-MDTSimulator
  • Show-MyCommands
These is alot...however some of these are not important (especially the HyperV ones) you can use them or lose them. Be careful though some depend on others. I have not full written a synopsis for them...maybe when I get the time, instead of blogging...😏

The are you want to up date is the lines 8 and 11

$VoiceWelcomeMessage = $true
$Checkmodules = @('Az','Az.Security','Azure','AzureAD','Microsoft.Graph.Intune','PSIntuneAuth','PSProfile','PSFramework','PSUtil')
The other area is where you contol the Azure environments. This is under the Set-MyAzureEnvironment function and you will need to add/remove/update the switchs in line 26


 And then sync that with lines 40-69

'<name of environment>' {

                $myTenantID = '<add your tenantid>'

                $mySubscriptionName = '<subscription name>'

                $mySubscriptionID = '<your subscription id>'

                $myResourceGroup = '<your resource group>'


I am looking into making a json/xml file config file for it, so there is no need to edit the script itself. The intention wasn't to have other use it, but as it grew and other saw me kick off my environment with easy, they started asking for here it is.  


Popular Posts