locked
working with WorkFlows RRS feed

  • Question

  • I am trying to learn about WorkFlows in PowerShell.   I found this code doing a Google search and it works.

    workflow CommvaultReport {
    sequence {
    $server_list = @(get-content C:\temp\machines.txt)
    $results = @()
    ForEach -Parallel ($serverName in $server_list) {
    inlinescript {
    $NewObject01 = new-object PSObject
    $NewObject01 | add-member -membertype NoteProperty -name "Server Name" -Value $using:serverName
    $NewObject01
    }
    }
    }
    }


    CommvaultReport | Export-Csv c:\temp\BackUpReport.csv

    ###############################################################################################



    What I am struggling with is gathering more data and writing it to my file.  


    workflow CommvaultReport {
    sequence {
    $server_list = @(get-content C:\temp\machines.txt)
    $results = @()
               ForEach -Parallel ($serverName in $server_list) {
       inlinescript {
                    $ComputerInfo = Get-WMIObject -class Win32_ComputerSystem -computername $server_list -Property *
                    $computerName = $ComputerInfo.name
                    $computerModel = $ComputerInfo.Model
    }
    }
    }
    }

    CommvaultReport $results | Export-Csv c:\temp\BackUpReport.csv

    This does not work and so far nothing has worked.  How do I get $RESULTS piped to my file and have it show me the data for each machine in machines.txt ?
    Thursday, June 22, 2017 8:27 PM

Answers

  • And to really use workflow technology we would do this which runs the list in parallel by default.

    workflow Get-Report {
    	Get-WMIObject Win32_ComputerSystem -pscomputername $PsComputerName
    }
    $server_list = get-content C:\temp\1.txt
    Get-Report -PSComputerName $server_list| Select-Object Name, Model


    \_(ツ)_/


    • Edited by jrv Thursday, June 22, 2017 10:25 PM
    • Marked as answer by bellmonster Friday, June 23, 2017 2:18 PM
    Thursday, June 22, 2017 10:24 PM

All replies

  • I am close but I still don't get the data I am seeking.

                                    


    cls

    workflow Get-Report {
    sequence {
    $server_list = @(get-content C:\temp\1.txt)
    $results = @()
       ForEach -Parallel ($serverName in $server_list) {
           inlinescript {
                        $ComputerInfo = Get-WMIObject -class Win32_ComputerSystem -computername $ServerName -Property *  
                        $computerName = $ComputerInfo.name
                        $computerModel = $ComputerInfo.Model

                        [PSCustomObject]@{
                        PCName=$computerName
                        'Model'=$computerModel  

                   }  # closes the ps custom opject

    }  # Closes the InlineScript

    } # closes the foreach loop

    } # closes the sequence loop

    } # closes the workflow

    $results

    $results | Get-Report | Export-Csv c:\temp\BackUpReport.csv -NoTypeInformation

    $results has no data.   I have 3 machines in 1.txt but it does not seem to find them.  

    Thursday, June 22, 2017 8:55 PM
  • Rather than trying to guess at how to use PowerShell you need to spend the time learning PowerShell basics.


    \_(ツ)_/

    Thursday, June 22, 2017 10:11 PM
  • Also use the code posting tool:

    workflow Get-Report {
    	$server_list = get-content C:\temp\1.txt
    	ForEach -Parallel ($serverName in $server_list) {
    		inlinescript {
    			Get-WMIObject Win32_ComputerSystem -computername $using:ServerName			
    		}
    	}
    }
    
    Get-Report | Select Name, Model


    \_(ツ)_/

    Thursday, June 22, 2017 10:18 PM
  • This is really all you need:

    workflow Get-Report {
    	$server_list = get-content C:\temp\1.txt
    	ForEach -Parallel ($server in $server_list) {
    		Get-WMIObject Win32_ComputerSystem -pscomputername $server
    	}
    }
    
    Get-Report | Select-Object Name, Model


    \_(ツ)_/

    Thursday, June 22, 2017 10:21 PM
  • And to really use workflow technology we would do this which runs the list in parallel by default.

    workflow Get-Report {
    	Get-WMIObject Win32_ComputerSystem -pscomputername $PsComputerName
    }
    $server_list = get-content C:\temp\1.txt
    Get-Report -PSComputerName $server_list| Select-Object Name, Model


    \_(ツ)_/


    • Edited by jrv Thursday, June 22, 2017 10:25 PM
    • Marked as answer by bellmonster Friday, June 23, 2017 2:18 PM
    Thursday, June 22, 2017 10:24 PM