我想在一个文本文件中组合下面脚本的输出

时间:2016-10-14 20:00:16

标签: powershell

Write-Host "Drive information for $env:ComputerName"

Get-WmiObject -Class Win32_LogicalDisk |
    Where-Object {$_.DriveType -ne 5} |
    Sort-Object -Property Name | 
    Select-Object Name, VolumeName, VolumeSerialNumber,SerialNumber, FileSystem, Description, VolumeDirty, `
        @{"Label"="DiskSize(GB)";"Expression"={"{0:N}" -f ($_.Size/1GB) -as [float]}}, `
        @{"Label"="FreeSpace(GB)";"Expression"={"{0:N}" -f ($_.FreeSpace/1GB) -as [float]}}, `
        @{"Label"="%Free";"Expression"={"{0:N}" -f ($_.FreeSpace/$_.Size*100) -as [float]}} |
    Format-Table -AutoSize
gcim Win32_OperatingSystem | f1 * | f1 > info.txt; notepad.exe info.txt

1 个答案:

答案 0 :(得分:0)

  $path="$([Environment]::GetFolderPath("Desktop"))\info.txt"; 
  gcim Win32_OperatingSystem | select Caption, InstallDate | fl | out-file  $path; 
  "Drive information for $env:ComputerName" | out-file  $path -Append;  
  Get-WmiObject -Class Win32_LogicalDisk | Where-Object {$_.DriveType -ne 5} | Sort-Object -Property Name | Select-Object Name, VolumeName, VolumeSerialNumber,SerialNumber, FileSystem, Description, VolumeDirty, ` @{"Label"="DiskSize(GB)";"Expression"={"{0:N}" -f ($_.Size/1GB) -as [float]}}, ` @{"Label"="FreeSpace(GB)";"Expression"={"{0:N}" -f ($_.FreeSpace/1GB) -as [float]}}, ` @{"Label"="%Free";"Expression"={"{0:N}" -f ($_.FreeSpace/$_.Size*100) -as [float]}} | Format-Table -AutoSize | out-file $path -Append

  notepad $path;