Dynamically get Hyper-V Servers, get all the VM dns names
has idea?
i'm working hours on i'm not getting anywhere.
foreach($system in $systems){ $hyperv = invoke-command $system.dnshostname -scriptblock {get-windowsfeature | {$_.name -match "hyper-v"} | {$_.installed -match $true}} } $system.dnshostname gets every dnshostname of systems in ad. don't know how ones installed hyper-v features.
the way written inly can information filtered features, feature name...
i still couldn't find way vms name. get-vm delivers vm name isn't same dns name.
how query ad using serviceprincipalname filter?
e.g.:
"(&(objectclass=computer)(|(serviceprincipalname=*hyper-v*)(serviceprincipalname=*microsoft virtual*)))"
with dsquery:
-----------------
dsquery * -filter "(&(objectclass=computer)(|(serviceprincipalname=*hyper-v*)(serviceprincipalname=*microsoft virtual*)))" -attr cn operatingsystem serviceprincipalname
ps without ad module:
-----------------------------
[adsisearcher]'(&(objectclass=computer)(|(serviceprincipalname=*hyper-v*)(serviceprincipalname=*microsoft (virtual*)))').findall() | select @{n='cn'; e={$_.properties.cn}}, @{n='operatingsystem';e={$_.properties.operatingsystem}}, @{n='serviceprincipalname'; e={ $_.properties.serviceprincipalname}}
ps ad module:
------------------------
get-adcomputer -ldapfilter "(&(objectclass=computer)(|(serviceprincipalname=*hyper*)(serviceprincipalname=*microsoft virtual*)))" -properties cn, operatingsystem, serviceprincipalname
the result can narrow down giving specific filter serviceprincipalname.
rgds,
Windows Server > Windows PowerShell
Comments
Post a Comment