Azure Power Shell - How to change network subnet - powershell

I'm trying to change an existing VM deployed via Resource Manager in Azure. The VM is configured with a wrong VirtualNetwork / Subnet. Changing this via portal.azure.net is not possible.
I've managed to retrieve the required network adapter by running: $adapter = Get-AzureRmNetworkInterface -Name xxxxx -ResourceGroupName xxxxx.
I can see the current configured subnet id via $adapter.IpConfigurations.Subnet and I've retrieved the new subnet via $net = Get-AzureRmVirtualNetwork -ResourceGroupName xxxxx -Name xxxxx.
I tried changing the $net.IpConfigurations.Subnet.Id = $net.Subnets.Id but I get a failure :
Subnet default referenced by resource xxxx is not the same Virtual
Network ....
Can anybody tell me how to change the virtual network that a network adapter is using if it was deployed using Resource Manager (the "Classic" has the simple Set-Subnet command).

Changing the Virtual Network for an exiting ARM deployed VM is not possible. But, changing the subnet for a VM is quite easy.
Login the Azure Portal
In Resource groups, choose the resource group your VM is in.
Choose your VM in the resources list of your resource group.
in Setting blade of your VM, and choose Network Interfaces.
Select the network interface you want to change, and click IP Address.
Choose a Subnet, and specify an IP address, or choose Dynamic Assignment.
If none of the exiting subnets meets your requirement, click your Virtual network to create a new subnet.
If you really want to change the Virtual Network of your VM, you can backup your OS Disk, and create a new VM with the OS Disk, and of course with the desired Virtual Network.

Related

How to add new local user in Azure VM through the PowerShell?

I have VM machine running which is not part of the domain and I would like to add the new local user through the PowerShell. Is this possible to do?
Once you have created your VM in Azure you will be able to interact with it as any other windows machine via PowerShell.
You will create a New-PSSession to the machine (you will use the ip adress for the VM as the computername):
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/new-pssession?view=powershell-6
You will then enter the session and create the local user: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.localaccounts/new-localuser?view=powershell-5.1
The main issue you may run into is, depending on firewall rules, you may not be able to directly access your azure VM. You will likely need to create a VPN in azure, include your Azure VM in that VPN, and then access the VPN from your local machine before you are able to establish a connection to the Azure VM. Please see the documentation for setting this up here: https://learn.microsoft.com/en-us/azure/vpn-gateway/vpn-gateway-howto-point-to-site-resource-manager-portal.

How to point multiple domain names to one compute engine in Google Cloud

I have multiple domain names and I want all of them point to the same webserver I have on google compute engine instance, how can I do that?
You don't need to have a separate static IP address per website—you can serve an arbitrary number of sites from a single VM by using a feature such as Apache virtual hosts which let you serve a different site depending on the hostname that is requested by the user.
As Per the Google Compute Engine docs on static IP addresses:
"An instance can have only one external IP address. If it already has an external IP address, you must first remove that address by deleting the old access configuration, then adding a new access configuration with the new external IP address"
but using Protocol Forwarding
You can archive multiple external IPs for one VM instance, but need some configuration. 1) By default, VM will be assigned with an ephemeral external IP, you can promote it to static external IP, which will remain unchanged after stop and restart. 2) Extra external IPs have to be attached to ForwardingRules which target the VM. You can use (or promote to) static IPs as well.
The command you may want to use would be:
1) Create a TargetInstance for your VM instance:
gcloud compute target-instances create <target-instance-name> --instance <instance-name> --zone=<zone>
2) Create a ForwardingRule pointing to the TargetInstance:
gcloud compute forwarding-rules create <forwarding-rule-name> --target-instance=<target-instance-name> --ip-protocol=TCP --ports=<ports>

Set-AzureRmNetworkInterface : Private static IP address does not belong to the range of subnet prefix

I have recently created a virtual machine in Azure where I have installed WordPress and MySQL in it. I have created a Web App too. Now I need to assign my static Web App IP address to the Virtual machine I created. I tried the following commands but no luck there.
New-AzureReservedIP –ReservedIPName IP –Location "South Central US" -ServiceName ServName
I am using latest Azure Powershell in my virtual machine. When I search for a solution people are saying the commands I used are not compatible with the latest powershell. So I used the commands explained here as follows.
$nic=Get-AzureRmNetworkInterface -Name networkinterfacename -ResourceGroupName resouorcegrpupname $nic.IpConfigurations[0].PrivateIpAllocationMethod = 'Static' $nic.IpConfigurations[0].PrivateIpAddress = 'ip address' Set-AzureRmNetworkInterface -NetworkInterface $nic
But when I run I am getting error as
Set-AzureRmNetworkInterface : Private static IP address does not belong to the range of subnet prefix 10.0.0.0/24.
Any help is much appreciated. Thanks in advance.
Note : I have logged in to the Powershell and I am able to run the commands Add-AzureAccount, Select-AzureSubscription, Get-AzureStorageAccount.
Private static IP address does not belong to the range of subnet prefix 10.0.0.0/24.
This error message has clearly described the root cause of this issue. I suppose that the static IP address doesn't reside in the subnet 10.0.0.0/24.
You have two options to overcome this issue:
Change the static IP address. (Choose an available IP from the subnet 10.0.0.0/24)
Create a new subnet which contains your static IP address.
Note: All the subnets must belong to same VNET. Azure doesn't support move the VM to another VNET.
Here is a good article about how to move the VMs between the subnets.

Trigger task in AzureVM from local machine via command line

What is the way to trigger a task that is in task manager of AzureVM from command prompt of my local machine??
I tried this (with AzureVm and task names)
schtasks /run /s <VMName> /tn <TaskName>
This gave me the error
ERROR: The network path was not found.
Both AzureVM and local machine are running windows server 2012 R2.
To properly answer this question it will depend on what network connectivity exists between your local machine and the Azure VM. If you are connecting to the Azure VM over the internet then you need to either open a port for the VM on the load balancer, or you need to create a public IP address for the specific VM so that you can access all of the ports of the VM over the internet. Alternatively if you have a site to site or point to site connection to the VM then you can access the VM directly as you are doing.
Assuming that you are connecting to the VM over the internet, the easiest approach is going to be to create a public IP address for the VM, then connect to the VM using either the DNS name of the public IP address or just using the IP address directly. If you wanted to go through the load balancer then you would need to determine which port and protocol (UPD/TCP) schtasks is using so that you can open the correct port.
Also remember that the Windows Firewall on the VM may need to be updated to allow scheduled tasks to be executed remotely.
An alternate option is to use Remote PowerShell to execute the schtasks on the VM. Please see the following blog post that provides great overview on using remote powershell with Azure VMs: http://michaelwasham.com/windows-azure-powershell-reference-guide/introduction-remote-powershell-with-windows-azure/

How do I get a public IP for my Azure VM?

I have deployed a VisualStudio web app onto my Azure VM and I need a public IP to the VM so that the public can use my URL to access the web.
The Azure Doc. says: "Every Virtual Machine is automatically assigned a free public Virtual IP (VIP) address. "
..but I can't find how to get this IP.
I tried "VM > Powershell > ipconfig > IPv4 Address. . . . . ."
but I cannot ping this IP from the Internet.
"Every Virtual Machine is automatically assigned a free public Virtual IP (VIP) address"
In order to find out the public ip goto-
Azure portal and then your VM dashboard. Here at the right side you see a quick glance tab under which you will be able to see the public IP. Snapshot for your reference-
Using powershell you can use below command for the same.
Get-AzureVM -ServiceName "testservice" -Name "testvm" | select PublicIPAddress
NOTE - Public IP will be null if instance is in stopped state. To know more on public IP you can read this-
https://azure.microsoft.com/en-in/documentation/articles/virtual-networks-instance-level-public-ip/
ICMP (ping) is not permited to bypass Azure gateways, Try check connectivity with other TCP tools (ie. TELNET / SSH / RDP etc ).
To get the IP address of the VM - you can simply go to www.whatismyip.com