I'm not able to execute PowerShell script successfully using .bat file provided by input file whereas it succeeds from PowerShell console/ISE
Error: get-content : Cannot find path 'C:\Windows\system32\BulletinIDList.txt' because it does not exist.
it seems script executes in "C:\Windows\system32\' context...how do I force script to look for input file in 'current directory'? please advise..!
Below is script contents to read input from txt file,
$currentFolder = $PWD.Path
You need to use the $MyInvocation.MyCommand.Path to pull the correct directory that your script is running in. When you launch a PowerShell.exe by default it goes to the Path C:\Windows\system32. Your script is pulling that path when your are doing $PWD.Path
$currentFolder = Split-Path -Parent $MyInvocation.MyCommand.Path
You must be logged in to reply to this topic.