2017-12-18 6 views
-1

PowerShell 디스플레이에서 특정 값을 얻는 방법은 무엇입니까?특정 값을 선택하는 PowerShell 스크립트

예제 - 아래 스크립트를 실행할 때 나는 6 번째 값을 얻었지만 4 번째 행 값만 가져와야합니다.

명령 :

Get-WmiObject win32_logicaldisk -Filter "Drivetype=3 

출력 : 난 단지 "183760687104"값을 가져 오기 위해 필요

 
DeviceID  : C: 
DriveType : 3 
ProviderName : 
FreeSpace : 183760687104 
Size   : 255791026176 
VolumeName : 

. 그것을 성취하는 방법. 또한 FreeSpace 태그도 갖고 싶지 않습니다. 그냥 평범한 가치 "183760687104".

+0

이들은 객체의 속성입니다. 필요한 사람들을 보여줘야합니다. 귀하의 질문에 대한 대답은 [여기] (https://stackoverflow.com/q/47863699/3110834)입니다. –

답변

2

당신은 단지 이름으로 필드에 액세스 : Get-WmiObject이되지 않습니다

(Get-WmiObject Win32_LogicalDisk -Filter "Drivetype=3").FreeSpace 

하는 것으로 대신 Get-CimInstance를 사용한다.

$freespace = (Get-CimInstance Win32_LogicalDisk -Filter "Drivetype=3").FreeSpace 

을 당신이 원하는대로 당신은 $freespace를 사용할 수 있습니다

(Get-CimInstance Win32_LogicalDisk -Filter "Drivetype=3").FreeSpace 

당신이 변수에 값을 저장하려면

, 그냥 할당합니다. 둘 이상의 로컬 디스크가있는 시스템에서 표현식이 단일 배열이 아닌 값 배열을 리턴하므로 결과를 첨자 화하여 첫 번째 디스크 만 선택할 수도 있습니다. 당신이 gm을 통해 객체, 단지 파이프 발현에 접근 가능한 분야에 대해 잘 모를 ( Get-Member의 줄임말) 인 경우

PS C:\Users\User> (Get-CimInstance Win32_LogicalDisk -Filter "Drivetype=3").FreeSpace[0] 
94229651456 
PS C:\Users\User> (Get-CimInstance Win32_LogicalDisk -Filter "Drivetype=3")[0].FreeSpace 
94239125504 

:이 표현의 하나는 당신에게 하나의 번호를 제공해야합니다

Get-CimInstance Win32_LogicalDisk -Filter "Drivetype=3" | gm 

은 사용 가능한 모든 필드를 나열합니다.

PS C:\Users\User> Get-CimInstance Win32_LogicalDisk -Filter "Drivetype=3" | gm 


    TypeName: Microsoft.Management.Infrastructure.CimInstance#root/cimv2/Win32_LogicalDisk 

Name       MemberType Definition 
----       ---------- ---------- 
Clone      Method  System.Object ICloneable.Clone() 
Dispose      Method  void Dispose(), void IDisposable.Dispose() 
Equals      Method  bool Equals(System.Object obj) 
GetCimSessionComputerName Method  string GetCimSessionComputerName() 
GetCimSessionInstanceId  Method  guid GetCimSessionInstanceId() 
GetHashCode     Method  int GetHashCode() 
GetObjectData    Method  void GetObjectData(System.Runtime.Serialization.SerializationInfo info, Sys... 
GetType      Method  type GetType() 
ToString      Method  string ToString() 
Access      Property uint16 Access {get;} 
Availability     Property uint16 Availability {get;} 
BlockSize     Property uint64 BlockSize {get;} 
Caption      Property string Caption {get;} 
Compressed     Property bool Compressed {get;} 
ConfigManagerErrorCode  Property uint32 ConfigManagerErrorCode {get;} 
ConfigManagerUserConfig  Property bool ConfigManagerUserConfig {get;} 
CreationClassName   Property string CreationClassName {get;} 
Description     Property string Description {get;} 
DeviceID      Property string DeviceID {get;} 
DriveType     Property uint32 DriveType {get;} 
ErrorCleared     Property bool ErrorCleared {get;} 
ErrorDescription    Property string ErrorDescription {get;} 
ErrorMethodology    Property string ErrorMethodology {get;} 
FileSystem     Property string FileSystem {get;} 
FreeSpace     Property uint64 FreeSpace {get;} 
InstallDate     Property CimInstance#DateTime InstallDate {get;} 
LastErrorCode    Property uint32 LastErrorCode {get;} 
MaximumComponentLength  Property uint32 MaximumComponentLength {get;} 
MediaType     Property uint32 MediaType {get;} 
Name       Property string Name {get;} 
NumberOfBlocks    Property uint64 NumberOfBlocks {get;set;} 
PNPDeviceID     Property string PNPDeviceID {get;} 
PowerManagementCapabilities Property uint16[] PowerManagementCapabilities {get;} 
PowerManagementSupported  Property bool PowerManagementSupported {get;} 
ProviderName     Property string ProviderName {get;} 
PSComputerName    Property string PSComputerName {get;} 
Purpose      Property string Purpose {get;} 
QuotasDisabled    Property bool QuotasDisabled {get;} 
QuotasIncomplete    Property bool QuotasIncomplete {get;} 
QuotasRebuilding    Property bool QuotasRebuilding {get;} 
Size       Property uint64 Size {get;} 
Status      Property string Status {get;} 
StatusInfo     Property uint16 StatusInfo {get;} 
SupportsDiskQuotas   Property bool SupportsDiskQuotas {get;} 
SupportsFileBasedCompression Property bool SupportsFileBasedCompression {get;} 
SystemCreationClassName  Property string SystemCreationClassName {get;} 
SystemName     Property string SystemName {get;} 
VolumeDirty     Property bool VolumeDirty {get;} 
VolumeName     Property string VolumeName {get;set;} 
VolumeSerialNumber   Property string VolumeSerialNumber {get;} 
PSStatus      PropertySet PSStatus {Status, Availability, DeviceID, StatusInfo}