Hallo Everyone,
i need to run a Script only on the VM's which are not member of our domain.
How can make a list of the VM's, which are in a "workgroup" and not a domain Member. Some server have FQDN although they are not in the domain.
Thank you for your support.
PS: I tried with Get-VM and Get-View, but i didnt find the right property.
Ciao
You can try to use this script.
The script checks if a Windows VM (That is PowerOn) is joined to domain
You must use a local VM administrator user (for $ VMCredential)
#Credential for access to vCenter
$credential = Get-Credential
#Credential with administrator role for login to VM
$VMCredential = Get-Credential
#vcenter
$vcenter = "<vcenter fqdn>"
connect-viserver $vcenter -Credential $credential
#List of VM
$VDIs = (Get-VM).where{$_.PowerState -eq 'PoweredOn' -and $_.Guest.OSFullName -match 'Windows'}
$script = @"
(gwmi win32_computersystem).partofdomain
"@
foreach ($VDI in $VDIs){
$value = Invoke-VMScript -VM $VDI -ScriptType Powershell -ScriptText $script -GuestCredential $VMCredential
if ($value.ScriptOutput -like "*True*") {
Write-Host "$VDI is joined to domain"
}
else
{
Write-Host "$VDI is not joined to domain"
}
}
Disconnect-VIServer
thank you Fabio for the Script.
I will give it a Try. But i think i will have the next Problem. I found out that not all Server have the Same Administrator Password 😞
I think i have to do it Manually, and log on every single server.