Passing Values to a function

Hi All,

I am trying to pass some values to a function to start a connect but not sure what i am doing wrong.

New-UDPage -Name "Nessus to Excel" -Icon home -Content {
New-UDRow -Columns {
    New-UDColumn -Size 4 -Endpoint {
        New-UDInput -title "Nessus Connection Setting" -SubmitText "Connect" -Id 'NessusLogin' -content {
            New-UDInputField -Type 'textbox' -Name 'NessusURL' -Placeholder "Localhost" -DefaultValue 'localhost' 
            New-UDInputField -Type 'textbox' -Name 'NessusUsername' -Placeholder "Username"
            New-UDInputField -Type 'password' -Name "NessusPassword" -Placeholder "Password"   
        } -Endpoint {
                New-UDInputAction -Toast "You have connected to $NessusURL" -Content{
                   Connect-Nessus -NessusURL $NessusURL -NessusUsername $NessusUsername -NessusPassword $NessusPassword
    New-UDColumn -Size 4 -Content {
        New-UDTable -Title "Server Information" -Headers @(" ", " ") -Endpoint {
                'Computer Name' = $env:COMPUTERNAME
                'Operating System' = (Get-CimInstance -ClassName Win32_OperatingSystem).Caption
                'Total Disk Space (C:)' = (Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DeviceID='C:'").Size / 1GB | ForEach-Object { "$([Math]::Round($_, 2)) GBs " }
                'Free Disk Space (C:)' = (Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DeviceID='C:'").FreeSpace / 1GB | ForEach-Object { "$([Math]::Round($_, 2)) GBs " }
             }.GetEnumerator() | Out-UDTableData -Property @("Name", "Value")
    New-UDColumn -Size 4 -Content {}



What’s the behavior you are seeing?

I get an error message say ‘Parameter set cannot be resolved using the specified name parameter’.

Your error message is coming from your usage of New-UDInputAction

It doesn’t work with both -Toast and -Content as they are from different parameter set.

Therefore, you need to change this single input action:

 New-UDInputAction -Toast "You have connected to $NessusURL" -Content{
                   Connect-Nessus -NessusURL $NessusURL -NessusUsername $NessusUsername -NessusPassword $NessusPassword

For these 2 separate actions.

  New-UDInputAction -Toast "You have connected to $NessusURL"
  New-UDInputAction  -Content {
     Connect-Nessus -NessusURL $NessusURL -NessusUsername $NessusUsername -NessusPassword $NessusPassword

You can get an idea of the different parameters set by looking at the command definition
e.g. : (Get-Command New-UDInputAction).ParameterSets | ft

1 Like

Awesome, that work but now the whole box disappears when i click connect

if you aren’t returning anything from Connect-Nessus. Just do this:

Connect-Nessus -NessusURL $NessusURL -NessusUsername $NessusUsername -NessusPassword $NessusPassword | Out-Null
New-UDInputAction -Toast "You have connected to $NessusURL"

The Connect-Nessus function make a connect an does have data that other function requires. I have tried to use the $Cache:Connect-Nessus that does not seem to work. The module i am using is Posh-Nessus

Can you point me to where this function is defined? I’m looking in the GitHub for Posh-Nessus but don’t see it.

The command is New-NessusSession i just had it in a function to do other thing. I have tried it with New-NessusSession the same results.

Ah, ok. I see the issue. New-NessusSession is using a $Global variable that won’t persist between endpoint calls. Let me think of a good solution for this.

Just a thought.
You could preserve the Global variable content in a Cache variable and maintain it as needed.

Something like

$Cache:NessusConn = $Global:NessusConn

in the first endpoint

Then, in subsequents ones

$Global:NessusConn = $Cache:NessusConn
# Other Nessus calls ... that will see the global variable as they expect
 $Cache:NessusConn = $Global:NessusConn # To refresh the variable in case it changed
1 Like

That would explain why i was getting this error message.

You cannot call a method on a null-valued expression.
At C:\Users\Michael\Documents\WindowsPowerShell\Modules\Posh-Nessus\Session.ps1:93 
+                 [void]$Global:NessusConn.Add($sessionobj)
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

itfranck - I tried what you said and it did not work.