Run PowerShell ISE from the command line?

Calvin Li picture Calvin Li · Jul 19, 2014 · Viewed 12.2k times · Source

So I have a script that works fine when I run it from PowerShell ISE. However, I need to automate it, so I run powershell.exe .\script.ps1, but I get errors about some of the commands not being recognized (they are from a non-standard module).

Any help is appreciated, thanks!

Answer

Frode F. picture Frode F. · Jul 19, 2014

Edit the beginning of your script to import all dependencies(modules). This is good practice as it makes the code more readable and works with both PS 2.0 an 3.0+

script.ps1

#Import example module
Import-Module ActiveDirectory

#Script start
$name = Read-Host "Username"
$user = Get-ADUser $name
.....