使用powershell检查RAM,页面文件,/ PAE,/ 3GB,SQL服务器内存

时间:2010-03-08 03:46:42

标签: sql-server powershell powershell-v2.0

我是PowerShell新手。

经过几天的搜索......

我已经整理了一个小的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" 

有关如何改进的评论吗?

提前致谢

1 个答案:

答案 0 :(得分: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。最近出现了两个涉及远程处理的资源: