如何在使用PowerGUI编译为EXE时引用依赖项PowerShell文件

如何在使用PowerGUI编译为EXE时引用依赖项PowerShell文件,powershell,dependencies,exe,powergui,Powershell,Dependencies,Exe,Powergui,我正在尝试使用该解决方案将两个分开的Powershell文件编译成一个.EXE。 它似乎支持这个特性,因为它甚至有一个按钮,称为依赖项。 但我找不到如何从同一.EXE中包含的任何其他PowerShell文件中引用依赖项文件的任何示例 我的主PS文件仅包含以下行: Start-Process powershell.exe -ArgumentList "-noexit -file C:\PGM\usbControl.ps1" 我想知道如何将“C:\PGM\usbControl.ps1”编码为.EX

我正在尝试使用该解决方案将两个分开的Powershell文件编译成一个.EXE。 它似乎支持这个特性,因为它甚至有一个按钮,称为依赖项。 但我找不到如何从同一.EXE中包含的任何其他PowerShell文件中引用依赖项文件的任何示例

我的主PS文件仅包含以下行:

Start-Process powershell.exe -ArgumentList "-noexit -file C:\PGM\usbControl.ps1"
我想知道如何将“C:\PGM\usbControl.ps1”编码为.EXE包内的相对路径,并指向包含的依赖项


谢谢。

最后,我不必使用任何外部IDE,标准powershell代码实现了这一点。嵌入代码!:)脚本块是关键

$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"
在这个很好的解决方法之后,我只是使用这个工具来编译它

.\ps2exe.ps1  -noConsole -inputFile .\magic.ps1 -outPutFile magic.exe

最后,我不必使用任何外部IDE,标准powershell代码实现了这一点。嵌入代码!:)脚本块是关键

$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"
在这个很好的解决方法之后,我只是使用这个工具来编译它

.\ps2exe.ps1  -noConsole -inputFile .\magic.ps1 -outPutFile magic.exe