I'm currently writing a powershell script that provisions a virtual machine, more testing at the moment. The code at present
New-AzureQuickVM -ImageName $VMImage.ImageName -Windows -Name $VMName -ServiceName $VMName -AdminUsername $adminLogin `
-Password $adminPasswd -AffinityGroup $affinityGrp -InstanceSize $instanceSize -VNetName $virtualNetwork -SubnetNames $virtualSubnet -WaitForBoot
I can't see a parameter on MSDN to set the IP address of the VM. I know you can do it like this:
New-AzureVMConfig -Name $vmname -ImageName $img –InstanceSize Small | Set-AzureSubnet –SubnetNames $sub | Set-AzureStaticVNetIP -IPAddress 192.168.4.7 | New-AzureVM –ServiceName $vmsvc1 –AffinityGroup "NorthEuropeAG";
But it seems neater to use the New-AzureQuickVM. Am I able to just pipe New-AzureQuickVM to Set-AzureStaticVNetIP similar to how New-AzureVMConfig works or is there a better way to do it?
The purpose of the New-AzureQuickVM is to create the VM with absolute minimum number of required fields. Like the Quick Create.
On the Other hand the New-AzureVMConfig give you all options that are necessary to have the StaticIP , as you have mentioned or something like the following.
New-AzureVMConfig -Name "testvm123" -InstanceSize "Small" -ImageName $ImageName |
Add-AzureProvisioningConfig -Windows -AdminUsername $username-Password $password |
Set-AzureSubnet -SubnetNames "Subnetname" |
Set-AzureStaticVNetIP -IPAddress "10.0.0.22" |
New-AzureVM -ServiceName "somevmservicename"
Only way to do it is by setting the IP after VM creation:
Get-AzureVM -ServiceName $VMName -Name $VMName | Set-AzureStaticVNetIP -IPAddress 192.168.4.7 | Update-AzureVM
Related
Don't know where exactly it is failing. I'm using VS Code to create the following script and running from there only:
$ResourceGroupName="powershell-grp"
$Location="North Europe"
$AppServicePlanName="PowershellAppService1975"
$WebAppName="PowershellWebApp1975"
Connect-AzAccount
Get-AzSubscription -SubscriptionName "Visual Studio Enterprise" | Select-AzSubscription
New-AzResourceGroup -Name $ResourceGroupName -Location $Location
New-AzAppServicePlan -Name $AppServicePlanName -Location $Location -Tier "B1" -NumberofWorkers 1 -ResourceGroupName $ResourceGroupName
New-AzWebApp -ResourceGroupName $ResourceGroupName -Name $WebAppName -Location $Location -AppServicePlan $AppServicePlanName
And in the powershell console, i get this error:
New-AzAppServicePlan: C:\Temp\AzureCmds\Azure Powershell-WebApp\Script1.ps1:9:1
Line |
9 | New-AzAppServicePlan -Name $AppServicePlanName -Location $Location -T …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Operation returned an invalid status code 'Unauthorized'
New-AzWebApp: C:\Temp\AzureCmds\Azure Powershell-WebApp\Script1.ps1:10:1
Line |
10 | New-AzWebApp -ResourceGroupName $ResourceGroupName -Name $WebAppName …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Operation returned an invalid status code 'Unauthorized'
Used -debug cmdlet option that gave the exact info on the issue.
The resource group location supported 0 instances for the chosen app service plan. Therefore, deployed app service plan and the web app to an altogether different location
I can find the VM by using
$vm = Get-AzureRmVM -ResourceGroupName "MyResource" -Name "MyVM"
But how can I find the network interface associated with this VM?
Once you have your VM in a variable $vm (as shown below)
$vm = Get-AzureRmVM -ResourceGroupName "MyResource" -Name "MyVM"
You can get the NIC by finding the interface that matches the ID from your VM
$nic = Get-AzureRmNetworkInterface
| Where {$_.Id -eq $vm.NetworkProfile.NetworkInterfaces[0].Id}
Is there a way to change/set SQL connectivity to Public(Internet) in a SQL Server azure vm while deploying sql vm or once deployed using powershell?
Part of my provisioning script looks like this. Will updating something in $vmConfig work?
# Create SQL Server
$vmConfig = New-AzureRmVMConfig -VMName $ServerName -VMSize 'Standard_D2_v2' | `
Set-AzureRmVMOperatingSystem -Windows -ComputerName $ServerName -Credential $adminCredentials -ProvisionVMAgent -EnableAutoUpdate | `
Set-AzureRmVMSourceImage -PublisherName "MicrosoftSQLServer" -Offer "SQL2017-WS2016" -Skus "SQLDEV" -Version "latest" | `
Set-AzureRmVMOSDisk -Name $osDiskName -VhdUri $osDiskUri -CreateOption "FromImage" | `
Add-AzureRmVMNetworkInterface -Id $nic.Id
# Add SQL Server VM extension
New-AzureRmVM -VM $vmConfig -ResourceGroupName $ResourceGroupName -Location $Location
Set-AzureRmVMSqlServerExtension -Name "SqlIaasExtension" -Version "1.2" -VMName $ServerName -ResourceGroupName $ResourceGroupName `
-Location $Location
Thank you
So I was lingering around my Azure account, and found some way to set static IP.
Commands to set static IP is:
Get-AzureVM -ServiceName <service-name> -Name <name> | Set-AzureStaticVNetIP -IPAddress <ip-address> | Update-AzureVM
When I do:
Get-AzureVM -ServiceName <service-name> | Set-AzureStaticVNetIP -IPAddress <ip-address> | Update-AzureVM
; or:
Get-AzureVM -Name <name> | Set-AzureStaticVNetIP -IPAddress <ip-address> | Update-AzureVM
it still succeeded.
What's the differences between ServiceName and Name?
And, related question. How do I list VMs that have IP address set to static?
According to manual:
-Service-name return information about all VM running in cloud service, -Name return info about exactly one VM.
I am writing a Powershell script to add/remove/edit IP restrictions for websites using Powershell. So far I am able to add restrictions, however wondering the best way to edit an existing ip restriction.
Add
Add-WebConfiguration -Filter /system.webserver/security/ipsecurity -Value #{ipAddress=$ipAddress;subnetMask="255.255.255.255";allowed=$allowed} -Location $websiteName -PSPath "IIS:\"
Edit
I have tried various combinations of:
Set-WebConfiguration -Filter system.webServer/security/ipSecurity/add[#ipAddress='192.123.123.123'] -Name "ipAddress" -Value $ipAddress -Location $websiteName -PSPath "IIS:\"
Set-WebConfigurationProperty -Filter system.webServer/security/ipSecurity/add[#ipAddress='192.123.123.123'] -Value = #{ipAddress=$ipAddress;subnetMask="255.255.255.255";allowed=$allowed} -Location $websiteName -PSPath "IIS:\"
Is the best way essentially to clear all, and recreate each time?
I had the same problem and fixed it like this -
# Compose new entry
$value = #{allowed="true";ipAddress="192.168.0.1"}
# Add new entry to restrictions
Add-WebConfigurationProperty -Filter 'system.webServer/security/ipSecurity' -PSPath "IIS:\Sites\MySite\" -Location "MyService" -Name "." -Value $value -ErrorAction Stop