有人可以請我解決以下問題或更好的方法來接近它 - 我所要做的就是返回有關所選服務器的一些信息,幷包含AD Description
Field:Powershell - WMI&AD對象
$cred = Get-Credential -Credential "test_user"
$servername = "servername"
[wmi]$os = Get-WmiObject -Class win32_operatingsystem -ComputerName $servername -Credential $cred
[wmi]$cs = Get-WmiObject -Class win32_computersystem -ComputerName $servername -Credential $cred
###[wmi]$ad = Get-ADComputer $servername -Properties Description -Credential $cred | Select-Object -Property description
[hashtable]$osProperties = @{
'Description' = $ad;
'OSVersion'=$os.version;
'OSBuild'=$os.buildnumber;
'SPVersion'=$os.servicepackmajorversion;
'Model'=$cs.model;
'Manufacturer'=$cs.manufacturer;
'RAM'=$cs.totalphysicalmemory/1GB -as [int];
'Sockets'=$cs.numberofprocessors;
'Cores'=$cs.numberoflogicalprocessors;
'SystemType'=$cs.SystemType}
$osproperties
將返回:
Manufacturer VMware, Inc.
RAM 4
OSVersion 6.1.7601
SystemType x64-based PC
SPVersion 1
Cores 2
Model VMware Virtual Platform
OSBuild 7601
Sockets 2
但是,如果我不選擇行get-adcomputer
我得到以下錯誤:
Cannot convert value "@{description=PROD - Portsmouth - VM - W2K8R2 Monitoring Server}" to type "System.Management.ManagementObject". Error: "Cannot convert the "@{description=PROD - Portsmouth - VM - W2K8R2
Monitoring Server}" value of type "Selected.Microsoft.ActiveDirectory.Management.ADComputer" to type "System.Management.ManagementObject"."
At line:12 char:2
+ [wmi]$ad = Get-ADComputer $servername -Properties Description -Credential $cred ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : MetadataError: (:) [], ArgumentTransformationMetadataException
+ FullyQualifiedErrorId : RuntimeException
刪除變量$ ad之前的[wmi]。 – notjustme 2015-02-23 11:07:30
耶穌....也許我盯着那太久了! – Richard 2015-02-23 11:25:16