Question
Start-Job with Credential
- smadon
- Auteur du sujet
- Hors Ligne
- Membre junior
-
Réduire
Plus d'informations
- Messages : 20
- Remerciements reçus 0
il y a 13 ans 2 mois #14247
par smadon
Start-Job with Credential a été créé par smadon
Hello,
Je rencontre un problème avec start-job que je voudrais lancer avec un credential car je voudrais modifier une clé de registre.
Mais quand je lance mon script, je reçois un message : \"Directory Invalid\"
Je ne comprends pas ou est l'erreur.
[code:1]
$Username = \"Admin\"
$Password = \"MyPassword\"
$global:Credential = New-Object System.Management.Automation.PSCredential -ArgumentList @($Username,(ConvertTo-SecureString -String $Password -AsPlainText -Force))
$RegKey = \"HKLM:\Software\MySoft\MySoft\Reps\1\"
$GoodRep = \"http://MYSERVER/Rep.xml\"
# Read the Registry
$Rep = Get-ItemProperty -path $RegKey
# If not the Good Rep, we write the good name
if (!($Rep.repository -eq $GoodRep))
{
Write-Output \"Rep not Correct, we change it.\"
$MyScript = { param ( $RegKey, $GoodRep)
Write-Output $Credential
Write-Output $RegKey
Set-ItemProperty -path $RegKey -name repository -value $GoodRep
}
$Job = Start-Job -ScriptBlock $MyScript -ArgumentList $Arguments -Credential $Credential
Wait-Job $Job
Receive-Job $job
}
[/code:1]
Le Message d'Erreur :
[code:1]
D:\>MyProg.exe
Rep not Correct, we change it.
WARNING: column \"Command\" does not fit into the display and was removed.
Id Name State HasMoreData Location
-- ----
1 Job1 Failed False localhost
Receive-Job : [localhost] There is an error launching the background process. E
rror reported: The directory name is invalid.
At D:\Users\user\AppData\Local\Temp\Quest Software\PowerGUI\XXXXX\RunMyProg.ps1:68 char:14
+ Receive-Job <<<< $job
+ CategoryInfo : OpenError: (:«») [Receive-Job], PSRemotingTransportException
+ FullyQualifiedErrorId : PSSessionStateBroken
[/code:1]
D'avance merci pour votre aide
Damien
Je rencontre un problème avec start-job que je voudrais lancer avec un credential car je voudrais modifier une clé de registre.
Mais quand je lance mon script, je reçois un message : \"Directory Invalid\"
Je ne comprends pas ou est l'erreur.
[code:1]
$Username = \"Admin\"
$Password = \"MyPassword\"
$global:Credential = New-Object System.Management.Automation.PSCredential -ArgumentList @($Username,(ConvertTo-SecureString -String $Password -AsPlainText -Force))
$RegKey = \"HKLM:\Software\MySoft\MySoft\Reps\1\"
$GoodRep = \"http://MYSERVER/Rep.xml\"
# Read the Registry
$Rep = Get-ItemProperty -path $RegKey
# If not the Good Rep, we write the good name
if (!($Rep.repository -eq $GoodRep))
{
Write-Output \"Rep not Correct, we change it.\"
$MyScript = { param ( $RegKey, $GoodRep)
Write-Output $Credential
Write-Output $RegKey
Set-ItemProperty -path $RegKey -name repository -value $GoodRep
}
$Job = Start-Job -ScriptBlock $MyScript -ArgumentList $Arguments -Credential $Credential
Wait-Job $Job
Receive-Job $job
}
[/code:1]
Le Message d'Erreur :
[code:1]
D:\>MyProg.exe
Rep not Correct, we change it.
WARNING: column \"Command\" does not fit into the display and was removed.
Id Name State HasMoreData Location
-- ----
1 Job1 Failed False localhost
Receive-Job : [localhost] There is an error launching the background process. E
rror reported: The directory name is invalid.
At D:\Users\user\AppData\Local\Temp\Quest Software\PowerGUI\XXXXX\RunMyProg.ps1:68 char:14
+ Receive-Job <<<< $job
+ CategoryInfo : OpenError: (:«») [Receive-Job], PSRemotingTransportException
+ FullyQualifiedErrorId : PSSessionStateBroken
[/code:1]
D'avance merci pour votre aide
Damien
Connexion ou Créer un compte pour participer à la conversation.
- Arnaud Petitjean
-
- Hors Ligne
- Modérateur
-
il y a 13 ans 2 mois #14260
par Arnaud Petitjean
MVP PowerShell et créateur de ce magnifique forum
Auteur de 6 livres PowerShell aux éditions ENI
Fondateur de la société Start-Scripting
Besoin d'une formation PowerShell ?
Réponse de Arnaud Petitjean sur le sujet Re:Start-Job with Credential
Bonjour Damien,
Je ne vois pas à quel moment tu passes tes arguments :
[code:1]$Job = Start-Job -ScriptBlock $MyScript -ArgumentList $Arguments -Credential $Credential[/code:1]
Autrement dit ta variable $Arguments n'est pas définie dans ton script.
Est-ce que tu récupères bien des valeurs lorsque dans ton scriptblock sont executés les 2 Write-Output ?
Arnaud
Je ne vois pas à quel moment tu passes tes arguments :
[code:1]$Job = Start-Job -ScriptBlock $MyScript -ArgumentList $Arguments -Credential $Credential[/code:1]
Autrement dit ta variable $Arguments n'est pas définie dans ton script.
Est-ce que tu récupères bien des valeurs lorsque dans ton scriptblock sont executés les 2 Write-Output ?
Arnaud
MVP PowerShell et créateur de ce magnifique forum
Auteur de 6 livres PowerShell aux éditions ENI
Fondateur de la société Start-Scripting
Besoin d'une formation PowerShell ?
Connexion ou Créer un compte pour participer à la conversation.
Temps de génération de la page : 0.041 secondes
- Vous êtes ici :
-
Accueil
-
forum
-
PowerShell
-
Entraide pour les débutants
- Start-Job with Credential