홈>
각 유닛의 램 양을 점검하는 작업 코드가 있습니다. 나는 IP 주소를 주었고 램의 양과 다른 모든 것들을 멋지게 포맷했습니다. 미리 작성된 파일을 여기에 추가하여 .txt 또는 .csv에서 IP 목록을 받도록 할 수 있습니까?
목록에서 실행되는 다른 파일에이 코드를 삽입하려고했지만 오류가 계속 발생합니다.
param([string]$fileInput,[string]$fileOutput )
If ( $fileInput -eq "" -OR $fileOutput -eq ""){
$list = Import-Csv $fileInput -Header name, licenseKey, keyStatus
foreach( $computerName in $list){
export-csv -InputObject $computerName -append $fileOutput -Encoding utf8
}
}
내 코드에서이 줄에 대한 올바른 배치를 잘 모르겠습니다.
write-host ""
$strComputer = Read-Host "Enter Computer Name to list memory slot information"
$colSlots = Get-WmiObject -Class "win32_PhysicalMemoryArray" -namespace "root\CIMV2" -computerName $strComputer
$colRAM = Get-WmiObject -Class "win32_PhysicalMemory" -namespace "root\CIMV2" -computerName $strComputer
$NumSlots = 0
write-host ""
$colSlots | ForEach {
“Total Number of Memory Slots: ” + $_.MemoryDevices
$NumSlots = $_.MemoryDevices
}
write-host ""
Read-Host "Press Enter to continue"
$SlotsFilled = 0
$TotMemPopulated = 0
$colRAM | ForEach {
“Memory Installed: ” + $_.DeviceLocator
“Memory Size: ” + ($_.Capacity / 1GB) + ” GB”
$SlotsFilled = $SlotsFilled + 1
$TotMemPopulated = $TotMemPopulated + ($_.Capacity / 1GB)
# if ($_.Capacity = 0)
# {write-host "found free slot"}
}
write-host ""
write-host "=== Summary Memory Slot Info for computer:" $strComputer "==="
write-host ""
If (($NumSlots - $SlotsFilled) -eq 0) {
write-host "ALL Slots Filled, NO EMPTY SLOTS AVAILABLE!"
}
write-host ($NumSlots - $SlotsFilled) " of " $NumSlots " slots Open/Available (Unpopulated)"
write-host ($SlotsFilled) " of " $NumSlots " slots Used/Filled (Populated)."
write-host ""
write-host "Total Memory Populated = " $TotMemPopulated "GB"
#
- 답변 # 1
와이즈 비즈 루프는 관용적 솔루션입니다.
다음과 같이 컴퓨터 이름이나 IP 주소를 포함하는 텍스트 파일을 만드십시오 :
즉, 각 시스템 이름이나 주소는 별도의 항목없이 자체 행에 있습니다. 충분히 간단 하죠? 예를 들어,
computer1 computer2 ... computern
로 저장하십시오. . 이름 목록을 얻은 후 위에서 언급 한c:\temp\computersToCheck.txt
를 지원하도록 코드를 변경하십시오. 루프.# Read all the computers from the file $computers = get-content c:\temp\computersToCheck.txt # Perform an operation for each row in the file foreach ($strComputer in $computers) { $colSlots = Get-WmiObject -Class "win32_PhysicalMemoryArray" -namespace "root\CIMV2" -computerName $strComputer # Rest of the code goes here ... write-host "Total Memory Populated = " $TotMemPopulated "GB" }