调用项目未从计划任务执行

时间:2016-05-20 16:32:49

标签: powershell scheduled-tasks

我想知道是否有人可以指出为什么脚本中的最后一行没有通过我的计划任务运行,该任务在登录时运行并作为系统帐户运行。 当我手动运行时,Line运行

我也尝试过start-process而不是invoke-item

$username = Get-WmiObject -class Win32_ComputerSystem | select-object   -ExpandProperty username 
$username = $username.replace(Domainname\', '')

$FaxClientService = 'printclient'
$FaxClientexec = 'C:\program files (x86)\fax\client\bin\printclient.exe'

$WantFile = "c:\users\'+$username+'\appdata\roaming\fax\client\PrintToFaxUserSettings.xml"
$FileExists = Test-Path $WantFile
If ($FileExists -eq $true)
{
    exit
}

Else
{
    # Insert username into XML
    $xml = new-object XML
    $xml.PreserveWhiteSpace = $true
    $xml.load("C:\temp\faxprinter\PrintToFaxUserSettings.xml")
    $xml.usersettings.username = $username
    $xml.PreserveWhiteSpace = $true
    $xml.save("C:\temp\faxprinter\PrintToFaxUserSettings.xml")
    Start-Sleep -s 10
    $ErrorActionPreference = "SilentlyContinue"
    Stop-Process -processname $FaxClientService -Force
    $ErrorActionPreference = "Stop"
    New-Item c:\users\$username\appdata\roaming\fax -type directory
    New-Item c:\users\$username\appdata\roaming\fax\Client -type directory

    $source = 'c:\temp\faxprinter\PrintToFaxUserSettings.xml'
    $dest = 'c:\users\' + $username + '\appdata\roaming\fax\client\PrintToFaxUserSettings.xml'
    Copy-Item -Force $source $dest
    Start-Sleep -s 30
    Invoke-Item $FaxClientexec
}

1 个答案:

答案 0 :(得分:1)

如果任务

  • 具有登录触发器
  • 访问userprofile
  • 包含互动行动(启动应用程序)

然后它真的听起来像你希望它以public IEnumerable<T> GetTs<T>() where T:A { return containerList.OfType<T>(); } 和&#34运行;只有当用户登录时才会运行&#34;而不是Users