以管理员身份登录时无法运行Powershell脚本

时间:2019-06-28 02:40:14

标签: windows powershell

我编写了一个脚本,该脚本应该在登录时运行以更改计算机的IP(用于登台销售点终端)。我以前曾使用过此脚本。现在,对其进行一些更改后,它将无法运行。重新启动终端后,没有任何反应。如果检查任务管理器,则可以看到Powershell.exe正在运行,并且刚刚挂起。 我正在创建的日志文件包含以下两行:

Transcript started, output file is c:\ta_staging\termlogon.log
2019-06-27 22:16:39.121     [INFO]  Checking for marker file
2019-06-27 22:16:39.215     [INFO]  No marker file found. Starting first run.

该脚本应运行并检查标记文件。如果找不到该文件,则应该通过弹出屏幕键盘从用户那里获取站点号。之后,它将根据站点号更改IP。 预定任务通过以下方式调用脚本:C:\Windows\System32\WindowsPowershell\v1.0\powershell.exe -executionpolicy remotesigned -file C:\staging\termlogon.ps1 -verb runas

被卡住的代码是:

if ( $(try { !(Test-Path -Path "$scriptPath\$marker" -PathType Leaf) } catch { $false } ) )
    {
        LogInfo "No marker file found. Starting first run."
        # Get the site number that is being staged.
        # Open the On Screen Keyboard for the tech to enter the information
        Start-Process osk
        [System.Windows.MessageBox]::Show("Please enter the site number.")
        LogInfo "Getting site ID from staging tech."
        $siteid = Read-Host "What is the site number being staged? Note: quick service sites must include '8' in the site number."
        LogInfo "Site ID is $siteid"
    } else {
    # Do Stuff
    }

我不知道为什么它停止工作或如何使其重新工作。有人有什么想法吗? 谢谢

1 个答案:

答案 0 :(得分:0)

因此该解决方案与Powershell脚本无关,但与我安排预定任务的方式有关。我选择了“无论用户是否登录都运行”。一旦将其更改为“仅在用户登录时运行”,所有内容便开始工作。