How to import a module for use in a dashboard in V3?

I’m trying to import a module for use on a dashboard. How do I do this in V3?
I found some documentation suggesting I do this:
New-UDEndpointInitialization -Module @("PoshNmap", ".\PoshNmap.psm1")
However, the dashboard won’t start with that bit of code in there.

This module has a function “Invoke-Nmap”, my hope is that a user can type in a remote server to target for NMAP scanning and a table on the page will be updated with the results output by that function. But first I need to import that module!

You can just import the module at the top of your dashboard.ps1.

Import-Module '.\PoshNmap.psm1' 

New-UDDashboard -Title '' -Content {

}

v3 automatically locates imported modules.

Hey Adam, I think I’ve got the module loading now. But I’m getting this error. Any suggestions?

Error: Minified React error #31; visit https://reactjs.org/docs/error-decoder.html?invariant=31&args[]=TypeError%3A%20Cannot%20read%20property%20’forEach’%20of%20null&args[]= for the full message or use the non-minified dev environment for full errors and additional helpful warnings.

in p
in ForwardRef
in ForwardRef
in div
in ForwardRef
in ForwardRef
in div
in ForwardRef
in ForwardRef
in ForwardRef
in ForwardRef
in u
in Dashboard
in t
in div
in t
in t
in n

This PowerShell code executes perfectly fine on the same server within ISE:

$Data = @()
$scanData = (invoke-nmap localhost -preset QuickPlus)
foreach($hostEntry in ($scanData | select *)){
    foreach($portEntry in $hostEntry.ports){
        $Data += @{Hostname = $hostEntry.Hostname; OS = $hostEntry.OS; IPv4 = $hostEntry.IPv4; Protocol = $portEntry.Protocol; Port = $portEntry.Port; Services = $portEntry.Services}
    }
}

Here’s how I have it laid out in PS UD:
> $Pages += New-UDPage -Name “Port Testing” -Content {

    New-UDContainer {
        New-UDForm -Content {
            New-UDTextbox -Label 'Standard' -Placeholder 'Textbox'
        } -OnSubmit {
            Show-UDToast -message $Session:scanData.Hostname
            $Data = @()
            $scanData = (invoke-nmap localhost -preset QuickPlus)
            $scanData = $scanData | select *
            foreach($hostEntry in $scanData{
                foreach($portEntry in $hostEntry.ports){
                    $Data += @{Hostname = $hostEntry.Hostname; OS = $hostEntry.OS; IPv4 = $hostEntry.IPv4; Protocol = $portEntry.Protocol; Port = $portEntry.Port; Services = $portEntry.Services}
                }
            }
            Sync-UDElement -iD 'results'
            }

            New-UDContainer {
                New-UDDynamic -autoRefresh -Id 'progress' -Content {
                    New-UDProgress -PercentComplete 0 -circular
                }
            }
            New-UDDynamic -AutoRefresh -Id 'results' -Content {
                New-UDTable -Title "Files" -Data $Session:Data 
            }
        }
    }