Announcement

Collapse
No announcement yet.

Running Powershell Script from inside Setup Factory

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Running Powershell Script from inside Setup Factory

    Hi All,
    Is it possible to run a powershell script from within Setup Factory?
    Thanks,
    John

  • #2
    Sure, check the documentation and see how you can pass a script to Powershell.exe as the argument, then perform the action with File.Run().

    Ulrich

    Comment


    • #3
      Hi there,
      I've tried to run powershell from inside Setup Factory but I get a script error (with no error stored in Application.GetLastError()) when I try to run it.
      My setup factory code is
      success1 = File.Run("C:\Windows\System32\WindowsPowerShell\v1 .0\powershell.exe","C:\Docs\Latest\Work\2022\01-January\Test1.ps1","C:\Docs\Latest\Work\2022\01-January",SW_SHOWNORMAL,false);

      If I run (from a CMD command line) C:\Windows\System32\WindowsPowerShell\v1 .0\powershell.exe C:\Docs\Latest\Work\2022\01-January\Test1.ps1 it works perfectly (the Test1.ps just writes some output to a file using:
      Get-ChildItem "C:\Windows\System32" | Out-File "C:\Docs\Latest\Work\2022\Test.txt"
      )

      What am I doing wrong? The powershell command works fine when not run from Setup factory, but seemingly not from within.
      Thanks in advance,
      John






      Comment


      • #4
        Without seeing the actual code, it is impossible to say for sure what you are doing wrong, but just looking at the text you pasted, it appears as there are many missing backslashes.

        Ulrich

        Comment


        • #5
          Thank you, it was indeed missing backslashes!
          Thanks again,
          John

          Comment

          Working...
          X