16 February 2015

Variable scope

declare a variable in script scope

$Script:text  = 'text'


alternative to scope is synchronized collections

$hash = [hashtable]::Synchronized(@{})
$hash.text = "text"

15 February 2015

Workflow

Powershell workflow is part of .NET Windows Workflow Foundation.


  • survive reboots and recover automatically from failures
  • state can be saved; checkpoints can be set
  • parallelizable
  • activities run independently of one another
  • uses the same syntax as a powershell function

Workflow script activity keywords:
  • InlineScript - run standard cmdlets as an activity
  • Sequence - control the order of execution of multiple activities
  • Parallel - run multiple activities in parallel - command execution runs in arbitrary order.
  • Foreach -parallel - iterate through a collection in parallel. Command in the scriptblock run sequentially.
  • Checkpoint-Workflow - create an on disk representation of workflow state
  • Suspend-Workflow - allow a workflow to be suspended (can be resumed)

12 February 2015

ISE script debugging


F9   - set line breakpoint - the script will pause when the designated line must be executed

F10 - step over - executes the current statement and then stop at the next statement. If the current statements is a function or script call then the debugger executes the whole function or script, and it stops at the next statement.

F11 - step into - executes the current statement and then stops at the next statement. If the current statement is a function or script call, then the debugger steps into that function or script.

SHIFT + F11 - step out - steps out of the current function and up one level if the function is nested. If in the main body, the script is executed to the end, or to the next breakpoint.

F5 - continue - continues execution to the end, or to the next breakpoint.

09 February 2015

Motherboard model and manufacturer

Get-CimInstance Win32_BaseBoard | Select-Object Manufacturer, Product

Get-WmiObject Win32_BaseBoard | Select-Object Manufacturer, Product


Use wmic:

wmic baseboard get product, manufacturer