Powershell-Snapin



  • Server
    • FOG Version: 1.4.4
    • OS: debian 9.0.0
    Client
    • Service Version:
    • OS: Windows 7 32bit
    Description

    Hi everybody,

    wrote a powershell snapin which adds a user, sets the workgroup of the client, activated windows license and so on.
    Some questions:

    • I start it with -ExecutionPolicy Bypass -NoProfile -File
      Is there any chance to capture the output of the powershell-Skript and redirect it to a file?
      Tried to add > c:\ps_out.txt which does not work.
    • I created a group, where I added 2 clients. I started the snapin on the group and client1 ran the powershell-commands and client2 did not start to do so. In the Task-Management I still see both clients: client1 says In-Progress (although done and already rebooted) and client2 says Queued, but does nothing (Think I found out why … not it the correct network to find the fog-server).
      Why is client1 still listed in the Active Task-Overview? Is it possibly so, because after the script is run, the client cannot find the fog-server, because it is in a different network with new IP-Adress?

    Thanks for your help
    Rainer



  • Tom has a good point here. I’ve struggled with launching powershell from the FOG Service with the correct privilege level to prevent UAC pop ups you never see. Disabling UAC on a PC and retrying the snapin will can be a good testing step. Windows 7 and Windows 10 treat UAC differently, or so it seems. To get around UAC in Win7. Seach for elevate.cmd and elevate.vbs that came out with Server 2008/Vista. I’ve found that this can successfully elevate a PS script in Win7. I’m still working on Win10.

    if you’re actually getting powershell to start your script, you can also pipe the output to a file using the out-file cmdlet:

    powershell.exe -Executionpolicy Bypass -noprofile -file myscript.ps1 | out-file full [full path to some text file]

    Jim



  • @Sebastian-Roth said in Powershell-Snapin:

    @Tywyn Probably just wrap another script around yours that does the call .\myscript.ps1 > C:\somelogfile.txt… Though I am not a windows guy but this might work.

    Will try. Thanx!


  • Developer

    @Tywyn Probably just wrap another script around yours that does the call .\myscript.ps1 > C:\somelogfile.txt… Though I am not a windows guy but this might work.



  • The script runs and it does what it shall do.
    The only thing is, that I would like to have the output (which is generated by Write-Output statements) redirected to a file.
    When you execute a script from the commandline I usually did a .\myscript.ps1 > C:\somelogfile.txt which worksgood.

    I was wondering, whether this can be done also with the script that runs as a snapin.

    Thanx
    Rainer

    EDIT: The issue, why on client2 the script was not running is solved. client2 was in another network an thus not reachable from the fog server.


  • Senior Developer

    I don’t know what the script looks like, but it’s fully possible there’s another problem causing the script not to write to the file as you’re intending, for example it doesn’t make it to the point where you have the log file being written?

    Typically I like to do a script in lines of:

    1. Define the variables.
    2. Write to log stating we’re about to start the work.
    3. Do the work, redirecting output from the running command to go into the log (both errors and standard)
    4. Write to log state we’re complete with doing the work.
    5. End the script as needed.

    I’d have to see the script to help you a little more, but I don’t think FOG is failing to run the script (as this isn’t what we typically see when people post such threads.) Rather the script IS running, but the expected actions aren’t done in the manner that the Client expects them to be done, such as something waiting for user interaction.


Log in to reply
 

395
Online

39.3k
Users

11.0k
Topics

104.4k
Posts

Looks like your connection to FOG Project was lost, please wait while we try to reconnect.