Running PowerShell from RunOnce

This topic contains 0 replies, has 1 voice, and was last updated by  Forums Archives 5 years, 11 months ago.

  • Author
    Posts
  • #5280

    by pizzim13 at 2012-11-14 16:45:14

    I am trying to run a set of powershell commands during a template customization. These commands are injected into the RunOnce in the registry.

    %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -command &{Add-Type -Assembly System.Web; [Web.Security.Membership]::GeneratePassword(21,7) | Select-Object @{N="Group";E={"Test Group"}}, @{N="Username";E={"TestUser"}}, @{N="Password";E={$_}} | Export-Csv -Path C:\stuff\user.csv -NoTypeInformation}
    I know that these commands work, as I can run them in a powershell console. I know that "%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -command &{PSCODE}" is correct because other runonce commands will run correctly. I cannot figure out what part of my syntax is failing.

    by DonJ at 2012-11-15 04:04:53

    Are you getting any kind of error? Have you tried putting all of this into a .PS1 file, and executing that instead of embedding the entire command in the registry? This may also be a matter of context – when RunOnce executes, the system isn't necessarily 100% up and running, and the user environment isn't necessarily 100% built, yet.

    by pizzim13 at 2012-11-15 12:09:56

    No errors. The console would not open either. Running these commands from a script file via the runonce does work. I cant explain it.

You must be logged in to reply to this topic.