通過使用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