Giter Club home page Giter Club logo

update-management-turn-on-vms's Introduction

Update Management - Turn On VMs

This script is intended to be run as a part of Update Management Pre/Post scripts.

It requires the ThreadJobs modules from the PowerShell gallery.

UpdateManagement-TurnOnVms.ps1 uses Az cmdlets and System Managed Identity.

This script will ensure all Azure VMs in the Update Deployment are running so they recieve updates. This script works with the Turn Off VMs script. It will store the names of machines that were started in an Automation variable so only those machines are turned back off when the deployment is finished.

 

TechNet gallery is retiring! This script was migrated from TechNet script center to GitHub by Microsoft Azure Automation product group. All the Script Center fields like Rating, RatingCount and DownloadCount have been carried over to Github as-is for the migrated scripts only. Note : The Script Center fields will not be applicable for the new repositories created in Github & hence those fields will not show up for new Github repositories.

update-management-turn-on-vms's People

Contributors

dmohanta avatar roramcmsft avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

update-management-turn-on-vms's Issues

Error

Job stream details
Get-AzResource : Could not convert string to DateTimeOffset: 1706089004. Path 'expires_on', line 1, position 1591. At line:104 char:23 + ... nResource = Get-AzResource -ResourceType Microsoft.Automation/Automat ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : CloseError: (:) [Get-AzResource], JsonReaderException + FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.GetAzureResourceCmdlet

Cannot index into a null array. At line:140 char:5 + $state = ($vm.Statuses[1].DisplayStatus -split " ")[1] + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : NullArray

Get-AzVM : Could not convert string to DateTimeOffset: 1706089007. Path 'expires_on', line 1, position 1591. At line:137 char:11 + $vm = Get-AzVM -ResourceGroupName $rg -Name $name -Status -Defaul ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : CloseError: (:) [Get-AzVM], JsonReaderException + FullyQualifiedErrorId : Microsoft.Azure.Commands.Compute.GetAzureVMCommand

New-AzAutomationVariable : Cannot validate argument on parameter 'ResourceGroupName'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again. At line:118 char:45 + New-AzAutomationVariable -ResourceGroupName $ResourceGroup -Automatio ... + ~~~~~~~~~~~~~~ + CategoryInfo : InvalidData: (:) [New-AzAutomationVariable], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Azure.Commands.Automation.Cmdlet.NewAzureAutomationVariable

Encrypt Azure Automation variables

As per the article:
https://learn.microsoft.com/en-us/azure/automation/shared-resources/variables?tabs=azure-powershell
A Microsoft Defender for Cloud recommendation is to encrypt all Azure Automation variables as described in Automation account variables should be encrypted.
Would it be possible to encrypt the automation variables? We are using this script as-is, which is causing us a compliance issue.
Is it as simple as amending line 173 -Encrypted $false to $true? Would that have any impact on update-management-turn-off-vms?

Runbook Not Working

Looking to use both this runbook and the Turn Off one as well to ensure VM's are powered on first before being Updated, using Azure Server Update Management (ASUM).

We can set the pre-script for our update deployment schedule to this Runbook, Update-management-turn-on-vms but when the update deployment runs, this runbook fails with multiple errors.

  • Get-AzureRmResource : Parameter set cannot be resolved using the specified named parameters. At line:111 char:23 + ... nResource = Get-AzureRmResource -ResourceType Microsoft.Automation/Au ...

  • New-AzureRmAutomationVariable : Cannot validate argument on parameter 'ResourceGroupName'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again. At line:125 char:50

  • Set-AzureRmContext : Parameter cannot be processed because the parameter name 'Subscription' is ambiguous. Possible matches include: -SubscriptionId -SubscriptionName. At line:142 char:40

  • Get-AzureRmVM : A parameter cannot be found that matches parameter name 'DefaultProfile'. At line:144 char:68 + ... RmVM -ResourceGroupName $rg -Name $name -Status -DefaultProfile $mute

  • Cannot index into a null array. At line:147 char:5 + $state = ($vm.Statuses[1].DisplayStatus -split " ")

  • Set-AzureRmContext : Parameter cannot be processed because the parameter name 'Subscription' is ambiguous. Possible matches include: -SubscriptionId -SubscriptionName. At line:142 char:40

  • Get-AzureRmVM : A parameter cannot be found that matches parameter name 'DefaultProfile'. At line:144 char:68 + ... RmVM -ResourceGroupName $rg -Name $name -Status -DefaultProfile $mute

  • Cannot index into a null array. At line:147 char:5 + $state = ($vm.Statuses[1].DisplayStatus -split " ")

  • Set-AutomationVariable : Variable not found. To create this Variable, navigate to the Variables blade and create a Variable named:

To my very untrained eye, it looks like the runbook is not able to parse the passed variable from the Update Management API,
param(
[string]$SoftwareUpdateConfigurationRunContext
)

From what I understand, this is passed from Update Management directly when a deployment is ran.

Output from the runbook does display the name of the VM's selected to be update, but no action to start the VM's is attempted,
Environments Context


{[AzureCloud, AzureCloud], [AzureChinaCloud, AzureChinaCloud], [AzureUSGovernment, AzureUSGovernment]} Microsoft.Azur...

Subscription Id: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

NxAVD-4: no action taken. State:

Subscription Id: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

NxAVD-5: no action taken. State:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.