Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

need to run powershell script in a bat file

$
0
0

I have a ps1 file with the following:

Get-ADUser -Filter * -SearchBase "ou=<HOSPOU>,ou=Domain Users and Groups,dc=<hospdomain>,dc=local" -Properties Description,EmailAddress| Select-Object -Property Name,SamAccountName,Description,EmailAddress|Export-Csv "\\<server>\home2$\information services\IS STAFF\Documentation\AD Info\smcusers.csv";

I have a bat file:

@ECHO OFF
SET ThisScriptsDirectory=%~dp0
SET PowerShellScriptPath=%ThisScriptsDirectory%smcusers.ps1
%windir%\system32\WindowsPowerShell\v1.0\powershell.exe -noexit -command import-module ActiveDirectory "%PowerShellScriptPath%";

But while it launches powershell with the AD module, It apparently cannot read the ps1 file.

I get:

H:\>C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -noexit -command i
mport-module ActiveDirectory "H:\smcusers.ps1";
Import-Module : A positional parameter cannot be found that accepts argument 'H
:\smcusers.ps1'.
At line:1 char:14
+ import-module <<<<  ActiveDirectory H:\smcusers.ps1;
    + CategoryInfo          : InvalidArgument: (:) [Import-Module], ParameterB
   indingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell
   .Commands.ImportModuleCommand

I have tried to modify the parameters 

%windir%\system32\WindowsPowerShell\v1.0\powershell.exe -noexit -command import-module ActiveDirectory -File "%PowerShellScriptPath%";

Still no luck.

I need to be able to run this as a scheduled task.



Karon W


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>