简体   繁体   中英

Retrieve Azure VM FQDN

I am looking for a way to check if we have Azure Virtual machines that are not domain joined. I am looking for a PS command or script to query the entire Azure VM estate and return a list with all VMs ideally in csv format. Those VMs that are not domain joined will be a subject to another task, of course - join to the domain.

The command which works fine to retrieve the FQDN is

Get-WmiObject -Namespace root\cimv2 -Class Win32_ComputerSystem | Select Name, Domain

However, this works only for individual machine. I was told to use foreach loop to query all VMs but I don't know how.

Psremoting is enabled and tested OK, same for WSMAN.

Here is the foreach command to find the list of VM's and domain names.

connect-azaccount
$vmlist=get-azvm | select -Property Name
foreach( $item in $vmlist){
Get-WmiObject  -Namespace root\cimv2 -ComputerName $item  -Class Win32_ComputerSystem | Select Name, Domain
}

在此处输入图像描述

If you want to use get-wmiobject cmdlet you need to enable wsman Here is the document for using enabling wsman .

Instead of wsman you can even run get-computerinfo if you run this command, you will get a property called csdomain which is the information of domain name.

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM