- This topic has 6 replies, 4 voices, and was last updated 10 months, 4 weeks ago by
March 1, 2020 at 7:23 pm #207012
I have just started packaging my scripts into EXE files from which smaller utilities which I then put in our remote connection ‘toolbox’ so our technicians can run these scripts on remote computers.
One issue I noticed is that I can’t create scripts with Get-ADUser, convert them to an EXE file and then have that script run when I launch the EXE on a server.
As a test, I confirmed the following ps1 file with this command into an EXE file:
Get-ADComputer -Filter * | select name | Export-Csv C:\utility\inventorytest.csv -NoTypeInformation
This command runs fine from the server (I am logged in as Domain admin) and creates the obvious csv file. However, when I convert to an EXE file, it will not run create the file (still logged in as domain admin).
I ran the exe directly from the command prompt and it is flagging the ‘get-adcomputer’ as unrecognised. I added ‘import-module activedirectory’ but I receive the same error.
Is what I want to do possible? I would before an EXE file that our technicians can just launch rather than copy and pasting a PS script to a server.
`C:\Users\Administrator\Documents\TechPro Control\Temp>Test-inventory.exe</code><br /><code>ERROR: import-module : The 'C:\Windows\system32\WindowsPowerShell\v1.0\Modules\activedirectory\activedirectory.psd1' module cannot</code><br /><code>ERROR: be imported because its manifest contains one or more members that are not valid. The valid manifest members are ('ModuleToP</code><br /><code>ERROR: rocess', 'NestedModules', 'GUID', 'Author', 'CompanyName', 'Copyright', 'ModuleVersion', 'Description', 'PowerShellVersion',</code><br /><code>ERROR: 'PowerShellHostName', 'PowerShellHostVersion', 'CLRVersion', 'DotNetFrameworkVersion', 'ProcessorArchitecture', 'RequiredMo</code><br /><code>ERROR: dules', 'TypesToProcess', 'FormatsToProcess', 'ScriptsToProcess', 'PrivateData', 'RequiredAssemblies', 'ModuleList', 'FileLi</code><br /><code>ERROR: st', 'FunctionsToExport', 'VariablesToExport', 'AliasesToExport', 'CmdletsToExport'). Remove the members that are not valid</code><br /><code>ERROR: ('HelpInfoUri'), then try to import the module again.</code><br /><code>ERROR:</code><br /><code>ERROR: At line:7 char:14</code><br /><code>ERROR: + import-module <<<< activedirectory</code><br /><code>ERROR: + CategoryInfo : InvalidData: (C:\Windows\syst...edirectory.psd1:String) [Import-Module], InvalidOperationExce</code><br /><code>ERROR: ption</code><br /><code>ERROR: + FullyQualifiedErrorId : Modules_InvalidManifestMember,Microsoft.PowerShell.Commands.ImportModuleCommand</code><br /><code>ERROR:</code><br /><code>ERROR: Get-ADComputer : The term 'Get-ADComputer' is not recognized as the name of a cmdlet, function, script file, or operable pro</code><br /><code>ERROR: gram. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.</code><br /><code>ERROR:</code><br /><code>ERROR: At line:8 char:15</code><br /><code>ERROR: + Get-ADComputer <<<< -Filter * | select name | Export-Csv C:\utility\inventorytest.csv -NoTypeInformation</code><br /><code>ERROR: + CategoryInfo : ObjectNotFound: (Get-ADComputer:String) , CommandNotFoundException</code><br /><code>ERROR: + FullyQualifiedErrorId : CommandNotFoundException</code></p><p><code> `
- This topic was modified 10 months, 4 weeks ago by Brian Clanton.
March 2, 2020 at 5:10 pm #207252ParticipantTopics: 10Replies: 204Points: 1,001Rank: Community Hero
One question I would have is the method you chose for converting to an EXE? I use ISESteroids, converted your sample code and it ran just fine as an EXE.
March 2, 2020 at 6:20 pm #207297ParticipantTopics: 17Replies: 1956Points: 4,010Rank: Community Hero
Looks like the cause is Powershell is running as version 2.0 which most likely defined in the EXE wrapper. Are there settings to manipulate the Powershell session for the EXE?
March 2, 2020 at 6:24 pm #207303
March 2, 2020 at 11:22 pm #207384
March 2, 2020 at 11:23 pm #207387
I did choose V2 by default since this might have to run on older version of Windows servers…it failed on Windows 2008 R2 server.
March 2, 2020 at 11:33 pm #207390ParticipantTopics: 10Replies: 204Points: 1,001Rank: Community Hero
I ran into a similar issue as I needed to run some converted scripts on XP (dont laugh). I worked with the vendor of the tool I was using (ISESteroids) to eventually get it done. I had to go back to a much older version of the conversion tool. I would think you will need to contact PowerShell Studio to get it done.
- The topic ‘Generate EXE files from ps1’ is closed to new replies.