none
Need to run script as current logged on user RRS feed

  • General discussion

  • I am writing a script that will be deployed through GPO to our users in order to backup certain registry keys.  This will also be setup as a scheduled task to run on an hourly basis.  The problems I am having is with the creation of the scheduled task as the script needs to run as the currently logged on user as it will be writing the output to a .reg file in the user's local app data folder.  When I run the script in PowerShell alone, it works just fine but when I try to run it through a scheduled task, it does not run correctly at all as the file is not being written to the directory we need it to be in.  We also need this to be completely silent to avoid getting helpdesk calls all day about the window popping up.  Any help on this would be greatly appreciated.

    $keys = 'HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Access\User MRU\AD_04D09F0C32180F7DD55CEE6DA2F7EF04AE4BCCED0DA22C1A1D610FDB1D3FF209\File MRU', 'HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Excel\User MRU\AD_04D09F0C32180F7DD55CEE6DA2F7EF04AE4BCCED0DA22C1A1D610FDB1D3FF209\File MRU','HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\OneNote\User MRU\AD_04D09F0C32180F7DD55CEE6DA2F7EF04AE4BCCED0DA22C1A1D610FDB1D3FF209\File MRU','HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\PowerPoint\User MRU\AD_04D09F0C32180F7DD55CEE6DA2F7EF04AE4BCCED0DA22C1A1D610FDB1D3FF209\File MRU'.'HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Publisher\User MRU\AD_04D09F0C32180F7DD55CEE6DA2F7EF04AE4BCCED0DA22C1A1D610FDB1D3FF209\File MRU'.'HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Visio\File MRU','HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Word\User MRU\AD_04D09F0C32180F7DD55CEE6DA2F7EF04AE4BCCED0DA22C1A1D610FDB1D3FF209\File MRU','HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Access\Place MRU\AD_04D09F0C32180F7DD55CEE6DA2F7EF04AE4BCCED0DA22C1A1D610FDB1D3FF209\File MRU', 'HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Excel\Place MRU\AD_04D09F0C32180F7DD55CEE6DA2F7EF04AE4BCCED0DA22C1A1D610FDB1D3FF209\File MRU','HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\OneNote\Place MRU\AD_04D09F0C32180F7DD55CEE6DA2F7EF04AE4BCCED0DA22C1A1D610FDB1D3FF209\File MRU','HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\PowerPoint\Place MRU\AD_04D09F0C32180F7DD55CEE6DA2F7EF04AE4BCCED0DA22C1A1D610FDB1D3FF209\File MRU'.'HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Publisher\Place MRU\AD_04D09F0C32180F7DD55CEE6DA2F7EF04AE4BCCED0DA22C1A1D610FDB1D3FF209\File MRU'.'HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Visio\File MRU','HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Word\Place MRU\AD_04D09F0C32180F7DD55CEE6DA2F7EF04AE4BCCED0DA22C1A1D610FDB1D3FF209\File MRU','HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Excel\File MRU','HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Excel\Place MRU','HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\MS Project\Recent File List','HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\OneNote\RecentNotebooks','HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\PowerPoint\File MRU','HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\PowerPoint\Place MRU','HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Word\File MRU','HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Word\Place MRU','HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\MS Project\User MRU\AD_04D09F0C32180F7DD55CEE6DA2F7EF04AE4BCCED0DA22C1A1D610FDB1D3FF209\File MRU','HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\MS Project\User MRU\AD_04D09F0C32180F7DD55CEE6DA2F7EF04AE4BCCED0DA22C1A1D610FDB1D3FF209\Place MRU'
    
    $tempFolder = "c:\Pacstar Scripts\MRU"
    $Backupfolder = "c:\Pacstar Scripts\Backup"
    $outputFile = "c:\Pacstar Scripts\Backup\Office File MRU and Place MRU.reg"
    
    New-Item -ItemType directory -Path $tempFolder
    New-Item -ItemType directory -Path $env:USERPROFILE\AppData\Local\MRU
    New-Item -ItemType directory -Path "c:\pacstar scripts\Backup"
    
    $keys | % {
      $i++
      & reg export $_ "$tempFolder\$i.reg"
    }
    
    'Windows Registry Editor Version 5.00' | Set-Content -Path $outputFile
    Get-Content "$tempFolder\*.reg" | ? {
      $_ -ne 'Windows Registry Editor Version 5.00'
    } | Add-Content -Path $outputFile
    
    Copy-Item -Path $outputfile -Destination "$env:USERPROFILE\AppData\Local\MRU\Office File MRU and Place MRU.reg"
    Remove-Item -path $tempFolder -recurse
    Remove-Item -path $BackupFolder -recurse



    • Edited by TBingeman Friday, January 18, 2019 12:40 AM
    • Changed type Bill_Stewart Friday, March 15, 2019 6:16 PM
    • Moved by Bill_Stewart Friday, March 15, 2019 6:17 PM Abandoned
    Friday, January 18, 2019 12:39 AM

All replies

  • You can make registry updates directly using the policy preferences registry settings.  They can update any user profile.  Note that a ser cannot update HKLM settings or system settings.

    In most Windows systems a user is likely blocked from creating root folders on the system drive.

    In a user session either use users "temp" folder or a folder in the user profile.

    For a onetime script this seems unnecessary.

    Without some error message or other info there is no way to answer your question.


    \_(ツ)_/

    Friday, January 18, 2019 12:56 AM
  • Set up your scheduled task like the Adobe Update task. To run when the interactive user logs on and then at time intervals. 

    Here is the XML. 

    <?xml version="1.0" encoding="UTF-16"?>
    <Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
      <RegistrationInfo>
        <Author>Adobe Systems Incorporated</Author>
        <Description>This task keeps your Adobe Reader and Acrobat applications up to date with the latest enhancements and security fixes</Description>
        <URI>\Adobe Acrobat Update Task</URI>
      </RegistrationInfo>
      <Principals>
        <Principal id="Author">
          <GroupId>S-1-5-4</GroupId>
        </Principal>
      </Principals>
      <Settings>
        <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
        <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
        <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
        <StartWhenAvailable>true</StartWhenAvailable>
        <IdleSettings>
          <Duration>PT10M</Duration>
          <WaitTimeout>PT1H</WaitTimeout>
          <StopOnIdleEnd>true</StopOnIdleEnd>
          <RestartOnIdle>false</RestartOnIdle>
        </IdleSettings>
      </Settings>
      <Triggers>
        <LogonTrigger id="TriggerUserLoggon">
          <StartBoundary>2013-08-01T12:05:00</StartBoundary>
          <EndBoundary>2027-05-02T08:00:00</EndBoundary>
          <Delay>PT12M</Delay>
          <Repetition>
            <Interval>PT3H30M</Interval>
          </Repetition>
        </LogonTrigger>
        <CalendarTrigger id="TriggerDaily">
          <StartBoundary>2013-01-01T11:00:00</StartBoundary>
          <EndBoundary>2027-05-02T12:05:00</EndBoundary>
          <ScheduleByDay>
            <DaysInterval>1</DaysInterval>
          </ScheduleByDay>
        </CalendarTrigger>
      </Triggers>
      <Actions Context="Author">
        <Exec>
          <Command>C:\Program Files (x86)\Common Files\Adobe\ARM\1.0\AdobeARM.exe</Command>
        </Exec>
      </Actions>
    </Task>

    Friday, January 18, 2019 1:13 AM
  • There were a lot of error in your script.  I think I fixed all of them.

    $keys = @(
        'HKCU\Software\Microsoft\Office\16.0\Access\User MRU\AD_04D09F0C32180F7DD55CEE6DA2F7EF04AE4BCCED0DA22C1A1D610FDB1D3FF209\File MRU',
        'HKCU\Software\Microsoft\Office\16.0\Excel\User MRU\AD_04D09F0C32180F7DD55CEE6DA2F7EF04AE4BCCED0DA22C1A1D610FDB1D3FF209\File MRU',
        'HKCU\Software\Microsoft\Office\16.0\OneNote\User MRU\AD_04D09F0C32180F7DD55CEE6DA2F7EF04AE4BCCED0DA22C1A1D610FDB1D3FF209\File MRU',
        'HKCU\Software\Microsoft\Office\16.0\PowerPoint\User MRU\AD_04D09F0C32180F7DD55CEE6DA2F7EF04AE4BCCED0DA22C1A1D610FDB1D3FF209\File MRU',
        'HKCU\Software\Microsoft\Office\16.0\Publisher\User MRU\AD_04D09F0C32180F7DD55CEE6DA2F7EF04AE4BCCED0DA22C1A1D610FDB1D3FF209\File MRU',
        'HKCU\Software\Microsoft\Office\16.0\Visio\File MRU',
        'HKCU\Software\Microsoft\Office\16.0\Word\User MRU\AD_04D09F0C32180F7DD55CEE6DA2F7EF04AE4BCCED0DA22C1A1D610FDB1D3FF209\File MRU',
        'HKCU\Software\Microsoft\Office\16.0\Access\Place MRU\AD_04D09F0C32180F7DD55CEE6DA2F7EF04AE4BCCED0DA22C1A1D610FDB1D3FF209\File MRU',
        'HKCU\Software\Microsoft\Office\16.0\Excel\Place MRU\AD_04D09F0C32180F7DD55CEE6DA2F7EF04AE4BCCED0DA22C1A1D610FDB1D3FF209\File MRU',
        'HKCU\Software\Microsoft\Office\16.0\OneNote\Place MRU\AD_04D09F0C32180F7DD55CEE6DA2F7EF04AE4BCCED0DA22C1A1D610FDB1D3FF209\File MRU',
        'HKCU\Software\Microsoft\Office\16.0\PowerPoint\Place MRU\AD_04D09F0C32180F7DD55CEE6DA2F7EF04AE4BCCED0DA22C1A1D610FDB1D3FF209\File MRU',
        'HKCU\Software\Microsoft\Office\16.0\Publisher\Place MRU\AD_04D09F0C32180F7DD55CEE6DA2F7EF04AE4BCCED0DA22C1A1D610FDB1D3FF209\File MRU'
        'HKCU\Software\Microsoft\Office\16.0\Visio\File MRU',
        'HKCU\Software\Microsoft\Office\16.0\Word\Place MRU\AD_04D09F0C32180F7DD55CEE6DA2F7EF04AE4BCCED0DA22C1A1D610FDB1D3FF209\File MRU',
        'HKCU\Software\Microsoft\Office\14.0\Excel\File MRU', 'HKCU\Software\Microsoft\Office\14.0\Excel\Place MRU',
        'HKCU\Software\Microsoft\Office\14.0\MS Project\Recent File List',
        'HKCU\Software\Microsoft\Office\14.0\OneNote\RecentNotebooks',
        'HKCU\Software\Microsoft\Office\14.0\PowerPoint\File MRU',
        'HKCU\Software\Microsoft\Office\14.0\PowerPoint\Place MRU',
        'HKCU\Software\Microsoft\Office\14.0\Word\File MRU',
        'HKCU\Software\Microsoft\Office\14.0\Word\Place MRU',
        'HKCU\Software\Microsoft\Office\16.0\MS Project\User MRU\AD_04D09F0C32180F7DD55CEE6DA2F7EF04AE4BCCED0DA22C1A1D610FDB1D3FF209\File MRU',
        'HKCU\Software\Microsoft\Office\16.0\MS Project\User MRU\AD_04D09F0C32180F7DD55CEE6DA2F7EF04AE4BCCED0DA22C1A1D610FDB1D3FF209\Place MRU'
    )
    
    $Backupfolder = Join-Path $env:TEMP 'MRU\Backup' 
    $outputFile = Join-Path $Backupfolder 'Office File MRU and Place MRU.reg'
    
    New-Item -ItemType directory -Path $Backupfolder -Force
     
    'Windows Registry Editor Version 5.00' | Set-Content -Path $outputFile
    $keys |
        ForEach-Object {
            $regfile = Join-Path $Backupfolder temp.reg
            reg export $_ $regfile
            if($LASTEXITCODE){
            }else{
               Write-Host 'Adding next file' -ForegroundColor green
               Get-Content $regfile | select -Skip 1 | Add-Content -Path $outputFile
               Remove-Item $regfile
            }
        }
    
    
    New-Item -ItemType directory -Path $env:USERPROFILE\AppData\Local\MRU -Force
    Copy-Item -Path $outputfile -Destination "$env:USERPROFILE\AppData\Local\MRU\Office File MRU and Place MRU.reg"
    Remove-Item -path $BackupFolder -recurse

    I can't test it with your registry keys because I have a much newer version of Office.



    \_(ツ)_/

    Friday, January 18, 2019 1:29 AM
  • This script is working fine until it is put into a vbs wrapper to keep the PowerShell command window from showing to the user.  Does anyone know a way of keeping the command window hidden while the script is running?
    Monday, January 21, 2019 4:32 PM
  • Run PowerShell with the "WindowStyle" argument.

    powershell /?

    Why would you put this in a VBS wrapper anyway?


    \_(ツ)_/

    Monday, January 21, 2019 5:04 PM
  • Whenever I use the -windowstyle hidden argument, it still ends up displaying the powershell console window and then closing it.  This will prompt our users to put in many helpdesk tickets that are not needed.  By wrapping it in a vbs wrapper, I should be able to get the window to not appear but every time I do the script does not run right.
    Monday, January 21, 2019 5:10 PM
  • I suspect you VScript is causing the window to be displayed. 

    powershell -WindowStyle hidden -File yourfile.ps1

    The "File" parameter must be last on the command line.


    \_(ツ)_/

    Monday, January 21, 2019 5:14 PM
  • Try this: http://www.commandline.co.uk/chp/
    Monday, January 21, 2019 5:28 PM
  • Without the vbs wrapper, is when I see the window pop up when using -windowstyle hidden -file myscript.ps1.
    Monday, January 21, 2019 6:01 PM
  • We must use what comes within the Windows operating system and not 3rd party software.
    Monday, January 21, 2019 6:02 PM
  • We must use what comes within the Windows operating system and not 3rd party software.
    Why?

    -- Bill Stewart [Bill_Stewart]

    Monday, January 21, 2019 6:41 PM
  • This is being told to my by my superiors, i.e. IT Manager, and I was not given an explanation as to why. I suspect it comes down to security and making sure our systems are as secure as possible.
    Monday, January 21, 2019 6:44 PM
  • Post the scheduled task and you script.


    \_(ツ)_/

    Monday, January 21, 2019 7:22 PM
  • This is being told to my by my superiors, i.e. IT Manager, and I was not given an explanation as to why. I suspect it comes down to security and making sure our systems are as secure as possible.

    If PowerShell is being run under a third party software package then you will need to contact the vendor of you package,


    \_(ツ)_/

    Monday, January 21, 2019 7:24 PM
  • Scheduled task

    <?xml version="1.0" encoding="UTF-16"?>
    <Task version="1.3" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
      <RegistrationInfo>
        <Author>PACSTAR\tbingemanadmin</Author>
        <Description>Backup Office MRU registry keys</Description>
        <URI>\Backup Office MRU</URI>
      </RegistrationInfo>
      <Triggers>
        <CalendarTrigger>
          <Repetition>
            <Interval>PT1H</Interval>
            <Duration>P1D</Duration>
            <StopAtDurationEnd>false</StopAtDurationEnd>
          </Repetition>
          <StartBoundary>2019-01-17T08:00:00</StartBoundary>
          <ExecutionTimeLimit>PT30M</ExecutionTimeLimit>
          <Enabled>true</Enabled>
          <ScheduleByDay>
            <DaysInterval>1</DaysInterval>
          </ScheduleByDay>
        </CalendarTrigger>
      </Triggers>
      <Principals>
        <Principal id="Author">
          <UserId>S-1-5-21-841175255-1821442940-924725345-8497</UserId>
          <LogonType>InteractiveToken</LogonType>
          <RunLevel>LeastPrivilege</RunLevel>
        </Principal>
      </Principals>
      <Settings>
        <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
        <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
        <StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
        <AllowHardTerminate>true</AllowHardTerminate>
        <StartWhenAvailable>true</StartWhenAvailable>
        <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
        <IdleSettings>
          <StopOnIdleEnd>false</StopOnIdleEnd>
          <RestartOnIdle>false</RestartOnIdle>
        </IdleSettings>
        <AllowStartOnDemand>true</AllowStartOnDemand>
        <Enabled>true</Enabled>
        <Hidden>true</Hidden>
        <RunOnlyIfIdle>false</RunOnlyIfIdle>
        <DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>
        <UseUnifiedSchedulingEngine>true</UseUnifiedSchedulingEngine>
        <WakeToRun>false</WakeToRun>
        <ExecutionTimeLimit>PT1H</ExecutionTimeLimit>
        <Priority>7</Priority>
        <RestartOnFailure>
          <Interval>PT1M</Interval>
          <Count>3</Count>
        </RestartOnFailure>
      </Settings>
      <Actions Context="Author">
        <Exec>
          <Command>C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe</Command>
          <Arguments>-WindowStyle hidden -File "c:\Pacstar Scripts\MRU_Backup.ps1"</Arguments>
        </Exec>
      </Actions>
    </Task>
    
    

    Script
    $keys = @(
        'HKCU\Software\Microsoft\Office\16.0\Access\User MRU\AD_04D09F0C32180F7DD55CEE6DA2F7EF04AE4BCCED0DA22C1A1D610FDB1D3FF209\File MRU',
        'HKCU\Software\Microsoft\Office\16.0\Excel\User MRU\AD_04D09F0C32180F7DD55CEE6DA2F7EF04AE4BCCED0DA22C1A1D610FDB1D3FF209\File MRU',
        'HKCU\Software\Microsoft\Office\16.0\OneNote\User MRU\AD_04D09F0C32180F7DD55CEE6DA2F7EF04AE4BCCED0DA22C1A1D610FDB1D3FF209\File MRU',
        'HKCU\Software\Microsoft\Office\16.0\PowerPoint\User MRU\AD_04D09F0C32180F7DD55CEE6DA2F7EF04AE4BCCED0DA22C1A1D610FDB1D3FF209\File MRU',
        'HKCU\Software\Microsoft\Office\16.0\Publisher\User MRU\AD_04D09F0C32180F7DD55CEE6DA2F7EF04AE4BCCED0DA22C1A1D610FDB1D3FF209\File MRU',
        'HKCU\Software\Microsoft\Office\16.0\Visio\File MRU',
        'HKCU\Software\Microsoft\Office\16.0\Word\User MRU\AD_04D09F0C32180F7DD55CEE6DA2F7EF04AE4BCCED0DA22C1A1D610FDB1D3FF209\File MRU',
        'HKCU\Software\Microsoft\Office\16.0\Access\Place MRU\AD_04D09F0C32180F7DD55CEE6DA2F7EF04AE4BCCED0DA22C1A1D610FDB1D3FF209\File MRU',
        'HKCU\Software\Microsoft\Office\16.0\Excel\Place MRU\AD_04D09F0C32180F7DD55CEE6DA2F7EF04AE4BCCED0DA22C1A1D610FDB1D3FF209\File MRU',
        'HKCU\Software\Microsoft\Office\16.0\OneNote\Place MRU\AD_04D09F0C32180F7DD55CEE6DA2F7EF04AE4BCCED0DA22C1A1D610FDB1D3FF209\File MRU',
        'HKCU\Software\Microsoft\Office\16.0\PowerPoint\Place MRU\AD_04D09F0C32180F7DD55CEE6DA2F7EF04AE4BCCED0DA22C1A1D610FDB1D3FF209\File MRU',
        'HKCU\Software\Microsoft\Office\16.0\Publisher\Place MRU\AD_04D09F0C32180F7DD55CEE6DA2F7EF04AE4BCCED0DA22C1A1D610FDB1D3FF209\File MRU'
        'HKCU\Software\Microsoft\Office\16.0\Visio\File MRU',
        'HKCU\Software\Microsoft\Office\16.0\Word\Place MRU\AD_04D09F0C32180F7DD55CEE6DA2F7EF04AE4BCCED0DA22C1A1D610FDB1D3FF209\File MRU',
        'HKCU\Software\Microsoft\Office\14.0\Excel\File MRU', 'HKCU\Software\Microsoft\Office\14.0\Excel\Place MRU',
        'HKCU\Software\Microsoft\Office\14.0\MS Project\Recent File List',
        'HKCU\Software\Microsoft\Office\14.0\OneNote\RecentNotebooks',
        'HKCU\Software\Microsoft\Office\14.0\PowerPoint\File MRU',
        'HKCU\Software\Microsoft\Office\14.0\PowerPoint\Place MRU',
        'HKCU\Software\Microsoft\Office\14.0\Word\File MRU',
        'HKCU\Software\Microsoft\Office\14.0\Word\Place MRU',
        'HKCU\Software\Microsoft\Office\16.0\MS Project\User MRU\AD_04D09F0C32180F7DD55CEE6DA2F7EF04AE4BCCED0DA22C1A1D610FDB1D3FF209\File MRU',
        'HKCU\Software\Microsoft\Office\16.0\MS Project\User MRU\AD_04D09F0C32180F7DD55CEE6DA2F7EF04AE4BCCED0DA22C1A1D610FDB1D3FF209\Place MRU'
    )
    
    $Backupfolder = Join-Path $env:TEMP 'MRU\Backup'
    $outputFile = Join-Path $Backupfolder 'Office File MRU and Place MRU.reg'
    
    New-Item -ItemType directory -Path $Backupfolder -Force
     
    'Windows Registry Editor Version 5.00' | Set-Content -Path $outputFile
    $keys |
        ForEach-Object {
            $regfile = Join-Path $Backupfolder temp.reg
            reg export $_ $regfile
            if($LASTEXITCODE){
            }else{
               Write-Host 'Adding next file' -ForegroundColor green
               Get-Content $regfile | select -Skip 1 | Add-Content -Path $outputFile
               Remove-Item $regfile
            }
        }
    
    
    New-Item -ItemType directory -Path $env:USERPROFILE\AppData\Local\MRU -Force
    Copy-Item -Path $outputfile -Destination "$env:USERPROFILE\AppData\Local\MRU\Office File MRU and Place MRU.reg"
    Remove-Item -path $BackupFolder -recurse


    • Edited by TBingeman Monday, January 21, 2019 9:04 PM put code into code blocks
    Monday, January 21, 2019 7:25 PM
  • Please edit your post and post the XML and code correctly using the code posting tool provided.  You post is hard yo read and cannot be easily copied for testing.


    \_(ツ)_/

    Monday, January 21, 2019 8:08 PM
  • I apologize that I did not get the code into code blocks.  It has been a very busy morning here.
    Monday, January 21, 2019 9:05 PM
  • Thank you.  I can now read it easily.  The task looks correct and the code is not capable of over-riding the hidden window.

    What version of PowerShell are you using and what OS version?  PS V2 on older systems would flash a window quickly and, at time it would persist for a bit.


    \_(ツ)_/

    Monday, January 21, 2019 9:13 PM
  • We are using PS version 5.1 on Windows 10 Professional x64
    Monday, January 21, 2019 9:15 PM
  • Then I suggest that a system repair may be required assuming that the only code being executed is what you posted.

    I recommend starting by deleting the task and recreating it from scratch. Sometime a task can get corrupted.  It is also possible that the task folder has become corrupted.  If you search for articles on repairing the scheduled task folder you will find examples.

    I loaded your task.  I changed it to run as W10 task and set it to "run whether the user is logged in or not" and not store password .  After that you exact task works with no flashing window even without the WindowStyle parameter.

    To run when the user logs in correctly set the schedule to run when the user logs in.  This will force it into the users session and it should remain hidden.

    Here is the modified XML.

    <?xml version="1.0" encoding="UTF-16"?>
    <Task version="1.4" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
      <RegistrationInfo>
        <Date>2019-01-21T16:24:35.7295662</Date>
        <Author>PACSTAR\tbingemanadmin</Author>
        <Description>Backup Office MRU registry keys</Description>
        <URI>\TestTask1</URI>
      </RegistrationInfo>
      <Triggers>
        <LogonTrigger>
          <Enabled>true</Enabled>
          <UserId>ALPHA\joneshere</UserId>
        </LogonTrigger>
      </Triggers>
      <Principals>
        <Principal id="Author">
          <UserId>S-1-5-21-9999999-9999999-9999999-1001</UserId>
          <LogonType>S4U</LogonType>
          <RunLevel>LeastPrivilege</RunLevel>
        </Principal>
      </Principals>
      <Settings>
        <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
        <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
        <StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
        <AllowHardTerminate>true</AllowHardTerminate>
        <StartWhenAvailable>true</StartWhenAvailable>
        <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
        <IdleSettings>
          <StopOnIdleEnd>false</StopOnIdleEnd>
          <RestartOnIdle>false</RestartOnIdle>
        </IdleSettings>
        <AllowStartOnDemand>true</AllowStartOnDemand>
        <Enabled>true</Enabled>
        <Hidden>false</Hidden>
        <RunOnlyIfIdle>false</RunOnlyIfIdle>
        <DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>
        <UseUnifiedSchedulingEngine>true</UseUnifiedSchedulingEngine>
        <WakeToRun>false</WakeToRun>
        <ExecutionTimeLimit>PT1H</ExecutionTimeLimit>
        <Priority>7</Priority>
        <RestartOnFailure>
          <Interval>PT1M</Interval>
          <Count>3</Count>
        </RestartOnFailure>
      </Settings>
      <Actions Context="Author">
        <Exec>
          <Command>powershell.exe</Command>
          <Arguments>-File d:\scripts\test.ps1</Arguments>
        </Exec>
      </Actions>
    </Task>


    \_(ツ)_/

    Monday, January 21, 2019 9:42 PM
  • We do have a select few users that are running Windows 7 also and our domain controllers are all 2012 R2.  The GPO settings do not let me state Windows 10 for the deployment of the scheduled task.
    • Edited by TBingeman Monday, January 21, 2019 9:59 PM
    Monday, January 21, 2019 9:54 PM
  • I believe it will work the same using W7 compatibility.

    In any case the issue is NOT a scripting issue but is one of how to use the task scheduler.  To get specific help on scheduler issues post in the correct Windows forum for system services and utilities.


    \_(ツ)_/

    Monday, January 21, 2019 10:08 PM