2016-04-14 8 views
0

このスクリプトを終了しようとするのが難しかったです。 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 

私は>>プロンプトを表示し続けます。スクリプトを実行して実行するには何が必要ですか?

+3

関数の最後に単に '}'がありません。関数を終了するだけです。 これを実行するには、関数を呼び出す必要があります。 – David

答えて

0

うん、Davidが正しく言ったように、コードの最後に閉じ括弧がありません}。私はそれをデバッグしようとしました。

P.S.次のコマンドでSet-PSDebugモードをオンにしてみてください。

セットPSDebug -Trace 1

これは、あなたがより良いあなたのスクリプトを診断するのに役立ちます。 :)

+0

チップのおかげですごく感謝しています。デバッグについての簡単な質問は、「デバッグ:1+」はそれが参照しているラインですか? – komb

+0

うん、それはそうだ、そうだ、DEBUG:1+ >>>> Set-PSDebug -Trace 1これは、デバッグモードがオンであることを意味する。これがオンになっている間は、スクリプトのすべての部分が実行された後で説明を表示することに気付くかもしれません。ケースを無効にしたい場合は、-Trace 1を-Trace 0に置き換えてください。役立つと思います。 :) – Ashish

関連する問題