PowerWF News, Tutorials, and more...

Get the latest tips and tricks directly from the PowerWF development team. Find out about new releases and upcoming features.


Seamless Automation

From the Desktop to the Data Center

The PowerWF family of products are easy enough for desktop and departmental automation, yet powerful and scalable enough for the Data Center. PowerWF compliments Opalis and other RBA solutions, lets you leverage your workforce and preserves your investment as your automation needs grow.


Special - 20% Discount


In conjunction with our recently announced Silver Award from Windows IT Magazine we would like to offer our customers an opportunity to save 20% off any Devfarm product purchase through the end of the year. This includes all PowerWF products as well as Devfarm's new PowerVI product!

PowerVI

vSphere Automation fueled by PowerShell


Designed for the VMware Administrator, PowerVI eases the automation of vSphere infrastructures. PowerVI includes over 100 PowerShell automation scripts that simplify everyday VMware administration tasks and PowerVI makes it easy to author new scripts.
November 25, 2011

How to Export PowerShell Data to XML

I saw a question on StackOverflow the other day asking how to save PowerShell results as XML.  If you are lucky, this could be as simple as using the export-clixml cmdlet.

But what if you are doing something more complex where you are pulling data from multiple sources or you want to control every aspect of the structure of the XML you are creating.  In that case, I think you have 2 options.

The simplest way would be to build up a string as your xml -

$procs = get-Process

$xml = "<xml>`r`n"
foreach($proc in $procs)
{ 
   
$xml += "<process name='" + $proc.Name + "' id='Proc_"+$proc.Id+"'>`r`n"

$xml += "<modules>`r`n" foreach($module in $proc.Modules) { $xml += "<module>" $xml += $module.ModuleName $xml += "</module>`r`n" } $xml += "</modules>`r`n" $xml += "</process>`r`n" } $xml += "</xml>`r`n" $xml | out-File -FilePath c:\temp\proc1.xml

The downside of this approach is that you need to build in you are reinventing the wheel and will therefore be responsible for any error checking and insuring that your final document is well formatted XML.

In many cases, a better way would be to build up your output as psobject/arrays/hashtables/etc.  You can then use the PowerShell cmdlets for additional massaging if necessary and use the export-clixml to output it as XML. That would look something like this -

    $procs = get-Process

    $processObject = @()
    foreach($proc in $procs)
    {
        $procInfo = new-Object PSObject
        $procInfo | add-Member NoteProperty -Name "Process" $proc.Name
        $procInfo | add-Member NoteProperty -Name "ID" $proc.Id
        $moduleInfo = @()  
        foreach($module in $proc.Modules)
        {          
            $moduleInfo += $module.ModuleName
        }  
        $procInfo | add-Member NoteProperty -Name "Module" $moduleInfo
        $processObject += $procInfo
    }

    $processObject | export-Clixml c:\temp\procs.xml



October 21, 2011

PowerSE Version Number

Had a chat on the website today where someone asked -

How do I tell what version of PowerSE I have installed; it doesn’t have a help -> About

It turns out, the way to tell the version of PowerSE is the same way you would tell the version of PowerShell. From the embedded host in PowerSE, type this command:

PS C:> get-host

Name             : PowerSE
Version          : 2.5.3.502
InstanceId       : cfc064c2-0958-41e5-bdd5-f3a35f7dfb98
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : en-US
CurrentUICulture : en-US
PrivateData      : PoshConsole.PoshHostProxy
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace



November 22, 2010

Customer Question - PowerWF and Web Services

Rudi ask…

The install was pretty smooth, yeah. I’ve been tinkering around with it. Uhm..one question, though. Can you tell me more about accessing web services using PowerWF?

Thanks!

Rudi.

Accessing web services is straight forward in both PowerWF and PowerShell. To test it out,

  1. Start PowerWF
  2. Create a new workflow
  3. Click on the Blue PowerShell icon on the toolbar
  4. When the PowerShell editor comes up, click on the Samples button
  5. Enter “Web Service” in the search bar.
  6. Select a PowerShell script that looks interesting – I chose one from the TechNet tab that converts a zip-code to Longitude and Latidude.

Here is the sample I used to test web services:

## Using web services and XML to convert ZIP code to lat lon coordinates
##
## Using web services from NWS to retrieve XML results of ZIP code
## containing the latitude and longitude coordinates, then parse

$zipcode = read-host “Enter your zip code”

$data = new-webserviceProxy -uri http://www.weather.gov/forecasts/xml/DWMLgen/wsdl/ndfdXML.wsdl

$latlon = [xml]$data.latlonlistzipcode($zipcode)

$latlon.dwml.latlonlist

You can of course alter this script in PowerWF, setting the $zipcode to an input parameter for the script, and adding visualization, etc.

The key to this is to use the new-webserviceProxy activity to set up the web service. This can be done in a script block, as was done here, or by directly dragging over the NewWebServiceProxy activity from the PowerShell toolbox and setting the URI. After the web service object is created, the easiest way to access it is using a PowerShell script block.



October 7, 2010

Tutorial: Integration with Service Manager Authoring (SCSM)

Service Manager (SCSM) is a relatively new addition to the System Center suite of products. Service Manager helps automate best practices within an IT organization, especially in cases of incident reporting and problem resolution, change control, and asset lifecycle management. Service Manager is tightly integrated with Operation Manager, Configuration Manager, and Active Directory Domain Services.

Service Manager (SCSM) provides a workflow based authoring tool to handle the logic behind the specific automated actions. PowerWF extends this functionality significantly by allowing users to either create custom toolbox items within the Service Manager authoring tool or to directly create Service Manager management packs. This tutorial discusses how PowerWF can be used to extend the existing Service Manager authoring tool by creating custom toolbox activities.

Topics Discussed

  • Creating a PowerWF Workflow
  • Using the embedded PowerShell Editor
  • Using Auto-Script Creation
  • Creating Input Parameters
  • Creating Service Manager (SCSM) Toolbox Activities
  • Importing and Using Custom Toolbox Activities in Service Manager

See Requirements…

    Procedure

    1. Create a new workflow called “TopCPUProcesses”
      Create new workflow for Service Manager
    2. Type “Process” in the toolbox search window to find the Get-Process activity. As its name suggest, this activity collect information about the processes running on a computer.
      Add an activity to a workflow using search feature
    3. Double-Click the blue PowerShell icon on the getProcess activity to open the PowerShell editor.
    4. Click the Start button to view the output of this activity. The Grid tab shows the complete results in a table format.
      View PowerShell results in editor.
    5. One nice feature of PowerWF is the ability to automatically generate PowerShell script based on user interaction with the Grid pane. Find the CPU column and click the heading to sort the results. Next, while holding down the CTRL key, select a cell in the CPU and Name columns.

      Automatically create PowerShell scripts from user input

      Note: If desired, additional cells can be selected. Be sure to hold down the CTRL key the entire time while selecting columns.

    Read More



    October 1, 2010

    Friday Fun: The XKCD Trouble-shooting Guide

    PowerWF comic strip

    It is probably no surprise to anyone that knows me that I am a huge fan of XKCD. The comic covers the entire tech-geek spectrum, with topics ranging from math and physics to computers and video games.

    In fact, if you open up the PowerWF Studio - Getting Started Guide you will see an XKCD comic prominently displayed on page 7.  You did know we had a Getting Started Guide, didn’t you?

    Anyway, I thought it would be fun to convert Randall Monroe’s cheat sheet into a real PowerWF workflow…


    Tech support cheat sheet

    [link]


    There are several ways to approach this, but I opted to leverage PowerShell and Visual Basic MsgBoxes so I could show off a few PowerWF features.  If you  just want to play with the final version of the workflow, you can download it here.

    But, if you would like to see how to actually create a workflow that makes decisions based on input from the user, I’ll explain what I did below the fold.

    Read More



    August 2, 2010

    Pardon Me, But Are You The Owner Of That Process

    There are times when IT administrators want to find out which processes are running on a machine, and which account is the owner of the process.  This tutorial turns a sample PowerShell script that I stumbled upon into an emailed report that contains this information.

    Topics Discussed

    • Importing a PowerShell Script
    • PowerShell Pipelines
    • PowerShell getWmiObject cmdlet
    • PowerShell forEachObject cmdlet
    • PowerShell selectObject cmdlet
    • PowerShell sortObject cmdlet
    • HTML output
    • Web Browser control
    • Sending results via SMTP

    Procedure

    1. Instead of creating a workflow using the procedure in the previous example, click the down arrow under the New button and select “New Workflow from PowerShell”.

      Create new workflow from PowerShell
    2. PowerWF will now prompt for a workflow name. Name the workflow “ProcessOwnerReport” and click OK.

      Create new workflow from PowerShell
    3. In many cases, a quick search of the web will yields a PowerCLI/PowerShell script to do most of the tasks in a workflow. The following script is one such example:
      Get-WmiObject Win32_Process | ForEach-Object { $ownerraw = $_.GetOwner(); $owner = ‘{0}\{1}’ -f $ownerraw.domain, $ownerraw.user; $_ | Add-Member NoteProperty Owner $owner -PassThru } | Select-Object Name, Owner
      This script looks pretty complex, but once PowerWF interprets it as workflow it will be much easier to understand.
    4. Enter this script in the PowerShell Editor and click OK.

      PowerShell script to find process owner

      NOTE: The PowerShell editor allows users to open and save PowerShell PS1 files, or test PowerShell scripts. Click the Play button if you want to test the PowerShell script or get an idea of what the output will be like.
    5. PowerWF automatically converts the PowerShell script into a PowerWF workflow. Notice that despite the complexity of the original script, it was actually three main PowerShell cmdlets in a pipeline.

      Workflow from PowerShell script

      This workflow could be immediately run to collect the desired data, but for this tutorial we will discuss how PowerWF interpretted the script. The forEach-Object is a special case that will be discussed.

    6. The first command in the original script was “Get-WmiObject Win32_Process”. We can see that this was converted into the “getWmiObject” activity with the classname property set to “Win32_Process”.

      Discussion of get-WMI PowerShell Properties

      In PowerShell, the “|” character is used to connect the output of one cmdlet to the input of another cmdlet.
    7. The second part of the script is a little more complex. PowerShell has multiple versions of “For” loops. Without going into a lot of technical details, suffice to say that from a workflow perspective, the example that we found uses the least friendly version, “forEach-Object”.

      PowerShell foreach-Object PowerShell cmdlet properties

      For the other “For” versions been used, PowerWF creates individual activities for each item. ForEach-Object is a special case that essentially runs an embeded script that is in the “Process” property. In this case the embedded script finds the process owner for each process that is passed into it.
    8. The final command simply selects the Process Name and the Owner that was discovered in the ForEach-Object loop.

      PowerShell select-Object cmdlet properties
    9. At this point, visualization can be added and the script tested. The desired output for this example is an HTML table, so in the toolbox search, type “html”. This will list all HTML related activities. Drag the “ConvertDataToHTML” activity to the workflow Canvas and drop at the bottom of the “pipelineSequence1” activity.

      PowerWF convertDataToHTML activity

      Although the WebBrowser activity can directly convert data to HTML, this activity allows the HTML output to be used as the body of an email.
    10. For a quick visualization the data can be displayed using a web browser. Click the next to the search box to show all activity packs. Drop the webBrowser activity from Visualization into the workflow below the “convertDataToHTML1” activity.

      Add PowerWF WebBrowser activity
    11. Press the Start button in the ribbon bar to run the workflow. In its current state, the workflow finds the processes and the process owners and displays them as an HTML table.

      PowerWF Web Browser output
    12. The results would be more meaningful if the data was sorted based on the process name. Typing “sort” in the search bar finds the “sortObject” PowerShell activity. Drop this in the pipelineSequence below the “selectObject1” activity.

      Add Sort to PowerWF workflow
    13. The sort object requires selecting one or more columns to sort on and the sort order (ascending or descending). Add a sort property of Name.

      PowerWF Sort properties
    14. The “convertDataToHTML” and “WebBrowser” activities can display their output in a number of different styles. Set the Style on the “toHTML1” activity to the Onyx style.

      Changing Web Browser Output appearance

    15. Press the Start button in the ribbon bar to run the workflow. The output is now in a meaningful format with a dark-themed display style.

      Web Browser Output appearance changed
    16. The “WebBrowser” activity can now be deleted and replaced with the “SendMailBySMTP”. This activity can be found by typing “mail” in the search bar. The “SendMailBySMTP” requires slightly more configuration than some other activities. Set the mail server host, user,password and SMTP Port and EnableSSL if necessary.

      Configuring SendMail activity properties
    17. It is also necessary to configure who the email is “To” and “From”, and the “Subject” of the email. Set the “To” email address to the target recipient and the “From” email address as the user whose credentials are used to connect to the mail server. The “Subject” should be set to something meaningful, such as “Process Owner Report”.

      Configuring SendMail activity properties
    18. The final steps are to set the “BodyHTML” property to True to configure the output of the “convertDataToHTML1” activity as the Body of the email. Click on the button next to “Body”. Expand the “convertDataToHTML”1 and select “Output”. This will bind the output from the “convertDataToHTML1” activity to the “Body” of the “sendMailBySMTP1” activity.

      Configure activity binding in PowerWF

      Up to this point PowerWF connected the output from one step in the workflow to the input of the next item in the workflow. The “sendMailBySMTP” activity is a little different because the upstream outputs could be used as the Subject, the Body, or even as a User or Password.
    19. The other improvement that could be made at this point is to change the table heading from “pipelinSequence1” to something more meaningful. This can be done by renaming the pipeline sequence to “ProcessOwnerSummary”

      Renaming a PowerWF activity to change the output table name
    20. Press the Start button in the ribbon bar to run the workflow. If everything is configured correctly, an email with snapshot ages should be sent to the target recipient.

      PowerWF formated email message
    21. Summary

      This tutorial showed how to import a PowerShell script into PowerWF Studio and how the script was converted into a workflow. The PowerShell script chosen finds to process owner for each process running on a system. The script was extended by outputting the result as HTML and emailing it via SMTP.


    July 22, 2010

    Message For You Sir

    I had a customer call in today with an interesting use case that he was having problems with.  Essentially he was using the getWMIObject activity to watch the Microsoft Messaging Queues for Bytes Used.  He wanted to take the result of the WMI query and store it in SCOM along with the values from two registry keys.

    He created a script that got him 90% of the way there, but was struggling with the final data mashup.  His initial workflow looked like this…

    1. Query WMI
      select BytesinJournalQueue from Win32_PerfFormattedData_msmq_MSMQQueue WHERE Name = “Computer Queues”
    2. Save to data set
    3. Read 1st registry value
      HKLM\SOFTWARE\Microsoft\MSMQ\Parameters\MachineCache
      MachineJournalQuota
    4. Save to data set
    5. Read 2nd registry value
      HKLM\SOFTWARE\Microsoft\MSMQ\Parameters\MachineCache
      MachineQuota
    6. Save to data set
    7. See what the data looks like

    The only steps he was missing was using a QueryData activity to turn the three sets of data into a single data table…

    In his case the query to combine the data was:

    Select pipelineSequence1.BytesinJournalQueue, readRegistryKey1.value As JournalQuota, readRegistryKey11.value As MachineQuota From pipelineSequence1, readRegistryKey1, readRegistryKey11

    Then all he needed to do was swap out the webBrowser activity with a toSCOM activity and publish it to System Center using the wizard.  After he walked through the wizard, he added a rule to Operations Manager to compare the values and alert if the WMI Query value was larger than either of the registry values.



    July 12, 2010

    Nothing Attracts A Crowd Like A Crowd

    If someone is standing around talking to themselves, you’ll probably ignore them and move along. If you see people milling around in a group listening to someone, the natural reaction is to stop and see what’s going on.

    Twitter is a social setting much like any other social setting - reach out and make a few friends, and soon you will get introduced to more friends.  This tutorial will show how PowerWF can help you with the first part; reaching out to people and making new friends.  In the twitter world this is done by following people with similar interest. 

    You following someone is the same as you stopping to listen to what they say.  They will take notice, especially if you repeat what they said.

    NOTE: This tutorial assumes that the PowerWF Twitter PowerShell Module is installed.

    Break it down

    If we break this down into more of a workflow, it might be something like:

    1. Find people tweeting about topic X
    2. Find out if what they say is useful:
      1. It contains a link
      2. It contains other key words
      3. It is more of significant length
    3. If it is:
      1. Retweet what they said
      2. Follow them

    Download Samples

    To use the following samples, unzip them into your workflow directory and open them with PowerWF.  Be sure to set the Twitter Usernam according to the tutorial instructions below.  You will likely also want to adjust the Twitter Search and QueryData.

    Build the workflow

    Turning this into a PowerWF script is actually pretty straight forward.  We begin with some basic house keeping; creating a workflow and connecting to Twitter.  Then we will follow the steps described above.

    1. Click NEW and create a workflow named “retweetAndFollow”.
    2. From the PowerWF.Twitter Toolbox, drag “ConnectTwitter” on to the canvas.

      PowerWF for Twitter - connect to Twitter

    Read More



     ::: Older Posts :::