DarkLite1
DarkLite1

Reputation: 14755

PowerShell shortcut

I'm trying to create a shortcut to run my PowerShell script. This works fine but not when it needs to load the Active directory module. I've searched everywhere, but couldn't find an answer. When adding the line 'import-module' it doesn't work anymore:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noexit -command import-module ActiveDirectory "& 'C:\MyScript.ps1' "

Thank you for your help.

Upvotes: 0

Views: 1463

Answers (2)

Michał Pawlak
Michał Pawlak

Reputation: 106

If you always want use ActiveDirectory you can put import-module ActiveDirectory command in your $profile file.

Upvotes: 0

Joey
Joey

Reputation: 354834

You're missing a semicolon. At the moment you're trying to execute the literal line

import-module ActiveDirectory & 'C:\MyScript.ps1'

which makes no sense if you try it interactively. It makes no more sense from the command line.

Try

-Command "&{Import-Module ActiveDirectory; & 'C:\MyScript.ps1'}"

instead.

Upvotes: 2

Related Questions