misc of command

Windows get uptime

  1. net stats srv|findstr
  2. systeminfo | find "System Boot Time:"
  3. eventvwr.msc -> filter EventID(6005)

Control a service

  1. net start tlntsvr

  2. sc \\hostname start tlntsvr

  3. Enable telnet service

    1
    2
    3
    4
    5
    6
    7
    $tlntsvr = gwmi -ComputerName webserver -Class Win32_Service -filter "name='tlntsvr'" -Credential $cred

    $tlntsvr.ChangeStartMode("Manual") (default it is Disabled)

    $tlntsvr.StartService()

    $ihs = gwmi -ComputerName webserver -Class Win32_Service -filter "name like 'IBM%1.3%'" -Credential $cred
  4. Enable remote desktop

    1
    2
    3
    4
    5
    6
    7
    $terminalService = gwmi -Class Win32_TerminalServiceSetting -Namespace root\cimv2\terminalservices -ComputerName webserver -Credential $cred //Windows Vista and Windows Server 2008

    $terminalService = gwmi -Class Win32_TerminalServiceSetting -Namespace root\cimv2 -ComputerName webserver -Credential $cred //Windows XP and Windows Server 2003

    $terminalService.AllowTsConnections // test the state

    $terminalService.SetAllowTSConnections(1)
  5. View eventlog by powershell

    1
    2
    3
    4
    5
    6
    7
    8
    9
    $username = "admin"
    $password = "password"
    $secstr = New-Object -TypeName System.Security.SecureString
    $password.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)}
    $cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $secstr

    $time = [System.Management.ManagementDateTImeConverter]::ToDmtfDateTime((Get-Date).AddHours(-72))

    gwmi Win32_NTLogEvent -filter "(LogFile='System') AND (Type='Error') AND (TimeWritten >= '$time')" -computer webserver -credential $cred | ft EventCode, EventType, Message -auto
  6. Open remote server path net use \\webserver\ipc$ password /user:username \\werbserver\c$

Reference

http://ss64.com/nt/sc.html
http://www.petri.co.il/check-uptime-in-server-2008.htm"