How to run OSDPowershell Script as users. RRS feed

  • Question

  • I'm creating a message box using powershell to run in OSD Task Sequence for OS upgrade purpose. Since OSD TS run as System my message box did run but it didn't shown on User interface (found in Task Manager OSDPowershell run as system). I have multiple users I could not set it to run as specific users in TS option. Anyone have an idea How to run OSDPowerShell Script using system so user can interact with the message box?

    Here is the script I made:


    #VPNDetectscript will check the AGNAdapter status, If the status is 'Up' it will pop-up a message, cancel button will end the TS and if user no using VPN status is not 'Up' TS will continue.

    $LogFile = "C:\Apps\Win10_1809_ReadinessRemoteAccess.log"
    #$LogFile = "C:\Windows\CCM\Logs\Win10_1809_ReadinessRemoteAccess.log"
    $Date = Date
    $Machinetype = ""
    "Current Date is $Date" | Out-File $LogFile -Append

      #Check Shell Remote Access VPN Connection
    "Start Shell Remote Access VPN connection status validation." | Out-File $LogFile -Append

        $VPNConnStatus = Get-NetAdapter | where InterfaceDescription -eq "AGN Virtual Network Adapter"
        #$VPNConnStatus = Get-NetAdapter -Name "*" -physical | where InterfaceDescription -notlike "*wireless*"
        "AGN Virtual Network Adapter found" | Out-File $LogFile -Append
        If($VPNConnStatus.Status -eq "Up"){
            "Shell Remote Access detected. Notification popup." | Out-File $LogFile -Append
            Add-Type -AssemblyName System.Windows.Forms
            Add-Type -AssemblyName PresentationFramework
            $msgBoxInput =  [System.Windows.MessageBox]::Show('Please READ and AGREE in order to proceed:

    • This can take up to 5-9 hours
    • Ensure your computer is plugged in throughout
    • Ensure your laptop remains powered on and connected to the VPN
    • We suggest you run it outside working hours due to the estimated 45-minute reboot/downtime

    ','You are detected as working on VPN','OkCancel','Information')
    } else {
       Write-Host "0"
      switch  ($msgBoxInput) {

      'Ok' {

      ## Return code 0 to resume the Task Sequence
      Write-Host "0"


      'Cancel' {

      ## Return code -100 to break the Task Sequence
      Write-Host "-100"


    • Edited by izzat117 Thursday, January 30, 2020 6:39 AM
    Thursday, January 30, 2020 3:20 AM

All replies

  • Please DO NOT post colorized code in this forum.

    Edit your original post and fix it after reading the following.

    The code you posted is completely broken and unreadable.


    Thursday, January 30, 2020 3:32 AM
  • thank you
    Thursday, January 30, 2020 6:39 AM
  • Please read the link I posted and follow the instructions. You still have not posted the code correctly so it is readable and can be copied.  Click the link and read the complete document.  It tells you how to post code in these technical forums.


    Thursday, January 30, 2020 9:26 AM