[英]Run PowerShell ISE from the command line?
所以當我從PowerShell ISE運行它時,我有一個可以正常工作的腳本。 但是,我需要自動化它,所以我運行powershell.exe .\\script.ps1
,但是我得到一些未被識別的命令的錯誤(它們來自非標准模塊)。
任何幫助表示贊賞,謝謝!
編輯腳本的開頭以導入所有依賴項(模塊)。 這是一個很好的做法,因為它使代碼更具可讀性,適用於PS 2.0和3.0+
script.ps1
#Import example module
Import-Module ActiveDirectory
#Script start
$name = Read-Host "Username"
$user = Get-ADUser $name
.....
一個原因應該是腳本來源或從您的配置文件腳本加載模塊。 在這種情況下,您的問題可能來自以下事實:從命令行啟動PowerShell並啟動PowerShell ISE不會使用系統相同的配置文件腳本。 看看每個中的$Profile
var並編輯相關文件。
$Profile
ISE上的$Profile
:
C:\Users\JPB\Documents\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps1
在我的命令行上的$Profile
:
C:\Users\JPB\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
更多關於檔案。 About_Profile
一種了解所有$Profile
路徑的方法:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.