úterý 28. prosince 2010

Powershell a Chromium

Dnešni script ukaže jak si stahnout vždy poslední verzi chromia – vývojová větev dev kanal.Zaroven uvidíme v akci modul bitstransfer.Na videu je volba chromium a miniinstaler.

 

Set-StrictMode -Version Latest
Import-Module bitstransfer

# comment out when not debugging
$VerbosePreference = "Continue"
#$VerbosePreference = "SilentlyContinue"

$versionFile = "$Env:temp\latestChromiumVersion.txt"
$installedChromiumVersion = 0

trap [Exception] {
      write-host
      write-error $("TRAPPED: " + $_.Exception.GetType().FullName);
      write-error $("TRAPPED: " + $_.Exception.Message);
      [string]($installedChromiumVersion) > $versionFile
      exit;
}


if (Test-Path $versionFile)
{ $installedChromiumVersion = [int32] (cat $versionFile) }

$latestChromiumBuildURL ="http://build.chromium.org/f/chromium/snapshots/chromium-rel-xp"
Start-BitsTransfer "$latestChromiumBuildURL/LATEST" $versionFile
$latestChromiumVersion = [int32] (cat $versionFile)

if ($installedChromiumVersion -eq $latestChromiumVersion)
{
    Write-Verbose "Exiting... Version $installedChromiumVersion is the latest."
    return
}

$installerAppName = "mini_installer"
$installer = "$Env:temp\$installerAppName.exe"
Write-Verbose "Initiating download of new version $latestChromiumVersion"
Start-BitsTransfer "$latestChromiumBuildURL/$latestChromiumVersion/mini_installer.exe" $installer
Write-Verbose "Installing new version of Chromium"
Invoke-Item $installer
$installerRunning = 1
while (!($installerRunning -eq $null))
{
    sleep 5
    $installerRunning = ( Get-Process | ? {$_.ProcessName -match "$installerAppName"} )
}

Write-Verbose "New Chromium Installed! Please restart the Chromium browser"

Powershell a chromium

neděle 26. prosince 2010

Powershell patchimage windowsupdate

Video je kratka ukazka toho jak updatovat  vhd image automaticky powershell scriptem.Platí a to hlavně to platí i pro wim….Jinak další zajímavý script powershellu řeší i známý problem diskpart a jeho nekorektní chování a vhd ale o něm někdy přiště

Osobně VHD mam ve virtualu,jako multiboot a v několika verzich jak plynul čas a k nejrůznějšímu použití.

Funkce má nespočet využití – některe si prostě přečtete  ve scriptu,jiné na strankach autora scriptu,no a další a další můžete přidávat podle toho k čemu vhd nebo wim použivate – nepouživate.

Stránky autora scriptu s podrobným popisem

http://www.optimalizovane-it.cz/windows-7/imagepatcher-aktualizujte-wim-a-vhd-z-windows-update.html

Video


patchimage


čtvrtek 23. prosince 2010

PowerShell vánoční pozdrav Get-Tree

 

#.Synopsis
#  Creates a fir tree in your console!
#.Description
#  A simple christmas tree simulation with (optional) flashing lights.
#  Requires your font be set to a True Type font (best results with Consolas).
#.Parameter Trim
#  Whether or not to trim the tree. NOTE: In violation of convention, this switch to true!
#  To disable the tree lights, use Get-Tree -Trim:$false
#.Example
#  Get-Tree -Trim:$false
#.Example
#  Get-tree Red, Cyan, Blue, Gray, Green
#
#  Description
#  -----------
#  Creates a tree with multi-colored lights in the five colors that work best...
param(
   [switch]$Trim=$true
,
   [ValidateSet("Red","Blue","Cyan","Yellow","Green","Gray","Magenta","All")]
   [Parameter(Position=0)]
   [String[]]$LightColor = @("Red")
)
if($LightColor -contains "All") {
   $LightColor = "Red","Yellow","Green","Gray","Magenta","Cyan","Blue"
}

Clear-Host
$OFS = "`n"
$center = [Math]::Min( $Host.UI.RawUI.WindowSize.Width, $Host.UI.RawUI.WindowSize.Height ) - 10

$Sparkle = [string][char]0x0489 
$DkShade = [string][char]0x2593
$Needles  = [string][char]0x0416

$Width = 2
[string[]]$Tree = $(
   "$(" " * $Center) "
   "$(" " * $Center)$([char]0x039B)"
   "$(" " * ($Center - 1))$($Needles * 3)"
 
   for($i = 3; $i -lt $center; $i++) {
      (" " * ($Center - $i)) + (Get-Random $Needles, " ") + ($Needles * (($Width * 2) + 1)) + (Get-Random $Needles, " ")
      $Width++
   }
   for($i = 0; $i -lt 4; $i++) {
      " " * ($Center + 2)
   }
)

$TreeOn = $Host.UI.RawUI.NewBufferCellArray( $Tree, "DarkGreen", "DarkMagenta" )
$TreeOff = $Host.UI.RawUI.NewBufferCellArray( $Tree, "DarkGreen", "DarkMagenta" )

# Make the tree trunk black
for($x=-2;$x -le 2;$x++) {
   for($y=0;$y -lt 4;$y++) {
      $TreeOn[($center+$y),($center+$x)] = $TreeOff[($center+$y),($center+$x)] =
         New-Object System.Management.Automation.Host.BufferCell $DkShade, "Black", "darkMagenta", "Complete"
   } 
}

if($trim) {
$ChanceOfLight = 50
$LightIndex = 0
for($y=0;$y -le $TreeOn.GetUpperBound(0);$y++) {
   for($x=0;$x -le $TreeOn.GetUpperBound(1);$x++) {
      # only put lights on the tree ...
      if($TreeOn[$y,$x].Character -eq $Needles) {
         $LightIndex += 1
         if($LightIndex -ge $LightColor.Count) {
            $LightIndex = 0
         }
         # distribute the lights randomly, but not next to each other
         if($ChanceOfLight -gt (Get-Random -Max 100)) {
            # Red for on and DarkRed for off.
            $Light = $LightColor[$LightIndex]
            $TreeOn[$y,$x] = New-Object System.Management.Automation.Host.BufferCell $Sparkle, $Light, "darkMagenta", "Complete"
            $TreeOff[$y,$x] = New-Object System.Management.Automation.Host.BufferCell $Sparkle, "Dark$Light", "darkMagenta", "Complete"
            $ChanceOfLight = 0 # Make sure the next spot won't have a light
         } else {
            # Increase the chance of a light every time we don't have one
            $ChanceOfLight += 3
         }
      }
   }
}
# Set the star on top
$TreeOn[0,$Center] = $TreeOff[0,$Center] = New-Object System.Management.Automation.Host.BufferCell $Sparkle, "Yellow", "darkMagenta", "Complete"
}


# Figure out where to put the tree
$Coord = New-Object System.Management.Automation.Host.Coordinates (($Host.UI.RawUI.WindowSize.Width - ($Center*2))/2), 2
$Host.UI.RawUI.SetBufferContents( $Coord, $TreeOff )

while($trim) { # flash the lights on and off once per second, if we trimmed the tree
   sleep -milli 500
   $Host.UI.RawUI.SetBufferContents( $Coord, $TreeOn )
   sleep -milli 500
   $Host.UI.RawUI.SetBufferContents( $Coord, $TreeOff )
}

pátek 17. prosince 2010

neděle 12. prosince 2010

Powershell a audit PC

Powershell lze pochopitelně použit na audit PC.Jednou z možností je prostě ladem skladem naskladat přikazy do textoveho souboru a ten potom copy – paste hodit do powershellu on si to už přebere.Výhodou je že se není nutne patlat s vlastní tvorbou – prostě si na miru do textaku nahodíme věci co nas zajimají.Vložime do powershellu a enter.Potom bud vypisem rolujeme nebo jak na konci videa uvidite si opět zpětně jednotlive přikazy volám a zobrazi když chci.Stačí prostě mačkat směrove klavesy a jednotlive přikazy co proběhly se nam opět zobrazují a mame možnost si je jednotlivě vyvolavat.Způsob jak je na každem,smerove šipky,popřipadě jak vidite na screenu F7 nebo prostě jiny způsob prace s historií.

f7k

Video

Powershell audit

sobota 11. prosince 2010

Powershell hromadný tisk

Pomocí powershellu můžeme pochopitelně i tisknout.Nejidealnější je přidat si funkci do profilu a nasledně ji volat – print-file.

Dnes tady jsou dvě videa.To první nam ukazuje tisk kdy prostě uvedeme cestu k souboru a vytiskne se pomocí tiskarny kterou jsme si nastavili jako defaultní.Zde jsem volil virtualní pdf printer,při vystupu na jinou tiskarnu nam samozřejmě vyběhne dialog v němž můžeme upravovat kvalitu tisku,velikost atd.

Zajímavější je druha varianta kdy přikazem určíme umistnění z nějž chceme tisknout, s požadavkem ho prohledat recursivně.Nasledně definujeme připonu ktera nas zajímá.V tomto připadě pdf.Spustíme přikaz a všechny soubory s koncovkou pdf v danem umistnění vytiskneme,využivam to spiš k převodu textaků z určitých umistnění na pdf,pošlu požadavek na složku a podsložky - všechny textove poznamky – většinou moje poznamky atd a tisk pdf tiskarnou.

Funkce do profilu

function print-file($file) 
{
begin {
function internal-printfile($thefile)
{
if ($thefile -is [string]) {$filename = $thefile }
else {
if ($thefile.FullName -is [string] ) { $filename = $THEfile.FullName }
}
$start = new-object System.Diagnostics.ProcessStartInfo $filename
$start.Verb = "print"
[System.Diagnostics.Process]::Start($start)
}

if ($file -ne $null) {
$filespecified = $true;
internal-printfile $file
}
}
process{if (!$filespecified) { write-Host process ; internal-printfile $_ } }
Ukazka video
Solo tisk

powershell solo tisk
 
Powershell hromadný tisk
 

neděle 5. prosince 2010

Powergui Powershell

Video ukazuje grafickou nadstavbu powershellu zminované powergui.V rozumne době jde ukazet tak možná jednu funkci kterou může plnit dejme tomu jako taskmanager a spravce služeb a to i na vzdalených strojích ale nejde do pár minut videa nacpat ani zdaleka základy typu Powerpack managment,powergui script editor a prace s ním.Na domovských strankach projektu ovšem naleznete od tutoriálů a odkazů vše potřebné.

http://powergui.org/index.jspa

Video

powergui

čtvrtek 25. listopadu 2010

Powershell poslech radia

Scriptik kterym si přidame funkci pro poslech oblíbené radiostanice.Po přidani a zaregistrování funkce ji spouštíme tak jak jsme si pojmenovali.v tomto připadě get-radio,nic nam nebraní si nadefinovat stanic víc a udělat get-evropa2,get-rockmax a spouštělo by se vždycky to co zvolime.

Script

function Get-radio
{
$ie = new-object -com "InternetExplorer.Application"
$ie.Navigate2(" http://www.evropa2.cz/player_2009/e2fm/");
$ie.width = 400
$ie.height = 270
$ie.Top=500
$ie.Left=0
$ie.Resizable =$false
$ie.ToolBar =$false
$ie.MenuBar =$false
$ie.Visible = $true;
}

sobota 20. listopadu 2010

Powershell Powergui WMI Demo

Dnešní ukazka bude script Powershell demo pro Powergui od Jamese Brundage,jde vlastně o komentované spouštění scriptů v Powershellu,přičemž v Powergui běží komentař – co to dělá a proč to dělá.Takže využití pro tutorialy,interaktivní napovědu atd.Scripty přidavame přikazem save demo – cesta k scriptu,vubec ovšem nemusí běžet script může to být pouze prostě textak s komentařem.V modulu je přiloženo demo v němž vidíte kod aby jste věděli jak a kdy vkladat tlačitko next a stop  pro tvorbu vlastnich dem.Takže blok kodu ,spuštění v powershellu– komenentař ,next.A pořád dokola.

Toto demo je o zakladní praci Powershellu s WMI.Jinak k Powergui – tedy grafickemu interface a script editoru pro Powershell se ještě vrátím a přiští ukázka by mohla být o ůžasných věcech které umožnuje – je celkem legrační že  existují placené alternativy kterým tím že umí desetinu co powergui silně fandím ještě.

Powershell Powergui

pátek 12. listopadu 2010

Powershell get-procinfo a add-node

Dva scripty ktere nam spusti v prvním připadě spravce procesů ktereho jsme nadefinovali co v něm chceme mít,v druhem připadě napovědu pro powershell která bude stylem možná pro někoho graficky stravitelnější.Pokud si script dáte do profilu spustí se při každem startu powershellu.Obě varianty mají propracovanější obdobu v powergui.Scripty – jejich autory najdete na technetu v scriptcentru.

Spuštění jak komu vyhovuje,vložení,cesta k scriptu,profil,get-procinfo ,get-HelpTree,podle preferencí,osobně volim zaregistrovaní pro get-HelpTree a spouštění přes upnutí u procinfo.

Video



function Add-Node {
param (
$selectedNode,
$name,
$tag
)
$newNode = new-object System.Windows.Forms.TreeNode
$newNode.Name = $name
$newNode.Text = $name
$newNode.Tag = $tag
$selectedNode.Nodes.Add($newNode) | Out-Null
return $newNode
}

function Get-HelpTree {
if ($script:cmdletNodes)
{
$treeview1.Nodes.remove($script:cmdletNodes)
$form1.Refresh()
}
$script:cmdletNodes = New-Object System.Windows.Forms.TreeNode
$script:cmdletNodes.text = "PowerShell Help"
$script:cmdletNodes.Name = "PowerShell Help"
$script:cmdletNodes.Tag = "root"
$treeView1.Nodes.Add($script:cmdletNodes) | Out-Null

$treeView1.add_AfterSelect({
if ($this.SelectedNode.Tag -eq "Cmdlet") {
$helpText = Get-Help $this.SelectedNode.Name -Full
$richTextBox1.Text = $helpText | Out-String
$linkLabel1.Text = $helpText.relatedLinks.navigationLink[0].uri
$form1.refresh()
} else {
$richTextBox1.Text = "Example to show how to use TreeView control in PowerShell script"
$linkLabel1.Text = "http://www.ravichaganti.com/blog"
}
})

#Generate Module nodes
$modules = @("Microsoft.PowerShell.Core","Microsoft.PowerShell.Diagnostics","Microsoft.PowerShell.Host","Microsoft.PowerShell.Management","Microsoft.PowerShell.Security","Microsoft.PowerShell.Utility")

$modules | % {
$parentNode = Add-Node $script:cmdletNodes $_ "Module"
$moduleCmdlets = Get-Command -Module $_
$moduleCmdlets | % {
$childNode = Add-Node $parentNode $_.Name "Cmdlet"
}
}
$script:cmdletNodes.Expand()
}

#Generated Form Function
function GenerateForm {
########################################################################
# Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.7.0
# Generated On: 3/2/2010 5:46 PM
# Generated By: Ravikanth Chaganti (http://www.ravichaganti.com/blog)
########################################################################

#region Import the Assemblies
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
#endregion

#region Generated Form Objects
$form1 = New-Object System.Windows.Forms.Form
$linkLabel1 = New-Object System.Windows.Forms.LinkLabel
$label4 = New-Object System.Windows.Forms.Label
$label3 = New-Object System.Windows.Forms.Label
$label2 = New-Object System.Windows.Forms.Label
$button1 = New-Object System.Windows.Forms.Button
$richTextBox1 = New-Object System.Windows.Forms.RichTextBox
$treeView1 = New-Object System.Windows.Forms.TreeView
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
#endregion Generated Form Objects

#----------------------------------------------
#Generated Event Script Blocks
#----------------------------------------------
#Provide Custom Code for events specified in PrimalForms.
$button1_OnClick=
{
$form1.Close()

}

$OnLoadForm_StateCorrection=
{Get-HelpTree
}

$linkLabel1_OpenLink=
{
[system.Diagnostics.Process]::start($linkLabel1.text)
}
#----------------------------------------------
#region Generated Form Code
$form1.Text = "Primal Form"
$form1.Name = "form1"
$form1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 838
$System_Drawing_Size.Height = 612
$form1.ClientSize = $System_Drawing_Size


$linkLabel1.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",9,0,3,0)
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 539
$System_Drawing_Size.Height = 23
$linkLabel1.Size = $System_Drawing_Size
$linkLabel1.TabIndex = 10
$linkLabel1.Text = "http://www.ravichaganti.com/blog"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 253
$System_Drawing_Point.Y = 541
$linkLabel1.Location = $System_Drawing_Point
$linkLabel1.TabStop = $True
$linkLabel1.DataBindings.DefaultDataSourceUpdateMode = 0
$linkLabel1.Name = "linkLabel1"
$linkLabel1.add_click($linkLabel1_OpenLink)

$form1.Controls.Add($linkLabel1)

$label4.TabIndex = 9
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 136
$System_Drawing_Size.Height = 23
$label4.Size = $System_Drawing_Size
$label4.Text = "Cmdlet Help URI"
$label4.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",9,1,3,0)

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 253
$System_Drawing_Point.Y = 518
$label4.Location = $System_Drawing_Point
$label4.DataBindings.DefaultDataSourceUpdateMode = 0
$label4.Name = "label4"

$form1.Controls.Add($label4)

$label3.TabIndex = 6
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 100
$System_Drawing_Size.Height = 23
$label3.Size = $System_Drawing_Size
$label3.Text = "Description"
$label3.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",9,1,3,0)

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 255
$System_Drawing_Point.Y = 37
$label3.Location = $System_Drawing_Point
$label3.DataBindings.DefaultDataSourceUpdateMode = 0
$label3.Name = "label3"

$form1.Controls.Add($label3)

$label2.TabIndex = 5
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 177
$System_Drawing_Size.Height = 23
$label2.Size = $System_Drawing_Size
$label2.Text = "PowerShell Help Tree"
$label2.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",9,1,3,0)

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 13
$System_Drawing_Point.Y = 13
$label2.Location = $System_Drawing_Point
$label2.DataBindings.DefaultDataSourceUpdateMode = 0
$label2.Name = "label2"

$form1.Controls.Add($label2)

$button1.TabIndex = 4
$button1.Name = "button1"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 75
$System_Drawing_Size.Height = 23
$button1.Size = $System_Drawing_Size
$button1.UseVisualStyleBackColor = $True

$button1.Text = "Close"

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 253
$System_Drawing_Point.Y = 577
$button1.Location = $System_Drawing_Point
$button1.DataBindings.DefaultDataSourceUpdateMode = 0
$button1.add_Click($button1_OnClick)

$form1.Controls.Add($button1)

$richTextBox1.Name = "richTextBox1"
$richTextBox1.Text = ""
$richTextBox1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 255
$System_Drawing_Point.Y = 61
$richTextBox1.Location = $System_Drawing_Point
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 562
$System_Drawing_Size.Height = 454
$richTextBox1.Size = $System_Drawing_Size
$richTextBox1.TabIndex = 1

$form1.Controls.Add($richTextBox1)

$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 224
$System_Drawing_Size.Height = 563
$treeView1.Size = $System_Drawing_Size
$treeView1.Name = "treeView1"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 13
$System_Drawing_Point.Y = 37
$treeView1.Location = $System_Drawing_Point
$treeView1.DataBindings.DefaultDataSourceUpdateMode = 0
$treeView1.TabIndex = 0

$form1.Controls.Add($treeView1)

#endregion Generated Form Code

#Save the initial state of the form
$InitialFormWindowState = $form1.WindowState
#Init the OnLoad event to correct the initial state of the form
$form1.add_Load($OnLoadForm_StateCorrection)
#Show the Form
$form1.ShowDialog()| Out-Null

} #End Function

#Call the Function
GenerateForm

Další script

function Get-ProcessInfo {
$array = New-Object System.Collections.ArrayList
$Script:procInfo = Get-Process | Select Id,Name,Path,Description,VM,WS,CPU,Company | sort -Property Name
$array.AddRange($procInfo)
$dataGrid1.DataSource = $array
$form1.refresh()
}

#Generated Form Function
function GenerateForm {
########################################################################
# Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.8.0
# Generated On: 2/24/2010 11:38 AM
# Generated By: Ravikanth Chaganti (http://www.ravichaganti.com/blog)
########################################################################

#region Import the Assemblies
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
#endregion

#region Generated Form Objects
$form1 = New-Object System.Windows.Forms.Form
$label1 = New-Object System.Windows.Forms.Label
$button3 = New-Object System.Windows.Forms.Button
$button2 = New-Object System.Windows.Forms.Button
$button1 = New-Object System.Windows.Forms.Button
$dataGrid1 = New-Object System.Windows.Forms.DataGrid
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
#endregion Generated Form Objects

#----------------------------------------------
#Generated Event Script Blocks
#----------------------------------------------
#Provide Custom Code for events specified in PrimalForms.
$button3_OnClick=
{
$Form1.Close()
}

$button1_OnClick=
{
Get-ProcessInfo
}

$button2_OnClick=
{
$selectedRow = $dataGrid1.CurrentRowIndex
if (($procid=$Script:procInfo[$selectedRow].Id)) {
Stop-Process -Id $procid -Confirm
}
}

$OnLoadForm_UpdateGrid=
{
Get-ProcessInfo
}

#----------------------------------------------
#region Generated Form Code
$form1.Text = "Primal Form"
$form1.Name = "form1"
$form1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 517
$System_Drawing_Size.Height = 414
$form1.ClientSize = $System_Drawing_Size

$label1.TabIndex = 4
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 155
$System_Drawing_Size.Height = 23
$label1.Size = $System_Drawing_Size
$label1.Text = "Process Manager"
$label1.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",9.75,2,3,0)
$label1.ForeColor = [System.Drawing.Color]::FromArgb(255,0,102,204)

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 13
$System_Drawing_Point.Y = 13
$label1.Location = $System_Drawing_Point
$label1.DataBindings.DefaultDataSourceUpdateMode = 0
$label1.Name = "label1"

$form1.Controls.Add($label1)

$button3.TabIndex = 3
$button3.Name = "button3"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 75
$System_Drawing_Size.Height = 23
$button3.Size = $System_Drawing_Size
$button3.UseVisualStyleBackColor = $True

$button3.Text = "Close"

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 429
$System_Drawing_Point.Y = 378
$button3.Location = $System_Drawing_Point
$button3.DataBindings.DefaultDataSourceUpdateMode = 0
$button3.add_Click($button3_OnClick)

$form1.Controls.Add($button3)

$button2.TabIndex = 2
$button2.Name = "button2"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 75
$System_Drawing_Size.Height = 23
$button2.Size = $System_Drawing_Size
$button2.UseVisualStyleBackColor = $True

$button2.Text = "Kill Process"

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 230
$System_Drawing_Point.Y = 378
$button2.Location = $System_Drawing_Point
$button2.DataBindings.DefaultDataSourceUpdateMode = 0
$button2.add_Click($button2_OnClick)

$form1.Controls.Add($button2)

$button1.TabIndex = 1
$button1.Name = "button1"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 75
$System_Drawing_Size.Height = 23
$button1.Size = $System_Drawing_Size
$button1.UseVisualStyleBackColor = $True

$button1.Text = "Refresh"

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 13
$System_Drawing_Point.Y = 379
$button1.Location = $System_Drawing_Point
$button1.DataBindings.DefaultDataSourceUpdateMode = 0
$button1.add_Click($button1_OnClick)

$form1.Controls.Add($button1)

$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 492
$System_Drawing_Size.Height = 308
$dataGrid1.Size = $System_Drawing_Size
$dataGrid1.DataBindings.DefaultDataSourceUpdateMode = 0
$dataGrid1.HeaderForeColor = [System.Drawing.Color]::FromArgb(255,0,0,0)
$dataGrid1.Name = "dataGrid1"
$dataGrid1.DataMember = ""
$dataGrid1.TabIndex = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 13
$System_Drawing_Point.Y = 48
$dataGrid1.Location = $System_Drawing_Point

$form1.Controls.Add($dataGrid1)

#endregion Generated Form Code

#Save the initial state of the form
$InitialFormWindowState = $form1.WindowState

#Add Form event
$form1.add_Load($OnLoadForm_UpdateGrid)

#Show the Form
$form1.ShowDialog()| Out-Null

} #End Function

#Call the Function
GenerateForm

čtvrtek 11. listopadu 2010

Powershell networktools script

Pěkný scriptík powershellu z tipy dne na kterem zaroven budeme demonstrovat výstup ogv,viz formatování výstupu,roura, |ogv.

scriptík si pokud ho budeme použivat častěj rovnou upneme k powershellu a spouštime jako upnutý.

Viz pinned script

samozřejmě opět ůpravám se meze nekladou a výstup ogv nám v takovém připadě umožnuje vyhledávání a interaktivní filtraci v datech ktere jsme do výstupu poslali.

Obsah scriptu

function Return-DropDown {
$Choice = $DropDown.SelectedItem.ToString()
$Address = $Address.Text
#$Form.Close()
if ($choice -eq "ping")
{
write-host "PING $address"
Test-Connection $address | Out-gridview
write-host
}
elseif ($choice -eq "nslookup")
{
write-host "NSLOOKUP $address"
nslookup $address | Out-gridview
write-host
}
elseif ($choice -eq "BIOS")
{
write-host "BIOS of $address"
Get-WmiObject win32_bios -ComputerName $address | Out-gridview
write-host
}
elseif ($choice -eq "Services")
{
write-host "Services of $address"
Get-WmiObject win32_service -ComputerName $address | Out-gridview
write-host
}
elseif ($choice -eq "Programs")
{
write-host "Programs installed on $address"
Get-WmiObject win32_product -ComputerName $address | Out-gridview
write-host
}
elseif ($choice -eq "RemoteUninstall")
{
$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = "Data Entry Form"
$objForm.Size = New-Object System.Drawing.Size(300,200)
$objForm.StartPosition = "CenterScreen"

$objForm.KeyPreview = $True
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Enter")
{$y=$objTextBox.Text;$objForm.Close()}})
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape")
{$objForm.Close()}})

$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(75,120)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "OK"
$OKButton.Add_Click({$location=$objTextBox.Text;$objForm.Close()})
$objForm.Controls.Add($OKButton)

$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(150,120)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = "Cancel"
$CancelButton.Add_Click({$objForm.Close()})
$objForm.Controls.Add($CancelButton)

$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(10,20)
$objLabel.Size = New-Object System.Drawing.Size(280,20)
$objLabel.Text = "Name of the application to be uninstalled:"
$objForm.Controls.Add($objLabel)

$objLabel2 = New-Object System.Windows.Forms.Label
$objLabel2.Location = New-Object System.Drawing.Size(10,50)
$objLabel2.Size = New-Object System.Drawing.Size(190,20)
$objLabel2.Text = "Don't be too generic!"
$objForm.Controls.Add($objLabel2)

$objTextBox = New-Object System.Windows.Forms.TextBox
$objTextBox.Location = New-Object System.Drawing.Size(10,80)
$objTextBox.Size = New-Object System.Drawing.Size(260,20)
$objForm.Controls.Add($objTextBox)

$objForm.Topmost = $True

$objForm.Add_Shown({$objForm.Activate()})
[void] $objForm.ShowDialog()

Try{
$app = Get-WmiObject win32_product -ComputerName $Address -ErrorAction SilentlyContinue | Where-Object {$_.name -match $location}
$returnvalue = $app.uninstall() | Select-Object -Property returnvalue -ErrorAction SilentlyContinue

if($returnvalue.returnvalue -eq "0")
{[Windows.Forms.MessageBox]::Show("Installation was successful!")}

else
{[Windows.Forms.MessageBox]::Show("Installation was not successful!")}}

Catch{
if($error[0] -match "The RPC server is unavailable" -or $error[0] -match "null-valued"){
[Windows.Forms.MessageBox]::Show("Computer is unreachable, name is invalid or application does not exist.")}}
}
elseif ($choice -eq "RemoteInstall")
{

$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = "Data Entry Form"
$objForm.Size = New-Object System.Drawing.Size(300,200)
$objForm.StartPosition = "CenterScreen"

$objForm.KeyPreview = $True
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Enter")
{$y=$objTextBox.Text;$objForm.Close()}})
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape")
{$objForm.Close()}})

$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(75,120)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "OK"
$OKButton.Add_Click({$location=$objTextBox.Text;$objForm.Close()})
$objForm.Controls.Add($OKButton)

$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(150,120)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = "Cancel"
$CancelButton.Add_Click({$objForm.Close()})
$objForm.Controls.Add($CancelButton)

$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(10,20)
$objLabel.Size = New-Object System.Drawing.Size(280,20)
$objLabel.Text = "UNC path for the application to be installed:"
$objForm.Controls.Add($objLabel)

$objLabel2 = New-Object System.Windows.Forms.Label
$objLabel2.Location = New-Object System.Drawing.Size(10,50)
$objLabel2.Size = New-Object System.Drawing.Size(190,20)
$objLabel2.Text = "Eg: \\computername\c$\firefox.msi"
$objForm.Controls.Add($objLabel2)

$objTextBox = New-Object System.Windows.Forms.TextBox
$objTextBox.Location = New-Object System.Drawing.Size(10,80)
$objTextBox.Size = New-Object System.Drawing.Size(260,20)
$objForm.Controls.Add($objTextBox)

$objForm.Topmost = $True

$objForm.Add_Shown({$objForm.Activate()})
[void] $objForm.ShowDialog()

Try{
$returnvalue = (Get-WmiObject -ComputerName $Address -List -ErrorAction SilentlyContinue | Where-Object -FilterScript {$_.Name -eq "win32_product"}).install($location) | Select-Object -Property returnvalue

if($returnvalue.returnvalue -eq "0")
{[Windows.Forms.MessageBox]::Show("Installation was successful!")}

else
{[Windows.Forms.MessageBox]::Show("Installation was not successful!")}
}
Catch{
if($error[0] -match "The RPC server is unavailable" -or $error[0] -match "null-valued"){
[Windows.Forms.MessageBox]::Show("Computer is unreachable, name is invalid or application does not exist.")}}

}
elseif ($Choice -eq "MapNetworkDrive")
{

$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = "Data Entry Form"
$objForm.Size = New-Object System.Drawing.Size(300,200)
$objForm.StartPosition = "CenterScreen"

$objForm.KeyPreview = $True
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Enter")
{$y=$objTextBox.Text;$objForm.Close()}})
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape")
{$objForm.Close()}})

$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(75,120)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "OK"
$OKButton.Add_Click({$y=$objTextBox.Text;$objForm.Close()})
$objForm.Controls.Add($OKButton)

$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(150,120)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = "Cancel"
$CancelButton.Add_Click({$objForm.Close()})
$objForm.Controls.Add($CancelButton)

$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(10,20)
$objLabel.Size = New-Object System.Drawing.Size(280,20)
$objLabel.Text = "Letter of new Network Drive:"
$objForm.Controls.Add($objLabel)

$objTextBox = New-Object System.Windows.Forms.TextBox
$objTextBox.Location = New-Object System.Drawing.Size(10,40)
$objTextBox.Size = New-Object System.Drawing.Size(260,20)
$objForm.Controls.Add($objTextBox)

$objForm.Topmost = $True

$objForm.Add_Shown({$objForm.Activate()})
[void] $objForm.ShowDialog()

$x = $y

$objTextBox.clear()
$objLabel.Text = "UNC:"
$objForm.Controls.Add($objLabel)
$objForm.Controls.Add($objTextBox)
$objForm.Add_Shown({$objForm.Activate()})
[void] $objForm.ShowDialog()

$map = New-Object -ComObject wscript.network
if($x -match ":"){Try{$map.MapNetworkDrive($x,$y)}Catch{if($error[0] -match "The local device"){[Windows.Forms.MessageBox]::Show("The local device is already in use.")}else{[Windows.Forms.MessageBox]::Show("The network name cannot be found.")}}}
else
{Try{$x = $x+":"; $map.MapNetworkDrive($x,$y)}Catch{if($error[0] -match "The local device"){[Windows.Forms.MessageBox]::Show("The local device is already in use.")}else{[Windows.Forms.MessageBox]::Show("The network name cannot be found.")}}}

}
}

[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")

$Form = New-Object System.Windows.Forms.Form

$Form.width = 300
$Form.height = 250
$Form.Text = "Network Tools"
$Form.maximumsize = New-Object System.Drawing.Size(300,250)
$Form.startposition = "centerscreen"
$Form.KeyPreview = $True
$Form.Add_KeyDown({if ($_.KeyCode -eq "Enter")
{return-dropdown}})
$Form.Add_KeyDown({if ($_.KeyCode -eq "Escape")
{$Form.Close()}})

$DropDown = new-object System.Windows.Forms.ComboBox
$DropDown.Location = new-object System.Drawing.Size(100,10)
$DropDown.Size = new-object System.Drawing.Size(130,30)

ForEach ($Item in $DropDownArray) {
$DropDown.Items.Add($Item)
}

$Form.Controls.Add($DropDown)

$DropDownLabel = new-object System.Windows.Forms.Label
$DropDownLabel.Location = new-object System.Drawing.Size(10,10)
$DropDownLabel.size = new-object System.Drawing.Size(100,20)
$DropDownLabel.Text = "Command"
$Form.Controls.Add($DropDownLabel)

$Button = new-object System.Windows.Forms.Button
$Button.Location = new-object System.Drawing.Size(100,150)
$Button.Size = new-object System.Drawing.Size(100,20)
$Button.Text = "OK"
$Button.Add_Click({Return-DropDown})
$form.Controls.Add($Button)

$address = new-object System.Windows.Forms.TextBox
$address.Location = new-object System.Drawing.Size(100,100)
$address.Size = new-object System.Drawing.Size(100,20)

$Form.Controls.Add($address)

$addresslabel = new-object System.Windows.Forms.Label
$addresslabel.Location = new-object System.Drawing.Size(10,100)
$addresslabel.size = new-object System.Drawing.Size(100,20)
$addresslabel.Text = "Computer"
$Form.Controls.Add($addresslabel)

$authorlabel = new-object System.Windows.Forms.Label
$authorlabel.Location = new-object System.Drawing.Size(160,185)
$authorlabel.size = new-object System.Drawing.Size(200,15)
$authorlabel.Text = "Powered by F. Binotto."
$Form.Controls.Add($authorlabel)

$Form.Add_Shown({$Form.Activate()})
$Form.ShowDialog()

Video


pondělí 8. listopadu 2010

Powershell set-acl

Natavení ACL pomocí powershellu.Tento přiklad je takový základní kdy nastavujeme acl pomocí powershellu okopirovaním acl ze složky kde opravnění jsou tak jak je chceme mít na složku ktera je má jinak.

Cest existuje několik,je to serial o powershellu takže ukazka jak na to v Powershellu – jedna z mnoha cest v něm.za jistých okolností napřiklad  v AD nebo když jde o okopirovaní nikoliv složka a co je v ní a vše stejně na jinou složku a vše co je v ní  ale jde o strom – strom a třeba v AD tak se to děla v Powershellu jinak.

Takže

get-acl D:\experimenty\test | set-acl  D:\experimenty\test2

Další možne scenaře a cesty

$PesACL = get-acl c:\pes.txt

set-acl -path C:\kocka.txt -AclObject $PesACL

Varianta soubor – soubor,trochu jinak napsaná.

Potom napřiklad

get-childitem c:\tvojeslozka-recurse -force | set-acl -aclobject $PesACL –whatif

tvojeslozka na disku C a vše co je v ní přebira stejne nastavení od pes.txt

Další varianta – vhodne pro kapku jine situace

$Acl.RemoveAccessRule($Ar) $Acl.RemoveAccessRuleAll()

Remove acl myslim netřeba komentovat.

Video k prvnímu připadu,ostatní jsou ukazky zbytečné ,k active directory a servrům se hodlam posunout až se mně budet chtít víc věnovat Powergui.


Powershell oprávnění

neděle 7. listopadu 2010

Powershell roura

Scriptik ktery si volá ladem skladem naházené přikazy v obyčejnem textaku.osobně mam předpřipravený takový texták který mně plně nahrazuje známý Everest napřiklad,spiš si myslím že everest je o konskou hlavu zpátky proti textáku protože tady nejde jenom o inventuru ale rovnou můžu administrovat připadně co potřebuji.

 

Powershell hotfixy

Bliži se sp1 v připadě seven tak se neuškodí podivat na hotfixy a restore point Veselý obličej


Powershell vložení USB disku

Potřebujete vědět že byl do stroje vložen USB disk?Jedna z možností je volaní wmi pomocí powershellu.

Po zaregistrování stačí vložit kratký přikaz který se zeptá.

Takže nejprve  Register-WmiEvent -Query "Select * from __InstanceCreationEvent within 5 where targetinstance isa 'win32_logicaldisk'" -SourceIdentifier disk -Timeout 1000

Samozřejmě se nic neděje.

Následně

PS C:\> Get-Event -SourceIdentifier disk

Pokračujeme

$a = Get-Event -SourceIdentifier disk

No a pro příští použití už stačí jenom zadávat toto

$a.SourceEventArgs.NewEvent.TargetInstance

usb disk schranka

úterý 2. listopadu 2010

Powershell–různé praktické

Stahování souboru z internetu pomocí powershellu,scriptík si samozřejmě může každý ohnout dle svých představ.

[reflection.assembly]::LoadWithPartialName("Microsoft.VisualBasic") | Out-Null
$url = 'http://www.idera.com/images/Tours/Videos/PowerShell-Plus-IDE-1.wmv'
$dest = "$home\video.wmv"
$object = New-Object Microsoft.VisualBasic.Devices.Network
$object.DownloadFile($url, $dest, "", "", $true, 500, $true, "DoNothing")
Invoke-Item $dest

Powershell runas

Start-Process powershell -verb runas

Start procesu jako jiny uživatel

Start-Process powershell -LoadUserProfile -Credential (Get-Credential)

Pěkný scriptík broken hardware

 
# Display Computer details
"Computer Details:"
$comp = gwmi Win32_ComputerSystem
"Manufacturer: {0}" -f $comp.Manufacturer
"Model:        {0}" -f $comp.Model
$computer2 = Get-WmiObject Win32_ComputerSystemProduct
"Service Tag:  {0}" -f $computer2.IdentifyingNumber
""
 
#Get hardware that is errored
"Hardware that's not working list" 
$broken = Get-WmiObject Win32_PnPEntity | where {$_.ConfigManagerErrorCode -ne 0}
 
#Display broken hardware
foreach ($obj in $broken){    
"Description:  {0}" -f  $obj.Description
"Device ID:    {0}" -f  $obj.DeviceID
"Error ID:     {0}" -f  $obj.ConfigManagerErrorCode


""
}

Scriptík vhodný pro spoustu lidí lidí co navštěvují forum s jedním dotazem pořád dokola – nechci aby se sit hlásila jako neidentifikovatelná a nemůžu to změnit Veselý obličej

$NLMType = [Type]::GetTypeFromCLSID(‘DCB00C01-570F-4A9B-8D69-199FDBA5723B’)

$INetworkListManager = [Activator]::CreateInstance($NLMType)

 

$NLM_ENUM_NETWORK_CONNECTED  = 1

$NLM_NETWORK_CATEGORY_PUBLIC = 0x00

$NLM_NETWORK_CATEGORY_PRIVATE = 0x01

$UNIDENTIFIED = "Unidentified network"

 

$INetworks = $INetworkListManager.GetNetworks($NLM_ENUM_NETWORK_CONNECTED)

 

foreach ($INetwork in $INetworks)

{

    $Name = $INetwork.GetName()

    $Category = $INetwork.GetCategory()

 

    if ($INetwork.IsConnected -and ($Category -eq $NLM_NETWORK_CATEGORY_PUBLIC) -and ($Name -eq $UNIDENTIFIED))

    {

        $INetwork.SetCategory($NLM_NETWORK_CATEGORY_PRIVATE)

    }

}

neděle 24. října 2010

Powershell disky oddíly a blbinky

Rychlá serie pár scriptíku bez vysvětlování co dělají a jak to dělají.Kdo chtěl už se tím prokousal,ostatní většinu ani nespustí.

Zakladní výpis logical disk

Get-WmiObject Win32_LogicalDisk | `
Select Name, DriveType, FileSystem, Size, FreeSpace | `
Format-Table -AutoSize

 

WIN32 Mount point

$computer = "LocalHost"
$namespace = "root\CIMV2"
Get-WmiObject -class Win32_MountPoint -computername $computer -namespace $namespace

Win32_OSRecoveryConfiguration

$computer = "LocalHost"
$namespace = "root\CIMV2"
Get-WmiObject -class Win32_OSRecoveryConfiguration -computername $computer -namespace $namespace

Win32_ShadowCopy

$computer = "LocalHost"
$namespace = "root\CIMV2"
Get-WmiObject -class Win32_ShadowCopy -computername $computer -namespace $namespace

Win32_SystemAccount

$computer = "LocalHost"
$namespace = "root\CIMV2"
Get-WmiObject -class Win32_SystemAccount -computername $computer -namespace $namespace

Win32_UserAccount

$computer = "LocalHost"
$namespace = "root\CIMV2"
Get-WmiObject -class Win32_UserAccount -computername $computer -namespace $namespace

Win32_DiskDrive

$computer = "LocalHost"
$namespace = "root\CIMV2"
Get-WmiObject -class Win32_DiskDrive -computername $computer -namespace $namespace

Win32_DiskDriveToDiskPartition

$computer = "LocalHost"
$namespace = "root\CIMV2"
Get-WmiObject -class Win32_DiskDriveToDiskPartition -computername $computer -namespace $namespace

Win32_DiskPartition

$computer = "LocalHost"
$namespace = "root\CIMV2"
Get-WmiObject -class Win32_DiskPartition -computername $computer -namespace $namespace

Win32_DiskQuota

$computer = "LocalHost"
$namespace = "root\CIMV2"
Get-WmiObject -class Win32_DiskQuota -computername $computer -namespace $namespace

Win32_DMAChannel

$computer = "LocalHost"
$namespace = "root\CIMV2"
Get-WmiObject -class Win32_DMAChannel -computername $computer -namespace $namespace

Win32_DriverForDevice

$computer = "LocalHost"
$namespace = "root\CIMV2"
Get-WmiObject -class Win32_DriverForDevice -computername $computer -namespace $namespace

Win32_IDEController

$computer = "LocalHost"
$namespace = "root\CIMV2"
Get-WmiObject -class Win32_IDEController -computername $computer -namespace $namespace

Win32_LogicalDiskRootDirectory

$computer = "LocalHost"
$namespace = "root\CIMV2"
Get-WmiObject -class Win32_LogicalDiskRootDirectory -computername $computer -namespace $namespace

Win32_IDEControllerDevice

$computer = "LocalHost"
$namespace = "root\CIMV2"
Get-WmiObject -class Win32_IDEControllerDevice -computername $computer -namespace $namespace

Win32_LogonSession

$computer = "LocalHost"
$namespace = "root\CIMV2"
Get-WmiObject -class Win32_LogonSession -computername $computer -namespace $namespace

Win32_Volume

$computer = "LocalHost"
$namespace = "root\CIMV2"
Get-WmiObject -class Win32_Volume -computername $computer -namespace $namespace

Některe vyžadují jednoznačně PowershellV2,ale myslim že pro XP a Visty byl formou stažení  v Seven je to jasné.Součast systemu.

Něco bude možná chtit  Windows 7 Resource Kit PowerShell Pack  ale kdo používá tak opět – dávno pradávno má.

Na zavěr jedna z legracek typu rss feed v powershellu,upravování obrazků v powershellu tak tady pro změnu kdyby Vás štvalo gui třeba WINAMPU

http://theessentialexchange.com/blogs/michael/archive/2007/11/15/shuffle-play-your-audio-files-with-powershell.aspx

No a krasná ukázka proč je powershell OBJEKTOVÝ SHELL takže něco uplně jineho než cmd

NEWTWORK MAP DRIVE -  KDO SI TO CHCE V GRAFICKEM ROZHRANÍ NAKLIKAT V SHELLU,ZVLAŠTNÍ KOMBINACE…

 

function mapdrive {

$map = New-Object -ComObject wscript.network
if($letter.Text -match ":"){
$letter = $letter.Text}
else{$letter = $letter.Text+":"}
$map.MapNetworkDrive($letter,$path.Text)

}

 

[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")

$Form = New-Object System.Windows.Forms.Form

$Form.width = 500
$Form.height = 350
$Form.Text = "Map Drive"
$Form.backcolor = "#5D8AA8"
$Form.maximumsize = New-Object System.Drawing.Size(500, 350)
$Form.startposition = "centerscreen"
$Form.KeyPreview = $True
$Form.Add_KeyDown({if ($_.KeyCode -eq "Escape")
    {$Form.Close()}})

$ListButton = new-object System.Windows.Forms.Button
$ListButton.Location = new-object System.Drawing.Size(200,200)
$ListButton.Size = new-object System.Drawing.Size(80,30)
$ListButton.Text = "MAP"
$ListButton.FlatAppearance.MouseOverBackColor = [System.Drawing.Color]::FromArgb(255, 255, 192);
$ListButton.ImageAlign = [System.Drawing.ContentAlignment]::MiddleLeft;
$Listbutton.FlatStyle = [System.Windows.Forms.FlatStyle]::Flat
$ListButton.Add_Click({mapdrive})

$Form.Controls.Add($ListButton)

$letter = new-object System.Windows.Forms.TextBox
$letter.Location = new-object System.Drawing.Size(65,60)
$letter.Size = new-object System.Drawing.Size(100,20)

$Form.Controls.Add($letter)

$letterlabel = new-object System.Windows.Forms.Label
$letterlabel.Location = new-object System.Drawing.Size(60,10)
$letterlabel.size = new-object System.Drawing.Size(100,50)
$letterlabel.Font = new-object System.Drawing.Font("Microsoft Sans Serif",12,[System.Drawing.FontStyle]::Bold)
$letterlabel.Text = "Drive Letter"
$Form.Controls.Add($letterlabel)

$pathlabel = new-object System.Windows.Forms.Label
$pathlabel.Location = new-object System.Drawing.Size(310,10)
$pathlabel.size = new-object System.Drawing.Size(200,50)
$pathlabel.Font = new-object System.Drawing.Font("Microsoft Sans Serif",12,[System.Drawing.FontStyle]::Bold)
$pathlabel.Text = "UNC path"
$Form.Controls.Add($pathlabel)

$path = new-object System.Windows.Forms.TextBox
$path.Location = new-object System.Drawing.Size(300,60)
$path.Size = new-object System.Drawing.Size(100,20)


$Form.Controls.Add($path)


$Form.Add_Shown({$Form.Activate()})
$Form.ShowDialog()

úterý 11. května 2010

Powershell pár vypisů

Pár powershell scriptíku ktere bych nazval informační

Takže jako první,jak jsme na tom s kodeky

$computer = "LocalHost"
$namespace = "root\CIMV2"
Get-WmiObject -class Win32_CodecFile -computername $computer -namespace $namespace

O co se script zajímá

kodek

Něco o mašině a o systemu

$computer = "LocalHost"
$namespace = "root\CIMV2"
Get-WmiObject -class Win32_ComputerSystem -computername $computer -namespace $namespace

zase které položky se bude snažit zjistit

masina

Jakpak jsme na tom s licencí

$computer = "LocalHost"
$namespace = "root\CIMV2"
Get-WmiObject -class SoftwareLicensingProduct -computername $computer -namespace $namespace

Vše o operačním systému

$strComputer = "."

$colItems = get-wmiobject -class "Win32_OperatingSystem" -namespace "root\CIMV2" `
-computername $strComputer

foreach ($objItem in $colItems) {
write-host "Boot Device: " $objItem.BootDevice
write-host "Build Number: " $objItem.BuildNumber
write-host "Build Type: " $objItem.BuildType
write-host "Caption: " $objItem.Caption
write-host "Code Set: " $objItem.CodeSet
write-host "Country Code: " $objItem.CountryCode
write-host "Creation Class Name: " $objItem.CreationClassName
write-host "CS Creation Class Name: " $objItem.CSCreationClassName
write-host "CSD Version: " $objItem.CSDVersion
write-host "CS Name: " $objItem.CSName
write-host "Current Time Zone: " $objItem.CurrentTimeZone
write-host "Debug: " $objItem.Debug
write-host "Description: " $objItem.Description
write-host "Distributed: " $objItem.Distributed
write-host "Encryption Level: " $objItem.EncryptionLevel
write-host "Foreground Application Boost: " $objItem.ForegroundApplicationBoost
write-host "Free Physical Memory: " $objItem.FreePhysicalMemory
write-host "Free Space In Paging Files: " $objItem.FreeSpaceInPagingFiles
write-host "Free Virtual Memory: " $objItem.FreeVirtualMemory
write-host "Installation Date: " $objItem.InstallDate
write-host "Large System Cache: " $objItem.LargeSystemCache
write-host "Last Boot-Up Time: " $objItem.LastBootUpTime
write-host "Local DateTime: " $objItem.LocalDateTime
write-host "Locale: " $objItem.Locale
write-host "Manufacturer: " $objItem.Manufacturer
write-host "Maximum Number Of Processes: " $objItem.MaxNumberOfProcesses
write-host "Maximum Process Memory Size: " $objItem.MaxProcessMemorySize
write-host "Name: " $objItem.Name
write-host "Number Of Licensed Users: " $objItem.NumberOfLicensedUsers
write-host "Number Of Processes: " $objItem.NumberOfProcesses
write-host "Number Of Users: " $objItem.NumberOfUsers
write-host "Organization: " $objItem.Organization
write-host "Operating System Language: " $objItem.OSLanguage
write-host "Operating System Product Suite: " $objItem.OSProductSuite
write-host "Operating System Type: " $objItem.OSType
write-host "Other Type Description: " $objItem.OtherTypeDescription
write-host "Plus Product ID: " $objItem.PlusProductID
write-host "Plus Version Number: " $objItem.PlusVersionNumber
write-host "Primary: " $objItem.Primary
write-host "Product Type: " $objItem.ProductType
write-host "Quantum Length: " $objItem.QuantumLength
write-host "Quantum Type: " $objItem.QuantumType
write-host "Registered User: " $objItem.RegisteredUser
write-host "Serial Number: " $objItem.SerialNumber
write-host "Service Pack Major Version: " $objItem.ServicePackMajorVersion
write-host "Service Pack Minor Version: " $objItem.ServicePackMinorVersion
write-host "Size Stored In Paging Files: " $objItem.SizeStoredInPagingFiles
write-host "Status: " $objItem.Status
write-host "Suite Mask: " $objItem.SuiteMask
write-host "System Device: " $objItem.SystemDevice
write-host "System Directory: " $objItem.SystemDirectory
write-host "System Drive: " $objItem.SystemDrive
write-host "Total Swap Space Size: " $objItem.TotalSwapSpaceSize
write-host "Total Virtual Memory Size: " $objItem.TotalVirtualMemorySize
write-host "Total Visible Memory Size: " $objItem.TotalVisibleMemorySize
write-host "Version: " $objItem.Version
write-host "Windows Directory: " $objItem.WindowsDirectory
write-host
}

Bios

$computer = "LocalHost"
$namespace = "root\CIMV2"
Get-WmiObject -class Win32_SystemBIOS -computername $computer -namespace $namespace

Příští díl se zaměří pouze a jenom na věci týkající se hardisků,oddílů na nich atd

úterý 13. dubna 2010

Videotutorial Powershell

Dnešni članek bude článek nečlánek.

Stahněte si videotutorial.Zdroj uveden ve videu.

A když jsme u věci neuškodi se zaregristrovat tady powershell.com a stahnout PDF Administrator's Guide to Windows PowerShell Remoting

sobota 13. února 2010

Powergui

Powershell Powergui

Dnes představím nástroj který bude asi pro řadu lidí stravitelnější než Powershell a sice grafickou nadstavbu Powergui.

Samozřejmě přímo z prostředí lze spouštět powershell konzoli,navíc zde máme možnost debuggingu a další vychytávky.Na stránkách projektu se můžete seznámit s tím co jsou tzv. powerpack a jak se v prostředí powergui používají.Protože nastroj je to hodně mocný – ale je to pořád vlastně jenom powershell,tak místo X slov si raději prohlédněte video.

Mimochodem všimněte si okénka PowerShell Script – po kliknutí uvidíte odpovídající script.

Adresa projektu

http://www.powergui.org/index.jspa

Video

pátek 12. února 2010

Portable Powershell

Spiš než příspěvek,protože momentálně se mně žádné psát za a nechce,za b nemám toho času by toto mohla být noticka pro twitter.

Takže v současnosti testuji portable powershell,jde o projekt na privátní pozvání,neveřejný a je to perfektní věc.

Obecně portable věci celkem se mně libí a v případě powershellu dvojnásobek.

Za prvé stáhnete si dvě verze portableps1 a portableps2 a máte obě verze powershellu, pro XP i pro Seven a Visty.Za druhé portable powershell funguje na strojích kde powershell není, to je jasné – prostě ho nosím na flashce ale funguje i na strojích kde je a podle diskuze to byl paradoxně celkem problem.

portablepowershell

takže na zavěr již jen adresa projektu

http://shelltools.wik.is/Portable_PowerShell