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!
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
.....