我很難完成這個腳本。 Bascially我想檢查內存剩下,檢查前3內存豬,顯示最後一次重啓時,顯示最後一次更新,顯示服務是自動的,但已停止並顯示我在服務器上有多少空間硬盤空間。完成powershell腳本
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