Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

PowerShell Script won't load Module/Snap-In when kicked off by scheduling software.

$
0
0

I have a PowerShell script that setups up new AD users based on information from our payroll system.  I want to run it using CRD, which is a scheduling software we use mostly for sending out Crystal Reports.

When I run the script from a PS session, command prompt, or Task Scheduler it works flawlessly.

When I run it from CRD it won't register my SQLTools Module or my Exchange tools snap-in.  I get these errors:

Import-Module : The specified module 'SQLTools' was not loaded because no valid
 module file was found in any module directory.
At C:\PJ_Processes\PowerShell\CreateNewADUsers.ps1:12 char:14+ Import-Module <<<<  SQLTools+ CategoryInfo          : ResourceUnavailable: (SQLTools:String) [Import-M 
   odule], FileNotFoundException+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Comm 
   ands.ImportModuleCommand

Add-PSSnapin : No snap-ins have been registered for Windows PowerShell version 
2.
At C:\PJ_Processes\PowerShell\CreateNewADUsers.ps1:13 char:13
+ Add-PSSnapin <<<<  Microsoft.Exchange.Management.PowerShell.Admin+ CategoryInfo          : InvalidArgument: (Microsoft.Excha...owerShell.Ad 
   min:String) [Add-PSSnapin], PSArgumentException+ FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.Ad 
   dPSSnapinCommand

I can get the module to register by copying the directory to a temporary location and specifying the full path, which suggests a permission issue to me, but when I add Echo "$env:userdomain\$env:username"to the script I can see that it's running under my domain account.

Here is the command I use to call the script:

Path:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

Working Folder:
C:\PJ_Processes\PowerShell

Optional Parameters:
.\CreateNewADUsers.ps1 2>&1 | tee -filePath C:\PJ_Processes\PowerShell\NewUsersLog.txt

I have tried adding "-version 1", "runas /user:", and "-executionpolicy bypass" but I still get the same results.

Is there a permission issue I'm missing here?  Is there a way I can find out why it's failing to register the modules and snap-in?


Viewing all articles
Browse latest Browse all 21975

Trending Articles