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.
<code>ERROR: import-module : The 'C:\Windows\system32\WindowsPowerShell\v1.0\Modules\activedirectory\activedirectory.psd1' module cannot</code>
<code>ERROR: be imported because its manifest contains one or more members that are not valid. The valid manifest members are ('ModuleToP</code>
<code>ERROR: rocess', 'NestedModules', 'GUID', 'Author', 'CompanyName', 'Copyright', 'ModuleVersion', 'Description', 'PowerShellVersion',</code>
<code>ERROR: 'PowerShellHostName', 'PowerShellHostVersion', 'CLRVersion', 'DotNetFrameworkVersion', 'ProcessorArchitecture', 'RequiredMo</code>
<code>ERROR: dules', 'TypesToProcess', 'FormatsToProcess', 'ScriptsToProcess', 'PrivateData', 'RequiredAssemblies', 'ModuleList', 'FileLi</code>
<code>ERROR: st', 'FunctionsToExport', 'VariablesToExport', 'AliasesToExport', 'CmdletsToExport'). Remove the members that are not valid</code>
<code>ERROR: ('HelpInfoUri'), then try to import the module again.</code>
<code>ERROR: At line:7 char:14</code>
<code>ERROR: + import-module <<<< activedirectory</code>
<code>ERROR: + CategoryInfo : InvalidData: (C:\Windows\syst...edirectory.psd1:String) [Import-Module], InvalidOperationExce</code>
<code>ERROR: + FullyQualifiedErrorId : Modules_InvalidManifestMember,Microsoft.PowerShell.Commands.ImportModuleCommand</code>
<code>ERROR: Get-ADComputer : The term 'Get-ADComputer' is not recognized as the name of a cmdlet, function, script file, or operable pro</code>
<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>
<code>ERROR: At line:8 char:15</code>
<code>ERROR: + Get-ADComputer <<<< -Filter * | select name | Export-Csv C:\utility\inventorytest.csv -NoTypeInformation</code>
<code>ERROR: + CategoryInfo : ObjectNotFound: (Get-ADComputer:String) , CommandNotFoundException</code>
<code>ERROR: + FullyQualifiedErrorId : CommandNotFoundException</code>
- This topic was modified 3 months ago by Brian Clanton.
March 2, 2020 at 5:10 pm #207252ParticipantTopics: 6Replies: 93Points: 428Rank: Contributor
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: 12Replies: 1623Points: 2,565Rank: 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: 6Replies: 93Points: 428Rank: Contributor
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.