【发布时间】:2017-10-16 11:59:48
【问题描述】:
我需要创建一个可以双击的powershell脚本(64位计算机),它将输出到与powershell脚本相同位置的.txt文件以生成以下信息:
- 计算机名称/型号/序列号。
- C 盘大小/C 盘上的可用磁盘空间
- 计算机运行的是哪个版本的操作系统
- 当前登录计算机的用户
到目前为止(但它不是很有效)我有:
$computerSystem = get-wmiobject Win32_ComputerSystem
$computerOS = get-wmiobject Win32_OperatingSystem
$computerHDD = Get-WmiObject Win32_LogicalDisk -Filter drivetype=3
$txtObject = New-Object PSObject -property @{
'PCName' = $computerSystem.Name
'Model' = $computerSystem.Model
'SerialNumber' = $computerBIOS.SerialNumber
'HDDSize' = "{0:N2}" -f ($computerHDD.Size/1GB)
'HDDFree' = "{0:P2}" -f ($computerHDD.FreeSpace/$computerHDD.Size)
'OS' = $computerOS.caption
'SP' = $computerOS.ServicePackMajorVersion
'User' = $computerSystem.UserName
}
$txtObject | Select PCName, Model, SerialNumber, HDDSize, HDDFree, OS, SP, User | Get-Process | Out-File 'system-info.txt' -NoTypeInformation -Append
【问题讨论】: