Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8975399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:52:12+00:00 2026-06-15T18:52:12+00:00

PowerShell -Command .\Foo.ps1 Foo.ps1 : Function Foo($directory) { echo $directory } if ($args.Length -eq

  • 0
PowerShell -Command .\Foo.ps1
  • Foo.ps1:

    Function Foo($directory)
    {
        echo $directory
    }
    
    if ($args.Length -eq 0)
    {
        echo "Usage: Foo <directory>"
    }
    else
    {
        Foo($args[0])
    }
    

    Despite Foo.ps1 being in the directory from where I am calling Powershell, this results in:

    The term '.\Foo.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program. 
    Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
    
    • EDIT: Wasn’t working because PowerShell was changing directory due to profile.ps1 containing cd C:\

I then tried to call it specifying the full path to the script file, but no matter what I try, I can’t get it to work. I believe I have to quote the path because it contains whitespaces, as does the file name I need to pass in an argument to the script.

  • Best guess so far:

    PowerShell -Command "'C:\Dummy Directory 1\Foo.ps1' 'C:\Dummy Directory 2\File.txt'"
    

    Outputs error:

    Unexpected token 'C:\Dummy Directory 2\File.txt' in expression or statement. 
    At line:1 char:136.
    
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T18:52:13+00:00Added an answer on June 15, 2026 at 6:52 pm

    try this:

    powershell "C:\Dummy Directory 1\Foo.ps1 'C:\Dummy Directory 2\File.txt'"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does PowerShell have an equivalent to this command construct from sh (and derivatives): $
I want to run a PowerShell command (not script) from a cmd.exe and manage
I'm trying to spawn an IE instance remotely via PowerShell. Invoke-Command -computername foo -scriptblock
I'm trying to use the powershell command select-xml to select data from an xml
I have the following powershell command i have converted from VB script: $conn =
I am trying to create a site map with a PowerShell command from this
Calling this powershell command and getting an error. Driving me nuts. Prompt> get-childitem -recurse
How can I save the results from a Powershell command to a MS SQL
I am new to Powershell and having trouble calling a function contained within a
I have a powershell command running when I execute a bat file, The command

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.