我正在为由多台计算机和服务器组成的网络制作系统库存程序 . 因此,我发现服务器更智能,更容易放置代码,以检查本地计算机上是否有任何新信息:

Powershell将作为登录脚本运行并获取所需的所有信息,然后将其与旧信息进行比较 .

就在那时我开始问你聪明人的问题 . 截至目前,我正在比较新旧信息:

  • Powershell收集所有数据并将其写入.txt文件

  • Powershell将新制作的"cacheInfo.txt"与"SystemInfo.txt"进行比较

这是一个不必要的联合......我希望..

有没有办法在powershell中比较这样的信息而不制作附加文件?

这是powershell的信息收集命令:

$compname = gc env:computername

#-----------------------------------------------------------------------------#
#HARDWARE
#-----------------------------------------------------------------------------#

#PC Serial Number
Write-Host "#PC Serial number"
gwmi -computer $compname Win32_BIOS | ForEach {$_.SerialNumber}

#System Info
Write-Host "#System Info"
#gwmi -computer $compname Win32_ComputerSystem | Format-List Name,Domain,Manufacturer,Model,SystemType
gwmi -computer $compname Win32_ComputerSystem | ForEach {$_.Name,$_.Domain,$_.Manufacturer,$_.Model,$_.SystemType}

#USB Devices
Write-Host "#USB Devices"
Get-WmiObject -Class Win32_DiskDrive | ForEach {$_.Model}
write-host ""

#Disk Info
Write-Host "#Disk Info"
$disk = gwmi -computer $compname Win32_logicaldisk
foreach($device in $disk){
    if(!$device.Size -eq 0){
        Write-Host $device.Name $device.VolumeName
        Write-Host -NoNewLine; "{0:N2}" -f ($device.Size/1Gb) + " Gb"
        Write-Host -NoNewLine; "{0:N2}" -f ($device.FreeSpace/1Gb) + " Gb"
        ""
    }
 }

#Memory Info
Write-Host "#Memory Info"
$memory = gwmi -computer $compname Win32_PhysicalMemory
foreach($device in $memory){
    Write-Host "Memory Unit:    " $device.PositionInRow
    Write-Host "Capacity:       " ($device.Capacity/1MB) "Mb"
    Write-Host "Data Width:     " $device.DataWidth
    Write-Host "Device Locator: " $device.DeviceLocator
    ""
}
#Graphic card
Write-Host "#Graphic card"
gwmi "win32_VideoController" | ForEach-Object {$_.Name} | write-host

#Processor Info
Write-Host "#Processor Info"
gwmi -computer $compname Win32_Processor | Format-List Caption,Name,Manufacturer,ProcessorId,NumberOfCores,AddressWidth
#-----------------------------------------------------------------------------#
#SOFTWARE
#-----------------------------------------------------------------------------#

#PC Printer Information
Write-Host "#Printer Info"
gwmi -computer $compname Win32_Printer | Select-Object DeviceID,DriverName, PortName | Format-List

#Current User
Write-Host "#Current User"
gwmi -computer $compname Win32_ComputerSystem | Format-Table @{Expression={$_.Username};Label="Current User"}

#All Users
Write-Host "#All users on computer $compname"
gwmi -computer $compname Win32_UserAccount | foreach{$_.Name}

#OS Info
Write-Host "#OS Info"
gwmi -computer $compname Win32_OperatingSystem | Format-List @{Expression={$_.Caption};Label="OS Name"},SerialNumber,OSArchitecture, installDate