Hyper-v VM’s hostname in Registry is no longer accurate

Welcome Forums General PowerShell Q&A Hyper-v VM’s hostname in Registry is no longer accurate

Viewing 3 reply threads
  • Author
    Posts
    • #273591
      Participant
      Topics: 3
      Replies: 2
      Points: 29
      Rank: Member

      On my Windows 10 Pro Hyper-V, I have a Server 2019 VM whose hostname is the default WIN-MUMBOJUMBO. On searching the Intertubes for a possible solution to find this hostname ‘scriptually’, I came across this solution, which unfortunately no longer works:

      (Get-Item “HKLM:\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters”).GetValue(“Hostname”)

      When I run the above line, I get a different value for ‘Hostname’ than the WIN-MUMB…

      So, is there another way to determine PowerShell scriptually the hostname of the VM(s). I need this so that I can then run Configurations on the different VMs I intend to create on Hyper-V.

      Any help is appreciated.

    • #273693
      Participant
      Topics: 5
      Replies: 349
      Points: 632
      Helping Hand
      Rank: Major Contributor
    • #273783
      Participant
      Topics: 3
      Replies: 2
      Points: 29
      Rank: Member

      Thanks for the reply.

      Your solution will work if I am able to know WIN-MUMBO… ahead of time. For example, I have a farm of new VMs I have deployed whose default “WIN-Mumbo..” default computernames I don’t know yet. I want to be able to get these default computernames so that I can do what you suggested to change their names. Conceptually this is what I am looking for:

      $oldComputerName = Some-FunctionToGetVMsComputerName

      $oldComputerName | Rename-Computer -NewName "Kangaroo"

      Hope this helps clarify my request. Thank you.

       

    • #273798
      Participant
      Topics: 3
      Replies: 2
      Points: 29
      Rank: Member

      Well I think I may have found the solution after all.

      After reading ‘random commandline’s suggestion on Invoke-Command, I looked it up and apparently there is a VMName parameter for Invoke-Command, so I was able to accomplish what I wanted:

      Invoke-Command -VMname $vmName -ScriptBlock { Rename-Computer -NewName 'Kangaroo' -Restart }

      Thank you.

Viewing 3 reply threads
  • You must be logged in to reply to this topic.