나는 Powershell 스크립트를 사용하여 SAN을 모니터링하고 있습니다. 나는 성공적으로이 코드 PowerShell의 시스템에서 모든 값을 포함하는 텍스트 파일을 추출 :Powershell에서 일반 텍스트로 다차원 배열 채우기
& "NaviSecCli.exe" -user xxxx -password xxxx -h host -f "C:\LUNstate.txt" lun -list
$Path = "C:\LUNstate.txt"
$Text = "Capacity \(GBs\)"
$Name = "^Name"
Get-Content $Path | Select-String -pattern $Text,$Name
이 다음과 같은 출력이 생성
Name: TEST-DATASTORE-1
User Capacity (GBs): 1536.000
Consumed Capacity (GBs): 955.112
Name: CV Snapshot Mountpoint
User Capacity (GBs): 1024.000
Consumed Capacity (GBs): 955.112
가 지금은 결장을 통해 값을 분할 할 수 있습니다, 변수에 출력을 넣어 : 유일한 흥미로운 데이터가 $ LUNArray [1]에 저장됩니다
$LUNArray = Get-Content $Path | Select-String -pattern $Text,$Name
$LUNArray | foreach {
$LUNArray = $_ -split ': '
Write-Host $LUNArray[0]
Write-Host $LUNArray[1]
}
, 그래서 난 그냥 쓰기 호스트 $ LUNArray을 남길 수 있습니다 [0] 이것은 다음과 같은 결과를 출력합니다 :
TEST-DATASTORE-1
1536.000
955.112
CV Snapshot Mountpoint
1024.000
955.112
이제 까다로운 부분이 있습니다. 다차원 배열에 데이터를 넣고 싶습니다. 그래서 나는 다음과 같은 배열 레이아웃을 얻을 것입니다 :
LUN Usercap ConsCap
TEST-DATASTORE-1 1536.000 955.112
CV Snapshot Mountpoint 1024.000 955.112
입력 파일은 다음과 같습니다
LOGICAL UNIT NUMBER 201
Name: TEST-DATASTORE-1
UID: 60:06:E4:E3:11:50:E4:E3:11:20:A4:D0:C6:E4:E3:11
Current Owner: SP B
Default Owner: SP B
Allocation Owner: SP B
User Capacity (Blocks): 3221225472
User Capacity (GBs): 1536.000
Consumed Capacity (Blocks): 2005641216
Consumed Capacity (GBs): 956.364
Pool Name: Pool HB Hasselt
Raid Type: Mixed
Offset: 0
Auto-Assign Enabled: DISABLED
Auto-Trespass Enabled: DISABLED
Current State: Ready
Status: OK(0x0)
Is Faulted: false
Is Transitioning: false
Current Operation: None
Current Operation State: N/A
Current Operation Status: N/A
Current Operation Percent Completed: 0
Is Pool LUN: Yes
Is Thin LUN: Yes
Is Private: No
Is Compressed: No
Tiering Policy: Lowest Available
Initial Tier: Lowest Available
Tier Distribution:
Capacity: 100.00%
LOGICAL UNIT NUMBER 63920
Name: CV Snapshot Mountpoint
UID: 60:50:38:00:14:50:38:00:C6:64:50:38:00:50:38:00
Current Owner: SP B
Default Owner: SP B
Allocation Owner: SP B
User Capacity (Blocks): 2147483648
User Capacity (GBs): 1024.000
Consumed Capacity (Blocks): 2005641216
Consumed Capacity (GBs): 956.364
Pool Name: Pool HB Hasselt
Raid Type: Mixed
Offset: 0
Auto-Assign Enabled: DISABLED
Auto-Trespass Enabled: DISABLED
Current State: Ready
Status: OK(0x0)
Is Faulted: false
Is Transitioning: false
Current Operation: None
Current Operation State: N/A
Current Operation Status: N/A
Current Operation Percent Completed: 0
Is Pool LUN: Yes
Is Thin LUN: Yes
Is Private: No
Is Compressed: No
Tiering Policy: Lowest Available
Initial Tier: Lowest Available
Tier Distribution:
Capacity: 100.00%
...
고마워요,하지만 그 트릭을하지 않는 것 같습니다. 추가 처리를 위해 사용할 수 있도록 배열의 개별 항목을 표시하는 방법은 무엇입니까? – KingT
@KingT 업데이트 된 답변보기. 지금 당장 샘플 입력 데이터를 질문에 추가했다면 훨씬 더 빨리 처리 할 수 있습니다. 데이터를 파싱 할 때 놀랄만 한 것처럼 보일 수 있습니다. 실제 데이터 구조는 중요합니다. –