VBS calling Powershell calling cscript


  • Backstory: I am responsible for an SCCM task sequence that runs on stand-alone media to rebuild computers while they are "away from home," i.e., no network connectivity to the domains their computer objects were originally created in.

    Since this is going to be occuring in an SCCM task sequence, everything will be running in system context...

    One of the tasks that must be carried out is applying gpos. I am using an MS tool "localgpo.wsf" which is a compiled (I think) cscript.

    I need to call the powershell script from the vbs with parameters that represent directories. Let's say directories A, B, and C.

    Then... the call for localgpos.wsf looks like this: "cscript localgpo.wsf /path:<insert path here>

    So this is what I have, thus far, for the powershell script:

    $strFolder = $args[0]}

    foreach ($i in get-childitem $strFolder | where {$_.PsIsContainer}) {start-process cscript localgpo.swf /path:$i.fullname}

    Now... that doesn't work. (Raw noob at powershell scripts... I'm sure the SME's are lol'ing about now.) I guess I should say it's working right up to when I added the start-process... THIS works:

    foreach ($i in get-childitem $strFolder | where {$_.PsIsContainer}) {$i.fullname}

    It returns the folders I need as parameters for running localgpo.swf.

    Does the start-process need to look something like this:

    {start-process "cscript localgpo.swf /path:" & $i.fullname} ? (Probably not... probably some other syntax... but... fully blown noob at work here.)

    TIA for all responses!


    • Edited by Lang Murphy Thursday, March 29, 2012 10:10 PM
    Thursday, March 29, 2012 5:38 AM

All replies

  • okay... I'm kinda getting there on my own... the problem I have right now is that the directory names have curly braces at begining and end and it looks like powershell is not treating them as characters, but as delimiters.

    BTW... how does one get paragraph breaks in these posts?

    So... if the directory is named {A}

    And I do something like:

    $a = "localgpo.wsf /path:c:\gpobackups\"

    $b = "{A}"

    $c = $a, $b

    -join $c

    start-process cscript -ArgumentList $c

    the code runs, without error, but it's lopping off the {A} and localgpo.wsf tries to apply a gpo from the path c:\gpobackups, which, of course, ain't what I'm trying to do.

    Friday, March 30, 2012 6:10 PM