powershell - 从 Powershell ISE 和 Windows 资源管理器运行脚本的不同行为
问题描述
当我从 Windows 资源管理器和 ISE 运行命令时,为什么我的命令表现不同?
我有一个来自 Test1.ps1 的简单命令(Test1 和 Test2 都在同一个文件夹中)
& ".\Test2.ps1"
当我从 Windows 资源管理器运行它时,会执行脚本 Test2.ps1。但是,当我在 ISE 中运行它时,它不起作用,并且出现以下错误:
& : Die Benennung ".\Test2.ps1" wurde nicht als Name eines Cmdlet、einer Funktion、einer Skriptdatei oder eines ausführbaren Programms erkannt。Überprüfen Sie die Schreibweise des Namens, oder ob der Pfad korrekt ist (sofern enthalten), und wiederholen Sie den Vorgang。在 Zeile:1 Zeichen:3 +& ".\Test2.ps1"
- CategoryInfo : ObjectNotFound: (.\Test2.ps1:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
对不起德国人:它基本上说:“.\Test2.ps1”没有作为 cmdlet、函数、脚本文件或已执行程序的名称找到。检查名称的输入或路径是否正确
解决方案
请检查脚本窗格中显示的工作目录。ISE 通常从您的用户配置文件开始。要么先更改脚本的路径。
Set-Location -Path "C:\ScriptLocation\"
或者在调用脚本时使用完整路径:
& "C:\ScriptLocation\Test2.ps1"
当您从资源管理器运行它时,PowerShell 会在同一个文件夹中启动,这就是它能够找到脚本的原因。
推荐阅读
- php - Flutter / Dart AES-256-CBC从PHP中的加密解密
- django - 如何在 python3 manage.py shell 中以表格形式打印 Django 查询集
- android - Android MediaStore.Files.getContentUri 如何获取应用程序内部的文件夹
- reactjs - 如何修复挂钩依赖数组?
- django - 将项目附加到 wagtail 中的流场
- python - Python Regex 问题将文件系统名称转换为指数
- c# - BadHttpRequestException:由于数据到达太慢,读取请求正文超时。请参阅 ASP.NET 核心 2.2 上的 MinRequestBodyDataRate
- c - 在 C 中使用 while 循环检查两个不同的用户名和密码组合
- google-play - 使用 Azure Pipelines 更新 Play 商店中的私有应用程序
- c - 简单的 C 程序无法编译 - 错误是“动态主可执行文件必须与架构 i386 的 libSystem.dylib 链接”