Manage Microsoft.ClassicCompute/domainNames with Az PowerShell module - azure

I have a classic Compute resource. I need to move some old deployment code that used Azure.Service module to Az and I was wondering, is there a way to manage that with Az or something up to date?
I have to upload some .cspkg and some .cscfg files. There is more to it, but basically, this was done using this cmdlet and the related ones, Set, Get etc.
I used Az.Resources' cmdlet New-AzResource to create it:
New-AzResource `
-Location 'location' `
-ResourceGroupName 'rgName' `
-ResourceType 'Microsoft.ClassicCompute/domainNames' `
-ResourceName 'rName' `
-ApiVersion '2018-06-01'
What cmdlets could I use to manage this resource?

In your case, you could use Az.CloudService module commands, to upload some .cspkg and some .cscfg files, use New-AzCloudService with parameters -PackageUrl and -ConfigurationUrl(or -Configuration).
The command New-AzCloudService can Create or update a cloud service, i.e. New, Set operations, to do Get operation, use Get-AzCloudService command.
Anyway, see here for all the commands to manage Microsoft.ClassicCompute/domainNames i.e. Cloud service, use them depends on your requirement.
Update:
In this case, looks you could not migrate your commands to Az module, Az.CloudService is for the new Cloud Service(extended support) which is ARM(Azure Resource Manager) based, and it is in the preview version, see Deploy a Cloud Service (extended support) using Azure PowerShell, some features might not be supported, I think the error was caused by this.
What you are using is Cloud Service(classic), it is ASM(Azure Service Management) based, the new Az module is just for ARM resources.
So in your case, you may need to continue to use Azure.Service module, or you can migrate the ASM to ARM i.e. Cloud Service(classic) to Cloud Service(extended support), see Migration to Azure Resource Manager, but not recommend you to use it in the production environment as it is in preview.

Related

Azure Cloud Services Extended Support Deploy using New-AzCloudService powershell. Set swappable cloud service

Few days ago I moved my service from Azure Cloud Services classic to Cloud Services extended support. The latest doesn't have Production/Staging slots. There is a new swap mechanism that is activated if during a deploy we configured the "swappable cloud service". I can do it using Visual Studio publish magic and it works fine.
Now I want to make a deploy using powershell script. The code below just creates a new deploy without activated swap. It works fine.
New-AzCloudService -Name $stagingName `
-ResourceGroupName $resourceGroupName `
-Location $location `
-ConfigurationFile $cscfgFilePath `
-DefinitionFile $csdefFilePath `
-PackageFile $cspkgFilePath `
-StorageAccount $storageAccount `
-KeyVaultName $keyVaultName
I didn't find any samples or clues of how to add the "swappable cloud service" to the New-AzCloudService. I figured out there is such settings in
NetworkProfile.SwappableCloudService.Id but I can't understand how to set it up properly. For example, if I add:
$production= Get-AzCloudService -ResourceGroup $resourceGroupName -CloudServiceName $productionName
$production.NetworkProfile.SwappableCloudService.Id = $production.Name # just to reuse the object
$loadBalancerConfig = CreateLoadBalancerConfig
$networkProfile = #{loadBalancerConfiguration = $loadBalancerConfig; swappableCloudService = $production.NetworkProfile.SwappableCloudService }
New-AzCloudService -Name $stagingName `
...
-NetworkProfile $networkProfile `
I got the error:
New-AzCloudService : Parameter set cannot be resolved using the specified named parameters
Is it possible to set the "swappable cloud service" for New-AzCloudService? How to do it?
Is it possible to set the "swappable cloud service" after the deploy (in any way, Azure portal, API, powershell, etc.)?
I suspect the issue relates to the -NetworkProfile not being supported when -ConfigurationFile, -DefinitionFile, and -PackageFile are used.
In the documentation, -NetworkProfile is used with -PackageUrl and -Configuration instead.
I've asked Microsoft about this as I am having the same issue.
Try $production.Id instead of $production.Name. Or $production.id (I am not sure if the case is important).

Az Powershell commands not working for "Cloud service (classic)"

I'm simply trying to extract the below information using Az PowerShell.
Resource on portal
Already tried the below commands
Get-AzCloudService -ResourceGroupName "testCosmosDB" # it gives no result.
Get-AzCloudService -ResourceGroupName "testCosmosDB" -CloudServiceName "testnameon" # as shown below.
The reason you're getting this error is because Az PowerShell module only support Cloud Services (Extended Support) and not Cloud Services (Classic).
One option for you is to migrate your classic Cloud Services to Cloud Services (Extended Support). You can learn more about the migration here: https://learn.microsoft.com/en-us/azure/cloud-services-extended-support/overview#migration-to-azure-resource-manager.
Another option (not sure if it is even viable) is to make use of really old version of Azure PowerShell (even before AzureRM) which has support for classic resources.

AzureRm Add-AzureCertificate equivalent in Az

Ahead of the deprecation of the AzureRM powershell cmdlets later this year I am updating some of our infrastructure scripts to use the Az powershell cmdlets rather than AzureRM.
One of our scripts uploads SSL certificates to Azure Cloud Service(Classic) resources using Add-AzureCertificate:
Add-AzCertificate -ServiceName $serviceName -CertToDeploy $certObject
where $certObject is a X509Certificate2 object.
What is the equivalent cmdlet in the Az module? Add-AzCertificate does not exist.
On the Cloud Service documentation page where it details configuring SSL, only certificate upload via the Azure portal is shown.
As the comment from #Alex AIT, before call the AzureRM commands, you can run Enable-AzureRmAlias cmdlet which enables a compatibility mode through aliases, to allow you to use existing scripts with minimal modification while working towards a full migration to Az. For more information, you could refer to Migrate existing scripts to Az.
Also, to call Azure Cloud Service(Classic) resources, you still need Azure modules. View this example- Az / AzureRM / Legacy Azure Powershell Conflicts.

How to implement Update-AzSqlServerVulnerabilityAssessmentSetting using AzureRM

I have an Az script that sets up Advanced Data Security for my Azure SQL Databases/Servers.
Unfortunately, Az cannot run in Azure Devops, so I translated the script to AzureRM. The script leaves Advanced Data Security in a "Partially Configured" state, due to the Azure SQL Server's VULNERABILITY ASSESSMENT SETTINGS not being set.
What is the AzureRM equivalent of Update-AzSqlServerVulnerabilityAssessmentSetting
I tried
Update-AzSqlServerVulnerabilityAssessmentSetting
to:
Update-AzureRmSqlDatabaseVulnerabilityAssessmentSettings
However, only the database gets configured and this leave the Server unconfigured.
They are not an equivalent, the AzureRm module was deprecated and will not be updated.
Unfortunately, Az cannot run in Azure Devops, so I translated the script to AzureRM.
As I know, the Task version with 4.*(preview) supports Az module. I tried it here.
If you want to AzureRm module to update Azure SQL Vulnerability Assessment Setting, you just can use command "update-AzureRmSqlDatabaseVulnerabilityAssessmentSettings" to configure all database in one server, AzureRM does not provide command to enable customers to directly configure Azure SQL server. For more details, please refer to the blog.
Get-AzureRmSqlDatabase -ResourceGroupName $params.rgname -ServerName $params.serverName`
| where {$_.DatabaseName -ne "master"} `
| Update-AzureRmSqlDatabaseVulnerabilityAssessmentSettings `
-RecurringScansInterval Weekly `
-NotificationEmail $scanNotificationEmail `
-EmailAdmins $true"

Migrate classic Azure resources to new Azure resource manager

After switching to the new Azure portal, I see all resources of mine are listed as classic resources. I am googling around to see if it's possible to have classic VM and migrate it to ARM and just hadn't seen anything that stated it was possible.
I tried deleting the class VM but keep the VHD to check if I can attach it to the ARM VM. The result said it doesn't work.
Is there any way that can be used to achieve this ?
Unfortunately (and strangely!) there isn't a way to do this via the portal and you have to drop down to Powershell instead (or xplat / Rest)
When I have exported VMs from v1 to v2 I typically make the original vhd file accessible via a blob share (this can be done temporarily for the duration of this command)
You can then deploy a new VM using that vhd as a source image's URI, using
Set-AzureRmVMOSDisk -VM $vm -Name $vmname -VhdUri $uri -CreateOption FromImage -Windows
Alternatively you can copy the vhd to v2 storage and use Attach instead of FromImage
If you wrap that around a standard VM Create script, you should be good to go!
There is a set of powershell scripts to assist in migrating classic vms to the new resource group model - asm-arm
They require the Azure and AzureRM powershell modules - msdn link to installation instructions

Resources