We help IT Professionals succeed at work.

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.
Comment
Watch Question

Distinguished Expert 2019

Commented:
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

Author

Commented:
Which I've done. As I said after executing the workflow nothing is displayed.
Most Valuable Expert 2012
Top Expert 2014

Commented:
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.
Distinguished Expert 2019

Commented:
http://www.screencast.com/t/9GNVakqFJwk  you can't duplicate this?

Author

Commented:
All it does is display the code nothing else.

My results are attached.
ise.docx
Most Valuable Expert 2012
Top Expert 2014
Commented:
Running the code only loads the HelloWorld workflow into memory. You need to execute HelloWorld at the command line after you run the code.

Author

Commented:
Ahhh. That I didn't do. Let me try that.

Author

Commented:
It works. Yeah. I knew I was doing something wrong. Now I can proceed.

Thank you very much.

Author

Commented:
VERY, VERY helpful.
Most Valuable Expert 2012
Top Expert 2014

Commented:
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.

Author

Commented:
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.
Distinguished Expert 2019

Commented:
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"

Author

Commented:
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.