Gestion de "spécial char" dans une string: Invoke-Expression
Bonjour a tous,
je bute depuis plus de 24H sur un truc tout bete mais qui commence a me rendre fou, je m'explique:
J'ai un code fonctionnel qui me permet de lancer une commande via
Citation:
invoke-expression
la chaine de caractere est contituée de plusieurs élément dont un path récupéré dans une clé de registre (parc hétérogene).
Le soucis c'est qu'à présent la chaine contient des espaces et des "(" ce qui semble poser probleme.
J'ai testé pas mal de chose et songe a un systeme d'encodage ou quelques chose comme ça mais si je pouvais éviter cela m'arrangerais vraiment et je suis persuadé que c'est tout a fait réalisable sans mais COMMENT ??
Code fonctionnel:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| $RegValue =get-itemproperty -path registry::"HKEY_LOCAL_MACHINE\SOFTWARE\woot\Creations\DIR";
$Reg =(($RegValue.'0010_REPERTOIRE_CREATIONS')+("\ZIMP\"));
[string]$SourceFilex64 =($Reg+"hpcpu118.cfg ");
[string]$psexec =($Reg+"psexec.exe ");
[string]$Argumentsx64 =($psexec+'/acceptEula -s -e cmd.exe /c copy /Y '+ $SourceFilex64 +'C:\Windows\System32\DriverStore\FileRepository\hpcu118t.inf_amd64_neutral_50868a4c1635292b\ 2>$null');
$list=@($Argumentsx64,$ArgumentsBisx64);
foreach($Todo in $list){
$Command =($psexec+$Todo);
try{
IeX -Command ($Command) -WarningAction SilentlyContinue| Out-Null;
}catch{};
} |
Code avec le chemin posant soucis:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
$RegValue =get-itemproperty -path registry::"HKEY_LOCAL_MACHINE\SOFTWARE\woot\Creations\DIR";
$Reg =(($RegValue.'0010_REPERTOIRE_CREATIONS')+("\ZIMP (Flora - Imprimantes)\"));
[string]$SourceFilex64 =($Reg+"hpcpu118.cfg ");
[string]$psexec =($Reg+"psexec.exe ");
[string]$Argumentsx64 =($psexec+'/acceptEula -s -e cmd.exe /c copy /Y '+ $SourceFilex64 +'C:\Windows\System32\DriverStore\FileRepository\hpcu118t.inf_amd64_neutral_50868a4c1635292b\ 2>$null');
$list=@($Argumentsx64,$ArgumentsBisx64);
foreach($Todo in $list){
$Command =($psexec+$Todo);
try{
IeX -Command ($Command) -WarningAction SilentlyContinue| Out-Null;
}catch{};
} |
Erreur renvoyée:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| The term 'C:\Temp\Srv_020' 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 line:1 char:16
+ C:\Temp\Srv_020 <<<< (creations)psexec.exe /acceptEula -s -e cmd.exe /c copy /Y C:\Temp\Srv_020(creations)hpcpu118.cfg C:\Windows\System32\DriverStore\FileR
epository\hpcu118t.inf_amd64_neutral_50868a4c1635292b\
+ CategoryInfo : ObjectNotFound: (C:\Temp\Srv_020:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
The term 'C:\Temp\Srv_020' 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 line:1 char:16
+ C:\Temp\Srv_020 <<<< (creations)psexec.exe /acceptEula -s -e cmd.exe /c copy /Y C:\Temp\Srv_020(creations)hpcpu118.cfg C:\Windows\System32\spool\drivers\x64
\3\
+ CategoryInfo : ObjectNotFound: (C:\Temp\Srv_020:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException |
Si quelqu'un pouvait m'y aider .. J'aime bie nme prendre la tete sur ce genre de chose mais la j'ai une grosse contrainte de temps et donc sucite votre aide a tous , merci.
PS: la clé renvois ce chemin (au cas ou) :
Citation:
C:\temp\Srv_020(creations)