Doc sourcing script not working

DKADM 0 Reputation points
2025-01-22T16:21:40.3733333+00:00

Hello,

I have a PowerShell 7.4 script saved locally that I need to run with parameters. when I type command.

PS C:\Users\Me>. \Graph_SPO_shared_files1.ps1: File C:\Users\me\PS_Scripts\Graph_SPO_shared_files1.ps1 -Sites "https://MYTENANT.sharepoint.com/sites/DevelopmentTestSite"

I get the error:

.: The term '\Graph_SPO_shared_files1.ps1:' is not recognized as a name of a cmdlet, function, script file, or executable program.

Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

I can confirm the path is correct.

Anyone know why I am receiving this error?

Any help would be appreciated

DKADM

PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,762 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. MotoX80 35,141 Reputation points
    2025-01-22T17:09:15.2966667+00:00

    You have multiple problems.

    You've got the script name in there twice along with ":File" which doesn't belong, and you have "dot space backslash" which won't work. To dot source a script you need to use "dot backslash scriptname". But that won't work either because your current directory is C:\Users\Me and the script appears to be in the PS_Scripts subfolder.

    cd \       # root of c:
    C:\Users\me\PS_Scripts\Graph_SPO_shared_files1.ps1 -Sites "https://MYTENANT.sharepoint.com/sites/DevelopmentTestSite"
    cd C:\Users\me\PS_Scripts\                                   # change to scripts directory. 
    .\Graph_SPO_shared_files1.ps1 -Sites "https://MYTENANT.sharepoint.com/sites/DevelopmentTestSite"
    
    
    

    Like this.

    User's image

    0 comments No comments

  2. Kavya 315 Reputation points
    2025-01-24T08:27:58.0266667+00:00

    Navigate to the directory where the script file resides. For example, if the script is available in C:\Users\Me and the script file name is Graph_SPO_shared_files1.ps1. Run the below cmdlets.

    cd C:\Users\Me
    .\Graph_SPO_shared_files1.ps1 -Sites "https://MYTENANT.sharepoint.com/sites/DevelopmentTestSite"

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.