Lors de la convertion du ps1 en EXE (ps2exe), la récupération du chemin du script/exe peut poser probleme
A priori la seule variable qui fonctionne serai
1 |
$PWD |
1 Commentaire
Laisser un commentaire
Cet article n'a pas été revu depuis la publication.
Cet article a été créé par david le 17 janvier 2020.
Salut David,
petit coup de pouce : quand tu utilises l’outil PS2EXE, tu peux utiliser ceci pour déclarer le dossier racine de ton futur PS1 converti en EXE.
if ($MyInvocation.MyCommand.CommandType -eq « ExternalScript »)
{ $ScriptPath = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition }
else
{ $ScriptPath = Split-Path -Parent -Path ([Environment]::GetCommandLineArgs()[0])
if (!$ScriptPath){ $ScriptPath = « . » } }
If (!$ScriptPath){
$FullPathToEXE = [System.Diagnostics.Process]::GetCurrentProcess().MainModule.FileName
$ScriptPath = [System.IO.Path]::GetDirectoryName($FullPathToEXE)
}
https://blog.delacourt.ovh/2019/10/powershell-ps2exe-0500-by-ingo-karstein.html