How to trigger script using .bat from 'current directory' provided by input file

Welcome Forums General PowerShell Q&A How to trigger script using .bat from 'current directory' provided by input file

This topic contains 1 reply, has 2 voices, and was last updated by

 
Participant
3 years, 9 months ago.

  • Author
    Posts
  • #28737

    Participant
    Topics: 13
    Replies: 11
    Points: 32
    Rank: Member

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

    ——–

    Thanks

  • #28739

    Participant
    Topics: 5
    Replies: 28
    Points: 1
    Rank: Member

    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

The topic ‘How to trigger script using .bat from 'current directory' provided by input file’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort