【发布时间】: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