I am trying to compile two separated Powershell files into a single .EXE using the solution PowerGUI . It seems to support this feature as it even has a button called Dependencies for that purpose. But I couldn't find any example of how to refer to a dependency file from any other PowerShell file included in the same .EXE
My main PS file only contains the following line:
Start-Process powershell.exe -ArgumentList "-noexit -file C:\PGM\usbControl.ps1"
I would like to know how to encode "C:\PGM\usbControl.ps1" as a relative path inside the .EXE package and point to the dependency included.
Thanks.
Finally I didnt have to use any external IDE, standard powershell code did the trick. Embed code! :) the ScriptBlock was the key.
$sb = {
$query = 'SELECT * FROM __InstanceOperationEvent WITHIN 5 WHERE TargetInstance ISA ''Win32_LogicalDisk'' AND TargetInstance.DriveType=2'
Register-WmiEvent -Query $query -SourceIdentifier RemovableDiskDetection -Action {
$class = $eventArgs.NewEvent.__CLASS
$device = $eventArgs.NewEvent.TargetInstance.DeviceID
$wshell = New-Object -ComObject Wscript.Shell
switch ($class)
{
__InstanceCreationEvent {
$path = $device + '\flag\'
Write-Host '*** Checking the existence of the file $path'
if (Test-Path -Path $path)
{
$wshell.Popup('Inserted, device id: $device WITH flag', 0, 'Done', 0x1)
}
else
{
$wshell.Popup('Inserted, device id: $device WITHOUT flag', 0, 'Done', 0x1)
}
}
__InstanceDeletionEvent {
$wshell.Popup('Removed, device id: $device ', 0, 'Done', 0x1)
}
}
}
}
start-process powershell.exe -argument "-noexit -nologo -noprofile -windowstyle hidden -command $sb"
After this nice workaround, I just used the PS2EXE tool to compile it.
.\ps2exe.ps1 -noConsole -inputFile .\magic.ps1 -outPutFile magic.exe