Restart-Computer Tento commandlet reboots provede restart computeru, bez toho aby doslo pri restartu k fastbootu.
pondělí 15. února 2016
čtvrtek 4. února 2016
Rychlý scan Defenderem příkazem powershellu
PS> Start-MpScan -ScanType QuickScan -ScanPath “C:” Funkčnost vyžaduje modul Defender !
Android a powershell
Zajimavou moznosti pro androidisty je aplikace Pulseway..Posilejte prikazy powershellu, spouštějte scripty ze sveho Androida..
úterý 24. ledna 2012
Bad device
sobota 31. prosince 2011
Zabij neodpovidajici proces
$notresponding.Kill()
neděle 16. října 2011
Primarní networkadapter
nebo
get-wmiobject win32_networkadapter -filter "netenabled=’true’"
get-wmiobject win32_networkadapterconfiguration -filter "IPEnabled=’True’"
pátek 16. září 2011
Seznam fontů
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
$objFonts = New-Object System.Drawing.Text.InstalledFontCollection
$colFonts = $objFonts.Families
$objIE = New-Object -com "InternetExplorer.Application"
$objIE.Navigate("about:blank")
$objIE.ToolBar = 0
$objIE.StatusBar = 0
$objIE.Visible = $True
$objDoc = $objIE.Document.DocumentElement.LastChild
foreach ($objFont in $colFonts)
{
$strHTML = $strHTML + "<font size='5' face='" + $objFont.Name + "'>" + $objFont.Name + "</font><br>"
}
$objDoc.InnerHTML = $strHTML
neděle 11. září 2011
admin status
pátek 9. září 2011
HOSTS
Function Get-HostsFile {
.SYNOPSIS
Retrieves the contents of a hosts file on a specified system.
.DESCRIPTION
Retrieves the contents of a hosts file on a specified system.
.PARAMETER ComputerName
The computers to access.
.NOTES
Name: Get-HostsFile
Author: Boe Prox
DateCreated: 15Mar2011
1.1 - 2011-03-17 - Jason Archer
Improved pipeline support (and fixed positional usage).
Added custom object creation and incremental output (better performance and cleaner code).
For local host, use local path.
Added error messages for error conditions.
1.0 - 2011-03-15 - Boe Prox
Initial release.
.LINK
http://boeprox.wordpress.com
.EXAMPLE
Get-HostsFile "server1"
Description
-----------
Retrieves the contents of the hosts file on 'server1'.
#>
[CmdletBinding()]
Param(
[Parameter(Position = 0, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)]
[ValidateNotNull()]
[string[]]$ComputerName = "localhost"
)
Begin {
$PSBoundParameters.GetEnumerator() | Foreach-Object {
Write-Verbose "Parameter: $_"
}
}
Process {
Write-Verbose "Starting process of computers"
ForEach ($c in $ComputerName ) {
Write-Verbose "Testing connection of $c"
If (Test-Connection -ComputerName $c -Quiet -Count 1) {
Write-Verbose "Validating path to hosts file"
if ($c -eq "localhost") {
$root = "C:"
} else {
$root = "\\$c\C`$"
}
If (Test-Path "$root\Windows\system32\drivers\etc\hosts") {
Switch -regex -file ("$root\Windows\system32\drivers\etc\hosts") {
"^#\w+" {
}
"^\d\w+" {
Write-Verbose "Adding IPV4 information to collection"
$new = $_.Split("") | Where-Object {$_ -ne ""}
If ($new[2] -eq $null) {
$notes = $null
} Else {
$notes = $new[2]
}
New-Object PSObject -Property @{
ComputerName = $c
IPV4 = $new[0]
IPV6 = $null
Hostname = $new[1]
Notes = $notes
}
}
Default {
If (!("\s+" -match $_ -OR $_.StartsWith("#"))) {
Write-Verbose "Adding IPV6 information to collection"
$new = $_.Split("") | ? {$_ -ne ""}
If ($new[2] -eq $null) {
$notes = $null
} Else {
$notes = $new[2]
}
New-Object PSObject -Property @{
ComputerName = $c
IPV4 = $null
IPV6 = $new[0]
Hostname = $new[1]
Notes = $notes
}
}
}
}
} ElseIf (Test-Path "$root\WinNT\system32\drivers\etc\hosts") {
Switch -regex -file ("$root\WinNT\system32\drivers\etc\hosts") {
"^#\w+" {
}
"^\d\w+" {
Write-Verbose "Adding IPV4 information to collection"
$new = $_.Split("") | ? {$_ -ne ""}
If ($new[2] -eq $null) {
$notes = $null
} Else {
$notes = $new[2]
}
New-Object PSObject -Property @{
ComputerName = $c
IPV4 = $new[0]
IPV6 = $null
Hostname = $new[1]
Notes = $notes
}
}
Default {
If (!("\s+" -match $_ -OR $_.StartsWith("#"))) {
Write-Verbose "Adding IPV6 information to collection"
$new = $_.Split("") | ? {$_ -ne ""}
If ($new[2] -eq $null) {
$notes = $null
} Else {
$notes = $new[2]
}
New-Object PSObject -Property @{
ComputerName = $c
IPV4 = $null
IPV6 = $new[0]
Hostname = $new[1]
Notes = $notes
}
}
}
}
} Else {
## TODO: Could use the properly localized path not found error
Write-Error "Unable to locate host file on computer: $c"
}
} Else {
## TODO: Could use the properly localized can not locate host error
Write-Error "Unable to locate computer: $c"
}
}
}
}
pátek 22. července 2011
Portable powershell
pátek 10. června 2011
Seskupovaní podle kriterií
Opět tip z powertips
Někde v hloubi blogu je myslim už group a totožne co je na powertips jenom misto
Get-Process | Group-Object -property Company je tam seskupovaní služeb.
Ukazka z powertips ukazuje vlastni seskupení podle tří kataegorii – rozdilná velikost,jak si je kdo nazve ve scriptu nebo kolik si takových kriteríí uděla a jaká velikost bude patřit k čemu je věc jenom toho co hledám a seskupuji.
PS> $criteria = {
if ($_.Length -lt 1KB) {
'tiny'
} elseif ($_.length -lt 1MB) {
'average'
} else {
'huge' }
}
PS> dir $env:windir | Group-Object -Property $criteria
Výsledek
Tvorba hash table se samozřejmě neomezuje na velikost nebo seskupovaní procesů,nakombinovat jde spousta věcí.
Vypnutí sitových adaptérú –různé způsoby
Další tip který vyšel na powertips
Ruzne zpusoby vypnuti network adapteru
GET-WMIOBJECT WIN32_NETWORKADAPTER | foreach { $_.Disable() }
Vypne všechny sitove adaptersy - Physical, Logical, všechny a GET-WMIOBJECT WIN32_NETWORKADAPTER | foreach { $_.Enable() }
všechny povolí
Filtr na fyzicke neboli where { $_.PhysicalAdapter –eq $TRUE} a přikaz níže zakáže pouze fyzicke adaptery
GET-WMIOBJECT WIN32_NETWORKADAPTER | where { $_.PhysicalAdapter –eq $TRUE} | foreach { $_.Disable() }
Co se týče filtrace tak fantazii se meze nekladou…
Inventura jinak
sobota 2. dubna 2011
Powershell a HTML 5
V jednom postu byl zminěn koncept integrace powershellu a HTML5,našel jsem tam mimo jine toto
iex (New-Object Net.WebClient).DownloadString("http://bit.ly/e0Mw9w")
vložte do powershellu a budete překvapeni stejně jako já.
pondělí 14. března 2011
pondělí 7. března 2011
Powershell a Nmap
Dnes jsem při upravování výstupu pro netstat v powershellu narazil v jine souvislosti na zajimavý ps1 script pro nmap.
http://blogs.sans.org/windows-security/2009/06/11/powershell-script-to-parse-nmap-xml-output/
Jeden z možných vystupů ktere exportuje potom vypadá takto
neděle 6. března 2011
pátek 25. února 2011
Prompt - změna
function prompt {
$mapped_drives = Get-WmiObject Win32_LogicalDisk -Filter "drivetype=4" | foreach {echo $_.deviceid}
$local_drives = Get-WmiObject Win32_LogicalDisk -Filter "drivetype=3" | foreach {echo $_.deviceid}
$removable_drives = Get-WmiObject Win32_LogicalDisk -Filter "drivetype=2" | foreach {echo $_.deviceid}
$t = $(get-date -format "HH:mm:ss")
$a = (get-location).path
$d = (get-location).path.substring(0,$a.indexof(":")+1)
$a = $a.substring($a.LastIndexOf("`\")+1)
if ((get-location).path.substring(0,(get-location).path.indexof(":")) -eq "Microsoft.PowerShell.Core\FileSystem") {
$a = (get-location).path
$a = $a.substring($a.indexof(":")+2)
write-host -fore white -back blue "$t - $a ";"`$`> "}
else {
if ($a -eq "") {$a = "`\"}
if ($d.length -gt 2) {
write-host -ForegroundColor black -backgroundcolor red "[$t] - [$d] $a ";"`$`> "}
elseif ($local_drives -contains "$d") {
write-host -ForegroundColor black -backgroundcolor green "[$t] - [$d] $a ";"`$`> "}
elseif ($removable_drives -contains "$d") {
write-host -ForegroundColor black -backgroundcolor yellow "[$t] - [$d] $a ";"`$`> "}
elseif ($mapped_drives -contains "$d") {
write-host -ForegroundColor black -backgroundcolor magenta "[$t] - [$d] $a ";"`$`> "}
}
}
Tak tato změna promptu se mně libí,dle popisu přidejete do profilu PS.
pátek 4. února 2011
čtvrtek 3. února 2011
Smazani eventlogu
Zaloha vystupů z eventlogu,přidejte si připadně export kam je libo,jiným způsobem
Smazaní eventlogu – daný přiklad likviduje prostě vše,obrazek je pastnutý ale ze stroje který je prakticky co se týče zaznamů teměř netčený nějakýma vstupama jediný zaznam tam byl jak vidíte pravě o předchozím mazaní – ID 1102.
Clear je tady celeho listu,můžete si nastavit pochopitelně jenom výběrové.
get-eventlog security | export-clixml -path Seclog.xml
Import-clixml Seclog.xml
get-eventlog -list |%{$_.clear()}
Ying Li
MyITforum.com