Author Posts

August 18, 2015 at 10:11 pm

Hi All,

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\' 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
$GetBulletins = Join-Path $currentFolder "BulletinIDList.txt"
$BulletinIDList = get-content $GetBulletins



August 18, 2015 at 11:45 pm

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
Replace the following to pull the current location of the script.

$currentFolder = Split-Path -Parent $MyInvocation.MyCommand.Path