none
Workflows than run a function passed as parameter RRS feed

  • Question

  • Hello! I'm making an installation script that calls a list of functions to install each product:

        InstallSqlServer
        InstallVisualStudio "2013" "\\fileserver1\File Storage\07 Software\COMPUTER INSTALLATION\en_visual_studio_premium_2013_x86_dvd_3009258.iso"         
        InstallTfs2012PowerTools   
    ...   

    Those are functions that contain the required code to install each product.

    The problem is that some products require a restart before trying to install them or they will fail, so... I thought of a "workflow" that reboots the system when it's required.

    That workflow should:

    1. Accept a function as a parameter
    2. Check it a reboot is required (I have a function that retrieves the information)
    3. Invoke the function passed as parameter (that could have parameters as well! like the InstallVisualStudio function.

    In pseudo-code it would be:

    workflow (function f) 
    {
        if RebootPending 
        {
            Reboot
        }
        
        Invoke f (with its original arguments)
    }
    

    Is it possible to do this?

    Thank you!


    Desde España / From Spain

    Thursday, May 22, 2014 9:14 AM

Answers

  • Thanks for your response.

    You say that some command line option makes it restart the machine if needed. The problem with that is that it breaks the execution of the script, and that is a major drawback. That's why I though about workspaces. I'm very new to PowerShell, sorry.

    Is there any way to surpass this problem and make the script run without breaking in the middle?


    Desde España / From Spain

    No - I said you do not need a function but you need to restart with wait.

    Restart-Computer -PSComputername $computer -wait

    This will wait on the taks until the remote system is up again.  It does not work well against a local system.

    A resume-able workflow on the local system takes more steps to save the state of the workflow so it is resume-able or you can split the workflow and schedule the remainder as a task on startup.  This is trhe easier method if you are not good with PowerShell.


    ¯\_(ツ)_/¯

    Thursday, May 22, 2014 3:30 PM

All replies

  • There is no such thing. and what you are trying to do cannot be done in PowerShell.

    You can place the function "inline" inside the workflow.

    Workflows run in a special namespace and cannot "see" what is in your session.  Variables and functions are not visible and functions cannot be passed.


    ¯\_(ツ)_/¯

    Thursday, May 22, 2014 9:53 AM
  • So, isn't there a good way to make a script that installs products without user interaction and rebooting when necessary? :(

    We need a script that is able to automate the installation of a bunch of applications in silent mode (including Visual Studio and SQL Server) for new users and thought about Power Shell. It would be a really pity that PS cannot handle a situations like this.

    Thank you.


    Desde España / From Spain

    Thursday, May 22, 2014 10:41 AM
  • So, isn't there a good way to make a script that installs products without user interaction and rebooting when necessary? :(

    We need a script that is able to automate the installation of a bunch of applications in silent mode (including Visual Studio and SQL Server) for new users and thought about Power Shell. It would be a really pity that PS cannot handle a situations like this.

    Thank you.


    Desde España / From Spain

    This is all possible but the SQLServer installer has all of that built in.  The installer has commandline arguments that tell the machine to reboot if necessary.  SQS seldom requires a reboot.

    Perhaps you are trying todo something that is unnecessary.

    Why do you think you need a function to reboot a machine?


    ¯\_(ツ)_/¯

    Thursday, May 22, 2014 11:01 AM
  • Thanks for your response.

    You say that some command line option makes it restart the machine if needed. The problem with that is that it breaks the execution of the script, and that is a major drawback. That's why I though about workspaces. I'm very new to PowerShell, sorry.

    Is there any way to surpass this problem and make the script run without breaking in the middle?


    Desde España / From Spain

    Thursday, May 22, 2014 3:21 PM
  • Thanks for your response.

    You say that some command line option makes it restart the machine if needed. The problem with that is that it breaks the execution of the script, and that is a major drawback. That's why I though about workspaces. I'm very new to PowerShell, sorry.

    Is there any way to surpass this problem and make the script run without breaking in the middle?


    Desde España / From Spain

    No - I said you do not need a function but you need to restart with wait.

    Restart-Computer -PSComputername $computer -wait

    This will wait on the taks until the remote system is up again.  It does not work well against a local system.

    A resume-able workflow on the local system takes more steps to save the state of the workflow so it is resume-able or you can split the workflow and schedule the remainder as a task on startup.  This is trhe easier method if you are not good with PowerShell.


    ¯\_(ツ)_/¯

    Thursday, May 22, 2014 3:30 PM
  • Nice, thanks!

    Desde España / From Spain

    Thursday, May 22, 2014 4:08 PM
  • Nice, thanks!

    Desde España / From Spain


    No problem.  I know where you will get stuck next so you will be back just like Arnold.

    ¯\_(ツ)_/¯

    Thursday, May 22, 2014 4:23 PM