2010-03-08 64 views
4

我是PowerShell新手。使用powershell檢查RAM,頁面文件,/ PAE,/ 3GB,SQL服務器內存

搜索後幾天....

我已經把一個小的PowerShell腳本(如下),以檢查頁面文件,/ PAE開關,/ 3GB開關,SQL服務器最大RAM,RAM最小。 我正在1臺服務器上運行。

如果我想在很多服務器上(從.txt文件)運行它,我該如何改變它? 如何更改它以搜索給定服務器的boot.ini文件內容?

clear 
$strComputer="." 

$PageFile=Get-WmiObject Win32_PageFile -ComputerName $strComputer 
Write-Host "Page File Size in MB: " ($PageFile.Filesize/(1024*1024)) 


$colItems=Get-WmiObject Win32_PhysicalMemory -Namespace root\CIMv2 -ComputerName $strComputer 
$total=0 
foreach ($objItem in $colItems) 
{ 
    $total=$total+ $objItem.Capacity 
} 


$isPAEEnabled =Get-WmiObject Win32_OperatingSystem -ComputerName $strComputer 
Write-Host "Is PAE Enabled: " $isPAEEnabled.PAEEnabled 

Write-Host "Is /3GB Enabled: " | Get-Content C:\boot.ini | Select-String "/3GB" -Quiet 
# how can I change to search boot.ini file's contents on $strComputer 

$smo = new-object('Microsoft.SqlServer.Management.Smo.Server') $strSQLServer 
$memSrv = $smo.information.physicalMemory 
$memMin = $smo.configuration.minServerMemory.runValue 
$memMax = $smo.configuration.maxServerMemory.runValue 


## DBMS 
Write-Host "Server RAM available:  " -noNewLine 
Write-Host "$memSrv MB" -fore "blue" 
Write-Host "SQL memory Min:    " -noNewLine 
Write-Host "$memMin MB " 
Write-Host "SQL memory Max:    " -noNewLine 
Write-Host "$memMax MB" 

任何評論如何可以改善?

在此先感謝

+0

但請記住,這BOOT.INI是不是現在不再使用了一段時間。對於任何最近的操作系統,這隻會產生任何東西 – Joey 2010-03-08 11:03:52

+0

如果在某些操作系統中未使用boot.ini,那麼我們將包含/ PAE和/ 3GB開關? – Manjot 2010-03-08 19:44:27

回答

1

如果你想只是爲了檢查boot.ini文件,如果你添加你可以使用Get-Content(如果你不會有憑據問題)

# create a test file with server names 
@" 
server1 
server2 
"@ | set-content c:\temp\serversso.txt 

# read the file and get the content 
get-content c:\temp\serversso.txt | 
    % { get-content "\\$_\c`$\boot.ini" } | 
    Select-String "/3GB" -Quiet 

後來一些東西,將需要在遠程計算機上運行,​​那麼你將需要使用遠程處理,基本上Invoke-Command。最近兩個資源似乎觸摸遠程:

+0

非常感謝這些資源。 – Manjot 2010-03-09 00:06:20