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 

$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

$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 
$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$

http://ss64.com/nt/sc.html

http://www.petri.co.il/check-uptime-in-server-2008.htm

你可能感兴趣的:(misc of command)