尋找域內所有的Windows Server 2012 R2的伺服器,並區分出哪些是物理機,那些是虛擬機器

來源:互聯網
上載者:User

標籤:powershell 基本命令

通過使用Get-Adcomputer和Get-Wmiobject 組合來實現。

思路是這樣的,先看一台伺服器的屬性值有什麼可用利用的。


[12r2-dc]: PS C:\> Get-ADComputer -Identity 12r2-dc -Properties *



AccountExpirationDate                :

accountExpires                       : 9223372036854775807

AccountLockoutTime                   :

AccountNotDelegated                  : False

AllowReversiblePasswordEncryption    : False

AuthenticationPolicy                 : {}

AuthenticationPolicySilo             : {}

BadLogonCount                        : 0

badPasswordTime                      : 0

badPwdCount                          : 0

CannotChangePassword                 : False

CanonicalName                        : abc.com/Domain Controllers/12R2-DC

Certificates                         : {System.Security.Cryptography.X509Certificates.X509Certificate}

CN                                   : 12R2-DC

codePage                             : 0

CompoundIdentitySupported            : {False}

countryCode                          : 0

Created                              : 10/9/2016 10:29:00 PM

createTimeStamp                      : 10/9/2016 10:29:00 PM

Deleted                              :

Description                          :

DisplayName                          :

DistinguishedName                    : CN=12R2-DC,OU=Domain Controllers,DC=abc,DC=com

DNSHostName                          : 12R2-DC.abc.com

DoesNotRequirePreAuth                : False

dSCorePropagationData                : {10/9/2016 10:29:03 PM, 12/31/1600 4:00:01 PM}

Enabled                              : True

HomedirRequired                      : False

HomePage                             :

instanceType                         : 4

IPv4Address                          : 169.254.15.118

IPv6Address                          :

isCriticalSystemObject               : True

isDeleted                            :

KerberosEncryptionType               : {RC4, AES128, AES256}

LastBadPasswordAttempt               :

LastKnownParent                      :

lastLogoff                           : 0

lastLogon                            : 131498622097210925

LastLogonDate                        : 9/10/2017 11:04:43 PM

lastLogonTimestamp                   : 131495834837332604

localPolicyFlags                     : 0

Location                             :

LockedOut                            : False

logonCount                           : 1860

ManagedBy                            :

MemberOf                             : {CN=Pre-Windows 2000 Compatible Access,CN=Builtin,DC=abc,DC=com, CN=Cert

                                       Publishers,CN=Users,DC=abc,DC=com}

MNSLogonAccount                      : False

Modified                             : 9/12/2017 7:23:19 PM

modifyTimeStamp                      : 9/12/2017 7:23:19 PM

msDFSR-ComputerReferenceBL           : {CN=12R2-DC,CN=Topology,CN=Domain System

                                       Volume,CN=DFSR-GlobalSettings,CN=System,DC=abc,DC=com}

msDS-GenerationId                    : {45, 30, 43, 189...}

msDS-SupportedEncryptionTypes        : 28

msDS-User-Account-Control-Computed   : 0

Name                                 : 12R2-DC

nTSecurityDescriptor                 : System.DirectoryServices.ActiveDirectorySecurity

ObjectCategory                       : CN=Computer,CN=Schema,CN=Configuration,DC=abc,DC=com

ObjectClass                          : computer

ObjectGUID                           : bf0a2518-aa9c-4cb9-ab8e-09be04b3e27b

objectSid                            : S-1-5-21-2770570338-4234891044-2636713416-1001

OperatingSystem                      : Windows Server 2012 R2 Standard

OperatingSystemHotfix                :

OperatingSystemServicePack           :

OperatingSystemVersion               : 6.3 (9600)

PasswordExpired                      : False

PasswordLastSet                      : 8/20/2017 4:58:11 PM

PasswordNeverExpires                 : False

PasswordNotRequired                  : False

PrimaryGroup                         : CN=Domain 

看到這裡就知道利用哪個屬性值了,過濾一下,用一個萬用字元運算式或是任何一個能把這個值抓住的條件就可以,再用一個選擇語句把名字選擇出來。

$computer = Get-ADComputer -Filter {operatingsystem -like "*20*"} | select -ExpandProperty name

然後運行了一下Get-Wmiobject,結果如下:

[12r2-dc]: PS C:\> Get-WmiObject -Class win32_computersystem



Domain              : abc.com

Manufacturer        : Microsoft Corporation

Model               : Virtual Machine

Name                : 12R2-DC

PrimaryOwnerName    : Windows User

TotalPhysicalMemory : 2094039040


然後想到,如果把變數$computer傳遞進來,再把兩個屬性暴露出來,就會產生一個結果集,當然,你願意輸出到檔案自己再用管道符輸出就是了。


Invoke-Command -ComputerName $computer {Get-WmiObject win32_computersystem} -ErrorAction SilentlyContinue | select name,model | sort model



結果就是:

Name                                                        Model

----                                                        -----

12R2-SCCM                                                   Virtual Machine


本文出自 “沙丁魚” 部落格,請務必保留此出處http://shadingyu.blog.51cto.com/2617687/1965482

尋找域內所有的Windows Server 2012 R2的伺服器,並區分出哪些是物理機,那些是虛擬機器

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.