AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 633781
Accepted
JJJJNR
JJJJNR
Asked: 2014-10-07 00:15:56 +0800 CST2014-10-07 00:15:56 +0800 CST 2014-10-07 00:15:56 +0800 CST

来自 CSV 的页面文件大小

  • 772

我有以下脚本,它检查远程服务器上的页面文件大小,是否可以针对主机名的 CSV 文件运行它?

clear 

$strComputer="computername"

$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
windows-server-2008
  • 1 1 个回答
  • 435 Views

1 个回答

  • Voted
  1. Best Answer
    Mathias R. Jessen
    2014-10-08T02:16:56+08:002014-10-08T02:16:56+08:00

    如果您有一个带有“主机名”列的 Csv 文件,如下所示,您可以使用Import-Csv.

    示例 servers.csv 文件:

    Id,Hostname,"ServerRole"
    123,Server1,"Web Server"
    124,Server2,"Web Server"
    131,Server3,"App Server"
    132,Server4,"App Server"
    

    foreach使用并Import-Csv完成您正在尝试执行的操作的脚本:

    # Clear the screen
    Clear-Host
    
    # Import the Hostname values from the CSV file
    $ComputerNames = Import-Csv -Path "C:\servers.csv" | Select-Object -ExpandProperty "Hostname"
    
    # Empty array to hold the results
    $ResultSet = @()
    
    # query each computer for their Page file and memory details
    foreach($strComputer in $ComputerNames)
    {
        $PageFile=Get-WmiObject Win32_PageFile -ComputerName $strComputer 
        $PFSize = ($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
    
        # Store all the details in a temporary hashtable
        $PageFileDetails = @{ 
            "ComputerName" = $strComputer
            "PagefileInMB" = $PFSize
            "Memory"       = $total
            "PAEEnabled"   = $isPAEEnabled
        }
    
        # Create a new object with the properties we defined in the hashtable and add it to the result
        $ResultSet += New-Object psobject -Property $PageFileDetails
    }
    
    # the host application will print out the details for each computer on the screen
    $ResultSet
    

    该$ResultSet变量现在包含一个PSObject表示查询的每台计算机,每台计算机都有一个“ComputerName”、“PagefileInMB”、“Memory”和“PAEEnabled”属性。

    您现在可以轻松找到禁用 PAE 的计算机:

    $ResultSet | Where-Object {$_.PAEEnabled -eq $False}
    
    • 1

相关问题

  • 文件复制到分支机构

  • 对于 ASP.Net 应用程序,Windows 64 位相对于 32 位的主要优势是什么?

  • Windows Server 2008 Hyper-V 虚拟化服务器的最佳 RAID 配置?

  • 远程连接 sql server 不工作,但如果防火墙禁用它呢?

  • 无法从 SQL Server 2008 备份数据库

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve