Export/New-ScaleSetImage.ps1
function Global:New-ScaleSetImage{ [CmdletBinding()] <# .SYNOPSIS Creates a new Application Server, installs Business Central, sys-preps it and saves it as a Scale Set Source .DESCRIPTION ... #> param( [Parameter(Mandatory = $true)] [string] $ResourceGroupName, [Parameter(Mandatory = $true)] [string] $ResourceLocation, [Parameter(Mandatory = $true)] [string] $Name, [Parameter(Mandatory = $false)] [string] $BCVersion, [Parameter(Mandatory = $false)] [string] $BCCumulativeUpdate, [Parameter(Mandatory = $false)] [string] $BCLanguage, [Alias("VirtualNetworkName")] [Parameter(Mandatory = $true)] [string] $VNetName, [Parameter(Mandatory = $true)] [string] $VMName, [Parameter(Mandatory = $true)] [string] $VMImagePublisher, [Parameter(Mandatory = $true)] [string] $VMImageOffer, [Parameter(Mandatory = $true)] [string] $VMImageSku, [Parameter(Mandatory = $true)] [string] $VMSize, [Parameter(Mandatory = $true)] [PSCredential] $VMCredentials, [Parameter(Mandatory = $true)] [int] $VMDiskSizeInGb, [Parameter(Mandatory = $true)] [string] $VMStorageAccountType, [Parameter(Mandatory = $true)] [string] $VMDataDiskName, [Alias("NetworkInterfaceName")] [Parameter(Mandatory = $true)] [string] $NicName, [Alias("NetworkInterfacePrivateIP")] [Parameter(Mandatory = $false)] [string] $NicPrivateIP, [Parameter(Mandatory = $false)] [string] $SubnetName, [Alias("PublicIPName")] [Parameter(Mandatory = $false)] [string] $PipName, [Alias("PublicIPDomainNameLabel")] [Parameter(Mandatory = $false)] [string] $PipDnsLabel ) process { # Put Script in Autostart # Download and Install Business Central # Deactivate default service # Call Sys Prep # Put created VM as Scale Set Source # Copy arguments for NIC creation from parent call $VMArguments = @{} foreach ($param in $PsBoundParameters.GetEnumerator()| Where-Object {$_.Key -notlike "BC*"}){ $VMArguments.Add($param.Key,$param.Value) } # Create new VM (as Application Server), might be a job, might be a VM-object (if VM already exists) $vm = New-CustomAzVm @VMArguments -AsJob if ($vm.GetType().ToString() -ne "Microsoft.Azure.Commands.Compute.Models.PSVirtualMachine"){ # Means: Job is currently running / VM is currently being deploy # use Write-Host "Receiving job..." $vm = Receive-Job -Job $vm -Wait Write-Host "Job received" $vm # to get the VM-object } $url = Get-BusinessCentralDownloadUrl -Version $Version -CumulativeUpdate $CumulativeUpdate -Language $Language } } Export-ModuleMember -Function New-ScaleSetImage |