0

I have Powershell script that has below code

$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

and output of the text file is

webrequest command output = 
instance_id is 

I have setup scheduled task to run this script on startup. When I execute this script manually in powershell then variable value gets set. However, It doesn't set value when I execute this script through TaskScheduler.

Does anybody know why?

Ashif Nataliya
  • 912
  • 2
  • 13
  • 28
  • What do you mean "blank result"? What are you doing with this variable once it is set? Do you echo it? Feed it to something else? Please post a [Minimal, Complete and Verifiable Example](https://stackoverflow.com/help/mcve) – arco444 May 14 '18 at 15:18
  • @acro444 Thanks for the reply. I have updated my question. It seems variable is unset only when i execute ps1 file through task scheduler in windows. – Ashif Nataliya May 14 '18 at 15:35
  • 1
    I'm going to guess it's a similar problem as this question: https://stackoverflow.com/q/50258933/478656 and a similar workaround might help. Even though the exact problem was never identified. – TessellatingHeckler May 14 '18 at 18:50

1 Answers1

0

“-UseBasicParsing” parameter worked like a charm for a unloginable account. I've used the following link for reference.

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