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>
<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:</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: ption</code>
<code>ERROR: + FullyQualifiedErrorId : Modules_InvalidManifestMember,Microsoft.PowerShell.Commands.ImportModuleCommand</code>
<code>ERROR:</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:</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>
<code> `