Navigation

PowerShell

Powershell - network monitor via ping

$servers = "seznam.cz","google.cz"
$collection = $()
$OutputFile = "D:\test\output.csv"
do {
	foreach ($server in $servers)
	{
		$status = @{ "ServerName" = $server; "TimeStamp" = (Get-Date -f s) }
		if (Test-Connection $server -Count 1 -ea 0 -Quiet)
		{ 
			$status["Results"] = "Up"

		} 
		else 
		{ 
			$status["Results"] = "Down" 
			$now = Get-Date -uformat "%Y/%m/%d %H:%M:%S"
			$out = $status["ServerName"] + " = " + $status["Results"] + " - " + $now
			$out | Out-File $OutputFile -append
		}
		sleep 1
		
		# $now = Get-Date -uformat "%Y/%m/%d %H:%M:%S"

PowerShell - příklady

Get-Command
Get-Command -verbget
Get-Command -verb get
Get-Command *
Get-Command *-service
history
get-help
get-help get-service
get-help Get-Service -examples
get-service -displayname *network*
ls
Get-Service --help
Get-Service -Name a*
Get-Service -Name *a*
Get-Service -Name *aw*
Get-Service -Name *w*
Get-Service -Name *wa*
Get-ADuser
Get-Service -Name *aw*
Get-Item
get-alias
Get-Alias -Definition Get-ChildItem
Get-Command *alias*
New-Alias np C:\Windows\System32\notepad.exe
np
sort
Get-Command *sort*
ip /a
Get-Process

PowerShell - jak na to, základy

http://en.wikipedia.org/wiki/Windows_PowerShell
http://www.powershellpro.com/powershell-tutorial-introduction/powershell-tutorial-conditional-logic/
http://pechanec.cz/windows-powershell/

Windows 7 - %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -noprofile
ISE - grafický editor/studio na skriptování
PowerGUI.org - Lepší než ISE, SW třetí strany (není vyvíjen MS)

Subscribe to PowerShell