简体   繁体   中英

How do I get “hello world” script to run from the command line in powershell?

I can not get pass this error message.

Thanks

The term 'power-date.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 t
hat the path is correct and try again.
At line:1 char:15
+ power-date.ps1 <<<< 
    + CategoryInfo          : ObjectNotFound: (power-date.ps1:String) [], CommandNotFound 
   Exception
    + FullyQualifiedErrorId : CommandNotFoundException

PowerShell will not run scripts in the current directory unless you prefix them with .\\ eg:

.\power-date.ps1

This is a security feature that prevents someone from dropping a script called dir or ls into a directory the hacker can access and that the user is often in. The hacker's intention being that when the user executes dir , the fake dir.ps1 wwould be invoked unknownst to the user. This security feature prevents this sort of attack. If the user wants to invoke the script dir.ps1, they have to explicitly reference it by path eg .\\dir.ps1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM