【问题标题】:Task scheduler to execute powershell script does not get response to webRequest执行powershell脚本的任务调度程序没有得到对webRequest的响应
【发布时间】:2018-10-24 06:28:44
【问题描述】:

我有以下代码的 Powershell 脚本

$instance_id=(Invoke-WebRequest -URI http://169.254.169.254/latest/meta-data/instance-id)
    Write $_ "webrequest command output = " $instance_id >> C:/auto_register.log
    $instance_id=$instance_id.Content        
    Write "instance_id is " $instance_id >> C:/auto_register.log

文本文件的输出是

webrequest command output = 
instance_id is 

我已设置计划任务以在启动时运行此脚本。当我在 powershell 中手动执行这个脚本时,变量值被设置。但是,当我通过 TaskScheduler 执行此脚本时,它没有设置值。

有人知道为什么吗?

【问题讨论】:

  • “空白结果”是什么意思?一旦设置了这个变量,你在做什么?你回应它吗?把它喂给别的东西?请发帖Minimal, Complete and Verifiable Example
  • @acro444 感谢您的回复。我已经更新了我的问题。只有当我通过 Windows 中的任务调度程序执行 ps1 文件时,似乎变量才被取消。
  • 我猜这是一个与这个问题类似的问题:stackoverflow.com/q/50258933/478656,类似的解决方法可能会有所帮助。即使从未发现确切的问题。

标签: powershell amazon-ec2 scheduled-tasks aws-sdk taskscheduler


【解决方案1】:

“-UseBasicParsing”参数对无法登录的帐户就像一个魅力。我已使用以下链接作为参考。

https://powershell.org/forums/topic/powershell-scripts-with-task-scheduler-failing/

【讨论】:

  • 欢迎来到 SO!。除了链接之外,请分享链接上的内容摘要
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-18
  • 2019-09-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多