完成powershell脚本

完成powershell脚本,powershell,Powershell,我很难完成这个脚本。基本上,我想检查剩余内存,检查前3个内存占用,显示上次重新启动的时间,显示上次更新,显示自动但已停止的服务,并显示服务器上有多少硬盘空间 Write-Host "Getting the information required" -ForeGroundColor green Function Get-Checks { $Output = "C:\users\b2badmin\desktop\checklist\check$((Get-Date).ToString('MM-

我很难完成这个脚本。基本上,我想检查剩余内存,检查前3个内存占用,显示上次重新启动的时间,显示上次更新,显示自动但已停止的服务,并显示服务器上有多少硬盘空间

Write-Host "Getting the information required" -ForeGroundColor green
Function Get-Checks {
  $Output = "C:\users\b2badmin\desktop\checklist\check$((Get-Date).ToString('MM-dd-yyyy_hh-mm-ss')).txt"
  #Get the computer name
  $env:computername | out-file -Append $Output
  #Show Available memory
  Get-Counter -ComputerName localhost '\Memory\Available MBytes' |
    Select-Object -ExpandProperty countersamples |
    Select-Object -Property Path, cookedvalue |
    Out-File -Append $Output
  #Show the processes that are using the most resources top 3
  Get-Process | Sort-Object -Descending WS |
    select -First 3 |
    Format-Table -Property WS,ProcessName |
    Out-File -Append $Output
  #Show last reboot
  Get-WmiObject win32_operatingsystem |
    select csname, @{LABEL=’LastBootUpTime’;EXPRESSION={$_.ConverttoDateTime($_.lastbootuptime)}} |
    Out-File -Append $Output
  #Show the last installed Hotfix for windows updates
  Get-HotFix | Select -Last 1 |
    Format-List -Property InstalledOn,Description,HotfixI |
    Out-File -Append $Output
  #Get the services that are Automatically started and list them if they are stopped
  Get-WmiObject Win32_Service |
    Where-Object { $_.StartMode -eq 'Auto' -and $_.State -ne 'Running' } |
    Format-Table -AutoSize @('Name' 'DisplayName' @{Expression='State';Width=9} @{Expression='StartMode';Width=9} 'StartName') |
    Out-File -Append $Output
  # Show how much room is left on the HDD
  Get-WmiObject Win32_LogicalDisk -ComputerName Localhost |
    Format-Table DeviceID, MediaType,
      @{Name="Size(GB)";Expression={[decimal]("{0:N0}" -f ($_.size/1gb))}},
      @{Name="Free Space(GB)";Expression={[decimal]("{0:N0}" -f ($_.freespace/1gb))}},
      @{Name="Free (%)";Expression={"{0,6:P0}" -f (($_.freespace/1gb) / ($_.size/1gb))}} -AutoSize |
    Out-File -Append $Output

我一直收到一个
>
提示。我需要什么来完成脚本,使其运行?

是的,正如David正确地说的那样,您的代码结尾缺少一个右括号}。我试着调试它,但发现了这个问题

另外,请尝试使用以下命令添加SETPSDEBUG mode on

设置PSDebug-跟踪1


这将帮助您更好地诊断脚本。:)

您只是缺少关闭函数末尾的
}
。您还必须调用函数才能运行。非常感谢您提供的提示。关于调试的一个简单问题是“Debug:1+”这是它所引用的行吗?是的,没错,它声明,Debug:1+>>>Set PSDebug-Trace 1,这意味着调试模式处于启用状态。当此选项处于启用状态时,您可能会注意到它将在执行脚本的每个部分后给出描述。如果您想禁用它,只需将-Trace 1替换为-Trace 0,希望有帮助。:)