This project is read-only.

Command Line Use


Opens the framework dialog for choosing scripts.

framework.ps1 -ScriptPath [\path to script\] -OU [$True|$False] -ADSPath 'OU=Workstations,DC=company,DC=com'|-CSVPath 'c:\input\computers.csv' -Parameters [Name:Value, Name:Value...]

Runs the specified script, if no parameters are passed the parameter dialog is shown.
  • If -OU $True, the OU Chooser is displayed in the parameter dialog.
  • ADSPath specify the LDAP URI to the resources you are interested in, excluding the LDAP://
  • CSVPath specify the path to the csv file of computers

The entire command-line can piped through Format-List or Export-CSV to better suite your particular needs.

Write framework enabled code

The scripts that run inside the framework are basically the block of code you would normally run inside a Do or For loop. As such it's ideally suited for presenting single-purposed scripts that would be run against a number of computer objects.

If your script is like most you will need one or more parameters, if you need to run your script against a group of computer in an OU this particular parameter is provided to you through the framework. But if you are running it against an individual computer, say for testing, you may want to specify a parameter which is fairly easy.

First define an empty array of script parameters:
$ScriptParameters = @()

Next, you will want to prompt for a computer name if you're not running against an OU:
If($OU -eq $False)
    # These are parameters that you would require if you're not using AD
    $param = New-Object PSObject
    $param | add-member NoteProperty Name 'Computer'
    $param | add-member NoteProperty Value ([ADSI]:WinNT://$env:ComputerName").name
    $param | add-member NoteProperty Prompt 'The computer you want to run the script against.'
    $ScriptParameters += $param

In order for your script to be properly displayed in the framework you will need to define at least the description outside of a ScriptBlock:

$ScriptDescription = "Do something to a computer"
$ScriptADSObjectType = 'computer'

Finally you will need to add code to do something when your script is chosen. Your code is defined with a ScriptBlock in PowerShell:
$ScriptBlock =
    function Get-Something($Computer)
        # This would be the code that would execute for you

    If($OU -eq $True)
        # This is the computer name that is returned from the framework
        $script:comp = $[0]

    # Basic error handling
    $ErrorActionPreference = "stop"
    $script:Success = $True

    trap [Exception]
        $script:ErrorMessage = $_.Exception.Message
        $script:Success = $False

    $script:SomethingDone=Get-Something $computer

    # Report back that something happened
    $output = New-Object PSObject
    $output = | add-member NoteProperty Computer $script:comp
    $output = | add-member NoteProperty Success'? $script:Success
    $output = | add-member NoteProperty Message $script:ErrorMessage
    write-output $output

Last edited Sep 21, 2009 at 4:41 PM by jeffpatton, version 8


No comments yet.