Update-AzureRmVmss : Required parameter 'adminPassword' is missing (null) - powershell

I am trying to run a PowerShell vmss custom extension script on scale set.
I get this error when it tries to run the Update-AzureRmVmss command
Update-AzureRmVmss : Required parameter 'adminPassword' is missing (null).
ErrorCode: InvalidParameter
ErrorMessage: Required parameter 'adminPassword' is missing (null).
StatusCode: 400
ReasonPhrase: Bad Request
$customConfig = #{
"fileUris" = #("https://$storageAccountName.blob.core.windows.net/scripts/script.ps1");
"commandToExecute" = "PowerShell -ExecutionPolicy Unrestricted .\script.ps1";
};
# Add the extension to the config
$vmss = Get-AzureRmVmss -ResourceGroupName $resourceGroup -VMScaleSetName $vmssname
Add-AzureRmVmssExtension -VirtualMachineScaleSet $vmss -Publisher Microsoft.Compute -Type CustomScriptExtension -TypeHandlerVersion 2.0 -Name "runscript" -Setting $customConfig
# Send the new config to Azure
Update-AzureRmVmss -ResourceGroupName $resourceGroup -Name "runscript" -VirtualMachineScaleSet $vmss

I figured out the issue.
The -Name needs to be scaleset name. The code I got from online had the name as the name of the script which was wrong.
Update-AzureRmVmss -ResourceGroupName $resourceGroup -Name "scalsetname" -VirtualMachineScaleSet $vmss

It might be easier to use the PowerShell cmdlet or CLI commands to add an extension directly..
PowerShell: Add-AzureRmVmssExtension
CLI: az vmss extension set
The Azure Cloud Shell has a built in authenticated version of CLI.

The correct parameter for Update-AzureRmVmss is -VMScaleSetName which also has an alias called Name.
I was also getting the same error using -Name parameter,
but when I tried using -VMScaleSetName in place of -Name, I do not see the error.
Here is the official documentation for reference: https://learn.microsoft.com/en-us/powershell/module/azurerm.compute/update-azurermvmss?view=azurermps-6.9.0
Update-AzureRmVmss -ResourceGroupName $resourceGroup -VMScaleSetName "scalesetname" -VirtualMachineScaleSet $vmss

If found this thread by searching for Required parameter 'adminPassword' is missing (null), but my solution was a different one.
Turns out that you get this message also if your chosen password does not match the security requirements of the VM (or whatever) you are installing. It is a confusing way to express that issue, to say the least, so maybe this helps someone.

Related

Run cosmosdb commands from powershell

I am trying to connect to azure cosmosdb from my local machine via powershell but every command I tried to run it returns the "Argument passed in is not serializable."
Here are a few of my commands,
Get-AzCosmosDBAccount -ResourceGroupName "cosmosbackup"
Invoke-AzCosmosDBSqlDatabaseThroughputMigration -ResourceGroupName "cosmosbackup" -AccountName "liabilitydata" -Name liability
New-AzCosmosDBSqlContainer -AccountName "liabilitydata"-DatabaseName "dailyliability"-ResourceGroupName "cosmosbackup"-Name schemes -PartitionKeyPath /Id -PartitionKeyKind Hash
Get-AzCosmosDBSqlContainer `
-ResourceGroupName "cosmosbackup" `
-AccountName "liabilitydata" `
-DatabaseName "dailyliability"
All of them fail for the same reason Argument passed in is not serializable.
Am I missing something? Please help
The issue here is that you need to set the context for running the script,
Step 1 : Connect with your Azure account
Connect-AzAccount
Step 2 : Pass the resource group and the cosmosdb account name as follows,
Get-AzCosmosDBAccount -ResourceGroupName cosmosbackup

Switch-AzureRmWebAppSlot does not swap the physical site only the application settings

I have been running the following command via powershell for AZURE but all that gets swapped are the application settings:
Switch-AzureRmWebAppSlot -ResourceGroupName 'myresourcegroup' -Name 'mywebsitename' -SourceSlotName "staging" -DestinationSlotName "production" -confirm -verbose
The same thing happens when I run this command:
Switch-AzureRmWebAppSlot -ResourceGroupName 'myresourcegroup' -Name 'mywebsitename' -SourceSlotName "staging" -DestinationSlotName "production" -SwapWithPreviewAction CompleteSlotSwap -confirm -verbose
I cannot use Switch-AzureWebsite as I cannot set a default subscription with my permissions.
Using the Login-AzureRMAccount the only way I found to switch slots is as follows:
$ParametersObject = #{targetSlot = "production"}
$RGN = 'resource-group-name-'
Invoke-AzureRmResourceAction -ResourceGroupName $RGN -ResourceType Microsoft.Web/sites/slots -ResourceName website-name/staging -Action slotsswap -Parameters $ParametersObject -Verbose -force
This was hard to find, in part because many examples required you to set your Azure default subscription prior to executing Switch-AzureWebsite and the other switch only moved the configuration elements over. I am curious if anyone has a clever way to discover power shell commands or ARM template commands aside from the ones generated for deployments on Azure. Ideally, I could perform an action on Azure an then see same thing scripted as PowerShell.
REF: Microsoft Docs Here

Remove-AzureRmResourceGroupDeployment not removing the azure dev test lab

I created a dev test lab from powershell using the command :
New-AzureRmResourceGroupDeployment -Name MyLab -ResourceGroupName MyLabRG -TemplateUri https://raw.githubusercontent.com/azure/azure-quickstart-templates/master/101-dtl-create-lab/azuredeploy.json
Now after I am done doing some operations in the lab, I want to delete it. So I use
Remove-AzureRmResourceGroupDeployment -Name MyLab -ResourceGroupName MyLabRG
It returns True, but when I check the Dev Test lab in portal, it is still there. Am I missing something?
If you want to remove the dev test lab, please have a try to use the following command, it works correctly on my side.
Remove-AzureRmResource -ResourceGroupName $resourcegroupName -ResourceType Microsoft.DevTestLab/labs -ResourceName $resourceName -ApiVersion 2016-05-15 -Force

List instances of Azure App Service with Powershell RM

My aim is to find all the instance Ids of a particular App Service in Azure so I can write a warm-up routine and test it against all running instances (ARRAfinity).
I can do the following with ASM Powershell but I need it in ARM (RM) as Octopus is configured for it.
(Get-AzureWebsite -Name "site-name" -Slot "Production").Instances
I have found the documentation around RM sparing, and the following hasn't led me to anything helpful:
Get-AzureRmWebApp -Name "site-name"
Any help would be really helpful.
Try something like this:
Get-AzureRmResource -ResourceGroupName $ResourceGroupName -ResourceType Microsoft.Web/sites/instances -Name $WebAppName -ApiVersion 2016-03-01
See also here for a helper function that also works on slots.
Or you can use:
Get-AzWebApp -ResourceGroupName $ResourceGroupName -Name $WebAppName
Resource cmdlets should run faster than Get-AzResource (Get-AzureRmResource), specially with heavy scripts.

Azure Microsoft.Azure.Diagnostics Extension

Trying to configure the BootDiagnostics on a VM on a storage account in a resource group different from the VMs. To the best of my knowledge this can only be done by installing the VmDiagnosticsExtension. I'm executing the following:
Set-AzureRmVMDiagnosticsExtension -ResourceGroupName $RgName -VMName $VmName `
-DiagnosticsConfigurationPath 'D:\DiagnosticsConfig.xml' `
-StorageAccountEndpoint '/subscriptions/ff26f7/resourceGroups/rgroup/providers/Microsoft.Storage/storageAccounts/amsdiag01'`
-StorageAccountName 'amsdiag01' `
-StorageAccountKey 'key''>
I get this error message:
ErrorMessage: Handler 'Microsoft.Azure.Diagnostics.IaaSDiagnostics'
has reported failure for VM Extension
'Microsoft.Insights.VMDiagnosticsSettings' with terminal error code
'1009' and error message: 'Enable failed for plugin (name:
Microsoft.Azure.Diagnostics.IaaSDiagnostics, version 1.6.3.0) with
exception Command
C:\Packages\Plugins\Microsoft.Azure.Diagnostics.IaaSDiagnostics\1.6.3.0\DiagnosticsPluginLauncher.exe
of Microsoft.Azure.Diagnostics.IaaSDiagnostics has exited with Exit
code: -106'
No further information available in C:\WindowsAzure\Logs\WaAppAgent.log on server. In the portal under 'Diagnostics' I can see the correct configuration. But the extension is in a '(unavailable)' state. Container in storage account is not created. Also, can't reboot the server due to the extension. I can remove and re-add the extension using PowerShell, but always same result. When performing a Get-AzureRmVMExtension I see the following 'Public Settings' entry:
PublicSettings : {
"storageAccount": "amsdiag01",
"xmlCfg": "PFdhZENmZz4NCiAgICAgIDxEaWFnbm9zdGljTW9uaXRvckNvbmZpZ3VyYXRpb24gb3ZlcmFsbFF1b3RhSW5NQj0iNDA5NiI+DQogICAgICAgIDxQZXJmb3JtYW5jZUNvdW50ZXJzIHNjaGVkdWxlZFRyYW5zZmVyUGVyaW9kPSJQVDFNIj4NCsKgwqDCoMKgwqAgICAgIDxQZXJmb3JtYW5jZUNvdW50ZXJDb25maWd1cmF0aW9uIGNvdW> eU5hbWU9IkNQVSBwcml2aWxlZ2VkIHRpbWUiIGxvY2FsZT0i
I've chosen not to use extensions but instead using the following:
$RgName = 'RG1'
$VmName = 'VM01'
$Vm = Get-AzureRmVM -ResourceGroupName $RgName -Name $VmName
$Vm = Set-AzureRmVMBootDiagnostics -Enable -VM $Vm -ResourceGroupName $RgName -StorageAccountName diagss01
Update-AzureRmVM -ResourceGroupName $RgName -VM $Vm