我需要创建一个PowerShell脚本,您可以双击(64位计算机),它将输出到与powershell脚本相同位置的.txt文件,以生成以下信息:
到目前为止(但它不是很有效)我有:
$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
答案 0 :(得分:1)
$PSScriptRoot
=启动脚本的当前位置,因此如果您在保存路径中指定Out-File "$PSScriptRoot\system-info.txt"
,则会将其保存在与脚本相同的位置
Get-Process
无法在此位置使用
NoTypeInformation
不作为Out-File
$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-Object PCName, Model, SerialNumber, HDDSize, HDDFree, OS, SP, User | Out-File "$PSScriptRoot\system-info.txt" -Append