Quantcast
Channel: System Center 2019, 2016 et 2012 forum
Viewing all articles
Browse latest Browse all 1222

Exécution de script Powershell dans séquence de tâche

$
0
0

Bonsoir,

Je rencontre un problème lors de l’exécution d'un script Powershell durant ma séquence de tache.

Pour exécuter celui-ci j'ai créer un package contenant juste mon script. Ensuite dans ma séquence j'ai ajouté une tâche "Exécuter la ligne de commande" avec la ligne de commande suivante :

powershell.exe -ExecutionPolicy Bypass -file .\info-ad.ps1

J'ai coché l'option "Package" afin de récupérer mon package précédemment créé et j'ai coché "Executer cette étape en tant que compte suivant" afin de spécifier un compte ayant le droit de faire du remoting et de modifier mon AD.

Lors de l’exécution de ma séquence de tâche mon script ne fonctionne pas. Voici ce que me dit le fichier smsts.log :

Import-PSSession : The term 'Import-PSSession' is not recognized as the name 
of a cmdlet, function, script file, or operable program. Check the spelling of 
the name, or if a path was included, verify that the path is correct and try 
again.
At C:\_SMSTaskSequence\Packages\PDL000B5\info-ad.ps1:4 char:1
+ Import-PSSession -session $s -module ActiveDirectory -prefix Rem
+ ~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Import-PSSession:String) [], Co 
   mmandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Get-WmiObject : The term 'Get-WmiObject' is not recognized as the name of a 
cmdlet, function, script file, or operable program. Check the spelling of the 
name, or if a path was included, verify that the path is correct and try again.
At C:\_SMSTaskSequence\Packages\PDL000B5\info-ad.ps1:10 char:17
+ $PrimaryUser = (Get-WmiObject -ComputerName $smsProvider `
+                 ~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Get-WmiObject:String) [], Comma 
   ndNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

gwmi : The term 'Get-WmiObject' is not recognized as the name of a cmdlet, 
function, script file, or operable program. Check the spelling of the name, or 
if a path was included, verify that the path is correct and try again.
At C:\_SMSTaskSequence\Packages\PDL000B5\info-ad.ps1:17 char:16
+ $objComputer = gwmi -computername "$smsProvider" -namespace "root\sms ...
+                ~~~~
    + CategoryInfo          : ObjectNotFound: (Get-WmiObject:String) [], Comma 
   ndNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

gwmi : The term 'Get-WmiObject' is not recognized as the name of a cmdlet, 
function, script file, or operable program. Check the spelling of the name, or 
if a path was included, verify that the path is correct and try again.
At C:\_SMSTaskSequence\Packages\PDL000B5\info-ad.ps1:19 char:23
+ $objMachineSettings = gwmi -computername "$smsProvider" -namespace "r ...
+                       ~~~~
    + CategoryInfo          : ObjectNotFound: (Get-WmiObject:String) [], Comma 
   ndNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

You cannot call a method on a null-valued expression.
At C:\_SMSTaskSequence\Packages\PDL000B5\info-ad.ps1:21 char:1
+ $objMachineSettings.get()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Set-RemADComputer : The term 'Set-RemADComputer' is not recognized as the name 
of a cmdlet, function, script file, or operable program. Check the spelling of 
the name, or if a path was included, verify that the path is correct and try 
again.
At C:\_SMSTaskSequence\Packages\PDL000B5\info-ad.ps1:26 char:1
+ Set-RemADComputer $Computer -Description $PrimaryUser -location $loca ...
+ ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Set-RemADComputer:String) [], C 
   ommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Il semblerait donc qu'il ne trouve pas les cmdlets. Pourtant si je lance manuellement mon script sur le poste cela fonctionne bien...

Merci d'avance pour votre aide.

Bastien

      

Viewing all articles
Browse latest Browse all 1222

Trending Articles



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