Azure: Change VM name using Cmdlets - powershell

I erroneously named a virtual machine.
Using the Azure Powershell I am able to rename cloud services using Set-AzureService. There doesn't seem to be a Set-AzureVM command to rename virtual machines.
Is there another way to rename a virtual machine? I do not wish to change the VM's service name.
EDIT, further clarity:
I do NOT want to rename the cloud service name or the machine/computer name in the VM instance. I purely wish to change the associated name that my virtual machine is labeled with. i.e. the name you see in the portal
The names in the column with the red arrow:

Set-AzureService does not change service name! It only changes deployment name and description. These properties are just kind of Meta-Data associated with the hosted service deployment. You cannot change cloud service name (**cloudservice**.cloudapp.net) by any means! You can only create or delete cloud service.
And, not you can't change VM's name via Azure PowerShell cmdlets, but most probably you can do this by remote power shell to the targeted VM. Please note that renaming a Windows machine always requires restart!
For information on how to use Remote Power Shell on Azure VM, please check out this article.
UPDATE
I think what you need is the UpdateRole action on the management API. It has parameter RoleName which is desribed as:
RoleName
Required. Specifies the name for the virtual machine. The name must be unique within Windows Azure.
And the powershell cmdlet to use is: Update-AzureVM

Related

Get Azure VM AD Domain

Is there a way to query the AD domain of a VM on azure using the REST API? The only way I found was to use a run command and use powershell on the VM to get the domain name, this however has a significant delay and I would like to find a faster method.
Run Command documentation:
https://learn.microsoft.com/en-us/azure/virtual-machines/windows/run-command
You can check the role assignments of the VM using
GET https://management.azure.com/subscriptions/subId/resourcegroups/rgname/providers/resourceProviderNamespace/parentResourcePath/resourceType/resourceName/providers/Microsoft.Authorization/roleAssignments?api-version=2015-07-01
See: https://learn.microsoft.com/en-us/rest/api/authorization/roleassignments/listforresource#roleassignment

How to use Powershell to script a domain user's temporary file location

I am writing deployment scripts using Powershell to install Scheduled Tasks, Windows Services and IIS App pools.
Each of these items will be run under the identity of an Active Directory domain user. My issue is that the business rules enforced on the servers state that no process or user can write to the C drive.
Therefore i need to direct each installed object to use the E drive for temporary storage of any kind.
How can i assign the temp directory environment variable of a domain user using powershell on a server that will have no 'knowledge' of that domain user until i instantiate the installed objects?
When it comes to the IIS app pools I have found a (hacky) solution that could potentially work in this:
https://serverfault.com/questions/711470/applicationpoolidentity-environment-variables-iis
that requires me to set the app pool to run as the profile, fire up the pool, snoop registry keys, obtain a SID, and then modify registry keys to set the environment variable for the temp drive.
Is there an easier way? And how could i do this for services and scheduled tasks?
Pie in the sky - i write one powershell script to modify the temp env parameter for this one domain account before installing any of these objects and then when they are installed it "just works".
Any suggestions?

Managing Multiple servers in an environment with Powershell DSC

I want to manage the servers in our staging pipeline with Powershell DSC (push model). The servers map to the environments as following
Development: 1 server
Test: 2 servers
UAT: 2 servers
Production: 2 servers
The server(s) within one environment do have the same configuration. But the configuration is different between the environments. I wanted to go with the push model because I do not have to setup a pull server.
Powershell DSC offers the option to manage the configuration via configuration data in a separate file But this comes with the caveat that you need to specify a node name that matches the respective server name. And that means, I need to copy the configuration data for each server in one environment. And when changing the configuration I need to remember that there is a second place where I need to update the configuration value.
Additionally, I do not really care about the server names. If the servers are exchanged tomorrow for new servers, the configuration should be just applied which is relevant to the environment.
What is the best practice approach to manage multiple servers within one environment with the same configuration?
Check the links, I think they cover scenerio
Using A Single DSC Configuration for Multiple Servers
enter link description here
DSC ConfigurationNames with multiple nodes
enter link description here
The mof file that gets produced does not contain the nodename inside it. So as long as you build a generic configuration, you can rename it after the fact at deploy time.
You can create one config for each environment with some generic name. Then enumerate the list of servers and make a copy of the config for each one with that servers name.
You can take it a step further. Have a share where you create a folder for each server that matches the server's name. Then copy the mof for that server into that folder with a name of localhost.mof. You can then run Start-DSCConfiguration -Path \\server\share\$env:computername from that machine as part of my deployment script.

Is it possible for DSC to deal with the creation and advanced configuration of Virtual Machines?

I'm trying to create a configuration, using PowerShell DSC, that would help me create a SharePoint farm using Virtual Machines. Assuming that I have a Windows 10 machine with Hyper-V installed I would like my configuration script to create the required VMs, for example DC, SPA1, SPw1, SPW2 and SPDB1, configure their network connections and connect to a domain controller (DC1), then proceed to install the SharePoint/SQL Server prerequisites and installation before going on to configure the farm, once available.
I've created configurations that complete various stages but I am unable to figure out how to connect them to work in an orchestrated manor. For example I can create the VMs or perform the install and configuration of SharePoint but I can't get these configurations to work in tandem.
Having read the DSC documentation I thought that is might be possible using composite resources but I am unable to get the configuration to continue onto the new Virtual Machine after creation.
From the composite resource documentation:
configuration RenameVM
{
Import-DscResource -Module TestCompositeResource
Node localhost
{
xVirtualMachine VM
{
VMName = "Test"
SwitchName = "Internal"
SwitchType = "Internal"
VhdParentPath = "C:\Demo\VHD\RTM.vhd"
VHDPath = "C:\Demo\VHD"
VMStartupMemory = 1024MB
VMState = "Running"
}
}
Node "192.168.10.1"
{
xComputer Name
{
Name = "SQL01"
DomainName = "fourthcoffee.com"
}
}
}
Ideally the node names would be dynamically declared in the configuration data and not explicitly defined I.P addresses. I'm also having trouble with my Hyper-V configuration creating multiple switches but that's a separate issue. So I guess my question is:
Is it possible to create a configuration that deals with the creation and advanced configuration of Virtual Machines?
The problem you are running up against is a conceptual one of what DSC does.
Reading the document that you linked, it says
Configurations are declarative PowerShell scripts which define and configure instances of resources. Upon running the configuration, DSC (and the resources being called by the configuration) will simply “make it so”, ensuring that the system exists in the state laid out by the configuration.
DSC is designed to configure an instance of a resource. At its basic level a DSC configuration is run on a single machine, configuring that machine into a specified state.
DSC scripts should be constrained to work within the boundaries of the machine that they are running on. It seems that this is part of the problem you are experiencing.
If you have two sets of scripts. A Deploy VM script, that runs against a hyper-v server and a Sharepoint build that then configures the VM once it has launched. It seems that what you are trying to do is launch the Sharepoint script from within the hyper-v deploy script. At that stage though the Sharepoint server is outside of the boundary of control of the hyper-v server (apart from its atomic VM capabilities, start,stop, delete etc)
Instead what I would suggest you do is see them as two entirely separate entities. There is no need to have a scripted connection between creating a VM and installing Sharepoint.
At a high level your pipeline would look something like this
Run deploy configuration to create a new VM. At the point where that VM is running that configuration is complete. It has no other actions.
The VM builds and starts, part of its initial configuration is to run a bootstrap script that tells it its function.
The VM contacts the DSC server, tells it its function, and requests any configurations that are available for it.
The VM downloads its configurations, and configures itself as a Sharepoint Server (or SQL Server, etc)
If there are external dependencies, i.e. you can install Sharepoint before SQL has completed, then simply have a dependson for a shared file. i.e. if \\server\share\sqlcompleted.txt exists Or whatever other mechanism fits your environment.
Building servers this way removes dependencies, it means that if you decide you want to switch to ESX then all you need to change is your deploy script. Equally if you move everything to a cloud deployment.

Get the machine name of an Azure worker or web role using PowerShell?

Is there any way using the PowerShell Azure cmdlets to get the machine name on which an Azure worker or web role is running? Specifically, I'm looking for the name that starts with "RD". I'm not 100% sure if I'm searching for this using the right terminology, because my results are clouded with information about Azure Virtual Machines. I've also been exploring the objects returned from such calls as Get-AzureDeployment and Get-AzureVM, but haven't found the "RD" name anyplace yet.
I've also found the discussion here, but wondering if it's out of date: http://social.msdn.microsoft.com/Forums/windowsazure/en-US/73eb430a-abc7-4c15-98e7-a65308d15ed9/how-to-get-the-computer-name-of-a-webworker-role-instance?forum=windowsazuremanagement
Motivation: My New Relic monitoring often complains "server not reporting" for instances that have been decommissioned. New Relic's server monitoring knows only the "RD..." names, and I'm looking for a quick way to get a list of these from Azure so that I can compare and see if New Relic is only complaining about old instances or if there's a real problem with one of the current instances.
You can actually get more significant host names than RD... by setting the vmName key in the cloud service's ServiceConfiguration file.
Then, your host names will be of the form vmnameXX, where XX is the instance number of the role. (i.e. "MyApp01", "MyApp02", ...)
For details on this, see the links below:
https://azure.microsoft.com/documentation/articles/virtual-networks-viewing-and-modifying-hostnames/
http://blogs.msdn.com/b/cie/archive/2014/03/30/custom-hostname-for-windows-azure-paas-virtual-machines.aspx