PoshNmap icon indicating copy to clipboard operation
PoshNmap copied to clipboard

Installation Process broken or needs some documentation

Open DanRobinsonHPE opened this issue 4 years ago • 11 comments

PS C:\WINDOWS\system32> Install-Module -Name PoshNmap
PS C:\WINDOWS\system32> Invoke-Nmap
Invoke-Nmap : The term 'Invoke-Nmap' is not recognized as the name of a cmdlet, function, script file, or
operable program. Check the spelling of the name, or if a path was included, verify that the path is correct
and try again.
At line:1 char:1
+ Invoke-Nmap
+ ~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Invoke-Nmap:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

PS C:\WINDOWS\system32>
PS C:\WINDOWS\system32> Get-Host | Select-Object Version

Version
-------
5.1.19041.1320

PS C:\WINDOWS\system32> Get-InstalledModule

Version              Name                                Repository           Description
-------              ----                                ----------           -----------
1.4.3                PackageManagement                   PSGallery            PackageManagement (a.k.a. One...
2.2                  PowerShellGet                       PSGallery            PowerShell module with comman...
1.0.6.19             SnippetPx                           PSGallery            The SnippetPx module enhances...
2.2                  Posh-SSH                            PSGallery            Provide SSH and SCP functiona...
0.6.1                PoshNmap                            PSGallery            A wrapper for NMAP Network Di...

DanRobinsonHPE avatar Dec 06 '21 22:12 DanRobinsonHPE

I see now there is 1 line i missed. "Must have nmap already installed" Would the above error have been caused because I didn't?

DanRobinsonHPE avatar Dec 06 '21 22:12 DanRobinsonHPE

@DanRobinsonHPE confirmed looks like there is an issue on 5.1, it works just fine on Powershell 7, looks to be a packaging issue with the newest version. image

JustinGrote avatar Dec 06 '21 22:12 JustinGrote

In powershell 7.2.2 its not working either:

PS C:\Windows\System32> Install-Module -Name PoshNmap

Untrusted repository You are installing the modules from an untrusted repository. If you trust this repository, change its InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from 'PSGallery'? [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"): A PS C:\Windows\System32> Invoke-Nmap Get-Command: C:\Program Files\WindowsPowerShell\Modules\poshnmap\0.6.1\Private\StartNmap.ps1:8 Line | 8 | $nmapexe = (Get-Command nmap).path | ~~~~~~~~~~~~~~~~ | The term 'nmap' is not recognized as a name of a cmdlet, function, script file, or executable program. | Check the spelling of the name, or if a path was included, verify that the path is correct and try | again.

InvalidOperation: C:\Program Files\WindowsPowerShell\Modules\poshnmap\0.6.1\Private\StartNmap.ps1:9 Line | 9 | & "$nmapexe" $argumentList $computerName | ~~~~~~~~~~ | The expression after '&' in a pipeline element produced an object that was not valid. It must result | in a command name, a script block, or a CommandInfo object.

PS C:\Windows\System32> Get-Host | Select-Object Version

Version

7.2.2

PS C:\Windows\System32> Get-InstalledModule PS C:\Windows\System32>

bust4rhymes avatar Apr 28 '22 15:04 bust4rhymes

@bust4rhymes this module does not install nmap for you, you have to supply it.

JustinGrote avatar Apr 29 '22 01:04 JustinGrote

@JustinGrote it looks like you have an extra PoshNmap in the load path on line 20 of the manifest file. It should go $PSScriptRoot\lib\Newtonsoft.Json-net40-client.dll. I removed it and the module loaded as expected.

patrickenfuego avatar May 23 '22 19:05 patrickenfuego

@JustinGrote it looks like you have an extra PoshNmap in the load path on line 20 of the manifest file. It should go $PSScriptRoot\lib\Newtonsoft.Json-net40-client.dll. I removed it and the module loaded as expected.

Found the same - and now I run into

PS C:\windows\system32> Invoke-Nmap www.google.com ConvertFromXml : Method invocation failed because [Newtonsoft.Json.JsonConvert] does not contain a method named 'SerializeXmlNode'. At C:\Program Files\WindowsPowerShell\Modules\PoshNMap\0.6.1\Public\ConvertFrom-NmapXML.ps1:41 char:26

  • ... (ConvertFromXml ([xml]$hostEntry).host).host | ...
  •                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (:) [ConvertFromXML], RuntimeException
    • FullyQualifiedErrorId : MethodNotFound,ConvertFromXML

Trying some work arounds got it to work eventually - now I get

PS> $var = @(Invoke-NMap www.google.com '-p 1-65535 -T4 -A -v') ForEach-Object: C:\Program Files\WindowsPowerShell\Modules\PoshNmap\0.6.1\Private\FormatPoshNmapHost.ps1:43:32 Line | 43 | $hostnode.ports.port | foreach-object { | ~~~~~~~~~~~~~~~~ | Index operation failed; the array index evaluated to null.

securatodd avatar Jun 08 '22 13:06 securatodd

@securatodd what version of Powershell are you running? It's only meant for 5.1+

JustinGrote avatar Jun 08 '22 14:06 JustinGrote

@securatodd what version of Powershell are you running? It's only meant for 5.1+

Current Version I am running in is 5.1.17763.2867

securatodd avatar Jun 08 '22 14:06 securatodd

Thanks, I'll try to investigate when I get time but unfortunately I have very little bandwidth for my community repos at the moment. Sorry, it is what it is :/

JustinGrote avatar Jun 08 '22 15:06 JustinGrote

@DanRobinsonHPE confirmed looks like there is an issue on 5.1, it works just fine on Powershell 7, looks to be a packaging issue with the newest version. image

i'm having the same problem with Powershell 7.4.0

> Install-Module -Name PoshNmap
Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from 
'PSGallery'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): a

> get-installedmodule

Version              Name                                Repository           Description
-------              ----                                ----------           -----------
0.6.1                PoshNmap                            PSGallery            A wrapper for NMAP Network Discovery

> invoke-nmap google.com
invoke-nmap: The term 'invoke-nmap' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

In the latest version did you export/alias the functions properly? I'm going to go check.

GeorgeBroughton avatar Dec 16 '23 03:12 GeorgeBroughton

Works for me on 7.4, fresh install. image

Do ipmo poshnmap -passthru |% exportedcommands to verify

JustinGrote avatar Dec 16 '23 16:12 JustinGrote