4 Replies Latest reply on Jul 27, 2016 11:28 AM by phoffmann

    WIndows Actions with minimized Powershell window?

    csoto Specialist

      I'm testing out Windows Actions Distribution Packages. So far, so good, with one minor cosmetic issue - a Powershell window is displayed whenever the package is run. Is there any way to suppress or minimize the window?

       

      Charles

        • 1. Re: WIndows Actions with minimized Powershell window?
          phoffmann SupportEmployee

          Couple of basic questions - not run into this myself, but possible I've not paid attention to:

           

          • What version of LANDesk / service pack are you using? (Just so we're comparing the same version(s)
          • How are you starting the PS Script exactly? <in case there's anything special to be aware of here>

           

          • Are you running it as "the logged on user"? Or as Local System? ... if you're running the PS Script as local system, I'd be quite surprised that the end-post would display anything.
          • You've got the usual options for not showing UI set in the delivery method, right?

           

          ... just asking around a few basics first ... I'll see if I can swing a few sanity tests / have a controlled-run PS-script to play with over the coming week. A bit more detail would be nice though - I've not noticed PS-screens pop up when I deployed my scripts around (but - as mentioned - may not have paid attention for it).

          • 2. Re: WIndows Actions with minimized Powershell window?
            phoffmann SupportEmployee

            OK so ...

             

            I created a little PS script (just to check "Powershell Script Packages" ) that looks like so (yes, it could've been shorter, but I'm trying to keep it on the "easy to understand" side) .

            [string]$LogFilePath = 'C:\xx\PS_Log.txt'
            [string]$LogString = ("I am running as user - " + [System.Security.Principal.WindowsIdentity]::GetCurrent().Name + " - and that matters!")
            [string]$FullLineString = (Get-Date -Format r).ToString() + " :: " + $LogString
            [string]$SleepyTime = (Get-Date -Format r).ToString() + " :: " + "Sleepy time - 5 seconds!"
            [string]$SleepyTimeOver = (Get-Date -Format r).ToString() + " :: " + "I've slept another 5 seconds!"
            
            Out-File -FilePath $LogFilePath -inputobject $SleepyTime -Append
            Write-Host "Going to sleep for 5 seconds now!"
            Start-Sleep -Seconds 5
            Write-Host ("Logging String = " + $FullLineString)
            Out-File -FilePath $LogFilePath -inputobject $FullLineString -Append
            Write-Host "Going to sleep for 5 seconds now!"
            Out-File -FilePath $LogFilePath -inputobject $SleepyTime -Append
            Start-Sleep -Seconds 5
            Write-Host "Sleepy Time is over!"
            Out-File -FilePath $LogFilePath -inputobject $SleepyTimeOver -Append
            Out-File -FilePath $LogFilePath -inputobject "" -Append
            

             

            What the script does:

            1. Writes (to both log & the powershell-screen) that it'll go to sleep for 5 seconds.
            2. Waits/Sleeps for 5 seconds.
            3. Writes to both Host & Log the username context it's running as.
            4. Writes to both Host & Log that it'll sleep for 5 more seconds.
            5. Sleeps/Waits for 5 seconds.
            6. Writes to both Host & Log that it's done sleeping.

             

            Not profound (not meant to be), but takes a while.

             

            Now - I've configured this as a Powershell package & my distribution method has "full UI" enabled, BUT I run the package in the LOCAL SYSTEM context.

            PS_AccountMatters.jpg

             

            Result of which (in the log) looked like so:

            PS_AsPSPackage_Output.jpg

            ... What I "could see":

            • I saw the graphical indicator that "Software is being installed" (expected).
            • I saw no PowerShell window pop up at all (expected, as I ran the script in the LOCAL SYSTEM context).
            • ... so "everything as expected" (even with full client UI options enabled).

             

            Now then - on to duplicating this script as an ACTIONS package... The WAIT/SLEEP stuff had its own actions, the log-entries & write-host commands needed to come as their own "Custom" actions, so hence the multiples of that (I figured I'd "go awkward" and have one item per line, though I Could've happily done multiple lines in a single CUSTOM action). So we look something like this in the end...

            PS_ActionsConfig.jpg

             

            ... and again, the ACTIONS package ran as LOCAL SYSTEM:

            PS_ActionsAccount.jpg

             

            ... with a FULL client UI enabled agent behaviour, I saw the following:

            • I saw the graphical indicator that "Software is being installed" (expected).
            • I saw no PowerShell window pop up at all (expected, as I ran the script in the LOCAL SYSTEM context).
            • ... so "everything as expected" (even with full client UI options enabled).

             

            ... so I suspect that your most likely problem is user context. If you run a powershell script as "the logged on user" I'm not sure you can minimise it as such ... (that'd have to be a PS own thing). Is there a requirement for you to be "in the current user context" specifically?

             

            Much of the "Actions" stuff (stop/start services / copy files / etc.) are system-tasks ... so I'm not sure why you'd need to run as the logged-on user for this. A bit more background on what you're actually trying to do would be helpful .

             

            From a version perspective, I'm running LD 2016 with an alpha SU4 patch (was testing against different issues being fixed), but I think that user-context is going to be the most likely snag here?

            • 3. Re: WIndows Actions with minimized Powershell window?
              csoto Specialist

              I believe you are on the right track with user context. I was trying everything as "logged on user" so it ran in the same context as my winlogon. Thanks!

              • 4. Re: WIndows Actions with minimized Powershell window?
                phoffmann SupportEmployee

                Happy to help.

                 

                User-context is something you want / will have to be PAINFULLY aware of in a software distribution context. Mainly as most users don't (or - shouldn't) have permissions to doing most actually sys-admin related tasks.

                 

                Pretty much the only exception / time when you're wanting to run in a logged-on user context is if you specifically have to hit up something like HKCU based registry keys, or a users' mapped drives or similar settings. Usually you want to avoid "current user" like the plague if at all you can .

                 

                Well - glad to have you on the road again! Happy scripting .