Link to home
Start Free TrialLog in
Avatar of RichardPWolf
RichardPWolfFlag for United States of America

asked on

Powershell Workflows not displaying anything

Trying to work with workflows in powershell but have run into a snag.

Running Powershell 4.0 on Windows 7 I have created sample workflows. When I go and execute them I get a brief "blip" on my screen as if something is happening (looks like a progression bar) but nothing displays. Even the simple hello world script doesn't work.

Thanks.
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

when you define a workflow i.e.
myfunction.ps1
workflow helloworld {
"Hello World"
}

Open in new window

like a function it will be defined but you have to execute it
.\myfunction.ps1
helloworld

reference: http://blogs.technet.com/b/heyscriptingguy/archive/2012/12/26/powershell-workflows-the-basics.aspx
Avatar of RichardPWolf

ASKER

Which I've done. As I said after executing the workflow nothing is displayed.
Hi, I must admit this is the first time I've ever looked at workflows, but I was able to get the sample working by putting the code into TestPS1.ps1, and executing the script.  This loads the workflow into memory, then you can execute the workflow directly:


PS C:\temp\scripts> .\TestPS1.ps1

PS C:\temp\scripts> helloworld
Hello World

PS C:\temp\scripts>


Have you tried that sequence?  The workflow remains available for that Powershell session.  Closing the ISE and opening a new session results in the workflow not being found.

Rob.
All it does is display the code nothing else.

My results are attached.
ise.docx
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ahhh. That I didn't do. Let me try that.
It works. Yeah. I knew I was doing something wrong. Now I can proceed.

Thank you very much.
VERY, VERY helpful.
No problem. I may look into workflows one day to study the difference between workflows and Invoke-Command in terms of paralleledness (???) and efficiency.  I'm a newbie to that concept, so at first impressions, I can't see where they differ too greatly.

Thanks for the grade.

Rob.
Where I'm looking at using workflows is for my reports that tag about 20 servers. As it stands in a sequential access these reports take about 8+ hours to run. By running in parallel I should be able to dramatically reduce that time. I've tried using the "job" functions of powershell but I've never got them to run.
please read the reference that I gave and look at the parallel item
workflow foreachpsptest {

   param([string[]]$computers)

   foreach –parallel ($computer in $computers){

    sequence {

      Get-WmiObject -Class Win32_ComputerSystem -PSComputerName $computer

      Get-WmiObject –Class Win32_OperatingSystem –PSComputerName $computer

      $disks = Get-WmiObject -Class Win32_LogicalDisk `

         -Filter "DriveType = 3" –PSComputerName $computer

     

      foreach -parallel ($disk in $disks){

        sequence {

          $vol = Get-WmiObject -Class Win32_Volume `

          -Filter "DriveLetter = '$($disk.DeviceID)'" `

          –PSComputerName $computer

          Invoke-WmiMethod -Path $($vol.__PATH) -Name DefragAnalysis

        }

      }

    }

   }

}  

foreachpstest  -Computers "server01", "server02", "server03"
Right. I've copied the code to dissect it for my reports. Hope that's alright. This is a long term project as I've got many reports due at the first of the month and I'm trying to script as many as possible (work smarter not harder).

Thanks.