【问题标题】:Cannot process argument transformation on parameter 'Principal'. Cannot convert value "" to type "Microsoft.Management.Infrastructure.CimInstance"无法处理参数“Principal”的参数转换。无法将值“”转换为类型“Microsoft.Management.Infrastructure.CimInstance”
【发布时间】:2023-03-29 01:13:01
【问题描述】:

我正在尝试在 Powershell 中创建一个计划任务,该任务将运行使用活动桌面的作业。

1) 我的假设是否正确,即计划任务在运行时可以看到活动桌面?

2) 当我执行以下 poweshell 脚本时,我不断收到错误消息:无法处理参数“Principal”的参数转换。无法将值“Servername”转换为类型“Microsoft.Management.Infrastructure.CimInstance”

代码如下:

import-module PSScheduledjob

$TaskStartTime =  (Get-Date).AddMinutes(2) 
$TaskName = "ExecTestCase"

write-output $TaskStartTime

$action = New-ScheduledTaskAction -Execute "C:\Selenium_Ruby\framework\run_locally_but_update_from_PROD_first.bat"
$trigger = New-ScheduledTaskTrigger -At $TaskStartTime -Once
$principal = "servername\userid"  #assume servername \ userid is in quotes
Register-ScheduledTask BatchRunTask -action $action -principal $principal -trigger $trigger 

怎么了? 有时我也会被拒绝访问计划任务

谢谢

【问题讨论】:

  • $principal = New-ScheduledTaskPrincipal -UserId "servername\userid"?

标签: windows powershell task


【解决方案1】:

参数-principal 不接受string 输入。 参考this documentation

例子:

$STPrin = New-ScheduledTaskPrincipal -GroupId "BUILTIN\Administrators" -RunLevel Highest

【讨论】:

    猜你喜欢
    • 2017-08-22
    • 2014-02-26
    • 2015-01-21
    • 2016-03-21
    • 1970-01-01
    • 1970-01-01
    • 2021-11-22
    • 2016-07-27
    相关资源
    最近更新 更多