以下是一个示例脚本,可以获取100台Windows服务器的IP地址、CPU、内存容量和硬盘容量,并将结果保存到CSV文件中:

# 定义服务器列表
$serverList = @(
    "server1.example.com",
    "server2.example.com",
    "server3.example.com",
    # ...
    "server100.example.com"
)

# 创建空数组以保存结果
$results = @()

# 循环遍历服务器列表
foreach ($server in $serverList) {
    # 获取系统信息
    $systemInfo = Get-WmiObject Win32_ComputerSystem -ComputerName $server
    $cpuInfo = Get-WmiObject Win32_Processor -ComputerName $server
    $memoryInfo = Get-WmiObject Win32_PhysicalMemory -ComputerName $server
    $diskInfo = Get-WmiObject Win32_LogicalDisk -Filter "DeviceID='C:'" -ComputerName $server

    # 构建结果对象
    $result = New-Object PSObject
    $result | Add-Member NoteProperty Server $server
    $result | Add-Member NoteProperty CPU $cpuInfo.Name
    $result | Add-Member NoteProperty MemoryCapacity ($memoryInfo.Capacity | Measure-Object -Sum).Sum
    $result | Add-Member NoteProperty DiskCapacity ($diskInfo.Size / 1GB)

    # 将结果添加到数组中
    $results += $result
}

# 将结果保存到CSV文件
$results | Export-Csv -Path "server_info.csv" -NoTypeInformation

以上脚本中,首先定义了一个包含100台服务器名称的列表。然后使用foreach循环遍历该列表,并使用Get-WmiObject命令获取每台服务器的系统信息。然后,将所有信息组合成一个结果对象,并将其添加到结果数组中。最后,使用Export-Csv命令将结果数组保存到CSV文件中。

Powershell 获取100台window 服务器ip地址、cpu内存容量、硬盘容量最后保存到csv文件

原文地址: https://www.cveoy.top/t/topic/bmIX 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录