PSU v3 beta 4 & beta 5 New-PSUScript not working

@adam
looks like new-psuscript -name “test” - enviroment “powershell 7” is no longer works from a dashboard compared to version 2.10.2 and earlier
am getting an error when trying from the beta versions.

New-UDPage -Name "Test" -Content { 

    Connect-PSUServer -ComputerName $Cache:PSUServer -AppToken $Cache:AppToken
        
    New-UDButton  -Text "script" -OnClick {
    
    New-PSUScript -Name "Test.ps1" -Environment "PowerShell 7" -Path "Test.ps1" -ScriptBlock {
        "Hello, world!"
    }
    
    }
}

it works from the GUI admin console but not from dashboard.

Any Update on this?

I haven’t looked into this yet. I’ll make sure it gets fix before our next beta release.

Thanks adam

This was raised by @adam as #1164

@adam
issue still exists in beta 6

below error appeared when trying to create a test script from within vscode using the following command

New-PSUScript -Name test123.ps1

and similar behavior from within the dashboard nothing has changed from beta5 for this error.

New-PSUScript: Parameter set cannot be resolved using the specified named parameters. One or more parameters issued cannot be used together or an insufficient number of parameters were provided.

tested as well version 2.11.0 and no issues found for the same command.

I just tried this again and it’s working for me.

$Pages = @(
    New-UDPage -Id 'variables' -Name "Name" -Content {
    Connect-PSUServer -ComputerName 'http://localhost:5000' -AppToken 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoiYWRtaW4iLCJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9oYXNoIjoiZWY0OGY5NTktNGFlNC00MTI4LTg1OTMtYjg0ZDQxZWQzMTJkIiwic3ViIjoiUG93ZXJTaGVsbFVuaXZlcnNhbCIsImh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vd3MvMjAwOC8wNi9pZGVudGl0eS9jbGFpbXMvcm9sZSI6WyJFeGVjdXRlIiwiUmVhZGVyIiwiT3BlcmF0b3IiLCJBZG1pbmlzdHJhdG9yIl0sIm5iZiI6MTY1MjE0NDAwNSwiZXhwIjoxNjgzNjgwMDA1LCJpc3MiOiJJcm9ubWFuU29mdHdhcmUiLCJhdWQiOiJQb3dlclNoZWxsVW5pdmVyc2FsIn0.EwIFKvxAly4yka-hfuvZfhsHawPgDaRTVaVfC90zFKg'
            
        New-UDButton  -Text "script" -OnClick {
        
        New-PSUScript -Name "Test.ps1" -Environment "PowerShell 7" -Path "Test.ps1" -ScriptBlock {
            "Hello, world!"
        }
        
        }
    }
)

New-UDDashboard -Title 'Test' -Pages $Pages

am on IIS

That doesn’t seem to affect it for me either.

$Pages = @(
    New-UDPage -Id 'variables' -Name "Name" -Content {
    Connect-PSUServer -ComputerName 'https://localhost:8081' -AppToken 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoiYWRtaW4iLCJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9oYXNoIjoiZWY0OGY5NTktNGFlNC00MTI4LTg1OTMtYjg0ZDQxZWQzMTJkIiwic3ViIjoiUG93ZXJTaGVsbFVuaXZlcnNhbCIsImh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vd3MvMjAwOC8wNi9pZGVudGl0eS9jbGFpbXMvcm9sZSI6WyJFeGVjdXRlIiwiUmVhZGVyIiwiT3BlcmF0b3IiLCJBZG1pbmlzdHJhdG9yIl0sIm5iZiI6MTY1MjE0NDAwNSwiZXhwIjoxNjgzNjgwMDA1LCJpc3MiOiJJcm9ubWFuU29mdHdhcmUiLCJhdWQiOiJQb3dlclNoZWxsVW5pdmVyc2FsIn0.EwIFKvxAly4yka-hfuvZfhsHawPgDaRTVaVfC90zFKg'
            
        New-UDButton  -Text "script" -OnClick {
        
        New-PSUScript -Name "Test.ps1" -Environment "PowerShell 7" -Path "Test.ps1" -ScriptBlock {
            "Hello, world!"
        }
        
        }
    }
)

New-UDDashboard -Title 'Test' -Pages $Pages

Can you make sure you don’t have an older version of the Universal module installed on the machine it could be using?

You could also use integrated mode.

$Pages = @(
    New-UDPage -Id 'variables' -Name "Name" -Content {  
        New-UDButton  -Text "script" -OnClick {
        
        New-PSUScript -Name "Test.ps1" -Environment "PowerShell 7" -Path "Test.ps1" -ScriptBlock {
            "Hello, world!"
        } -Integrated
        
        }
    }
)

New-UDDashboard -Title 'Test' -Pages $Pages

i dont have any other module installed but am not using integrated, let me try again with integrated and see if there is a deference

@adam

I was able to find the problem which is the get-psuschedule the code below is a test you can try at your end.
you will notice a script & schedule are created but it errors out when trying to get the scheduled time
because $ScheduleDate for some reason is null.
the weird thing is if i open vscode and tried the get-psuschedule ill get results and then refresh the page will show everything normally.

but when the error appears like before if you try to restart the dashboard will still there the only way to get it to work is by accessing the vscode and type the get-psuschedule command.

New-UDPage -Name "Test PSU" -Icon (New-UDIcon -Icon Windows -Size 1x) -Content { 
        

    
       New-UDTabs -Tabs {
       
          New-UDTab -Text 'Config & Enhancement' -Content { 
          
             
	  
	        Connect-PSUServer -ComputerName $Cache:PSUServer -AppToken $Cache:AppToken

                New-UDDynamic -Id 'S3' -Content {
    
                
                $APools = @('Test1','Test2','Test3') 
                
                   $Data = @(  ForEach($_ in $APools) { 
                  
        [PSCustomObject]@{
            Name   = $_
            }
          }
        )

                   $Columns = @(

                   New-UDTableColumn -Property Name -Title Name -ShowSort -IncludeInExport -IncludeInSearch -ShowFilter -FilterType select

                   
                   
                   

              

              New-UDTableColumn -Property Schedule -Title Schedule -Render {
              
              Try
	      {
	      
              $Check = Get-PSUScript -Name "$($EventData.Name).ps1"
	      
	      }
	      Catch
	      {
	      $ErrorMessage = $_.Exception.Message
	      }
	      if($Check){
	          
	      $ScheduleDate = Get-PSUSchedule -Script $Check | Select-Object -ExpandProperty NextExecution | Out-String
	      
	      Show-UDToast -Message "$ScheduleDate" -MessageColor Green -Title $($EventData.Name) -Position topCenter -Duration 5500
	      
             if((Get-Date $ScheduleDate) -lt (Get-Date)){
          
              $Text = 'Expired'
              $BackgroundColor = '#F12A0F'
              $icon = 'edit'                 
                }
              else
	        {
              $Text = 'Modify'
              $BackgroundColor = '#0FF148'
              $icon = 'edit'
                } 
		
	        }
		else
		{
		
	      $Text = 'New'
              $BackgroundColor = '#3498DB'
              $icon = 'file'
	      
	      }

New-UDTooltip -Type info -Effect float -Place top -TooltipContent { "Schedule Email config & enhancement S3 Tenant files!" } -Content {

New-UDButton -Style @{ backgroundColor = $BackgroundColor } -Text $Text -OnClick {

Show-UDModal -FullWidth -MaxWidth 'md' -Content {

New-UDForm -Content {

New-UdRow -Columns {

New-UdColumn -LargeSize 6 -Conten {

New-UDCard -Title "Date" -Style @{BackgroundColor = '#5DADE2'} -Content {
                
New-UDDatePicker -id Date -Label Date -Format 'MM/dd/yyyy'
		  		                                   
     }                   
 }

New-UDColumn -LargeSize 6 -Content {

New-UDCard -Title "Time UTC" -Style @{BackgroundColor = '#D2B4DE'} -Content {
	     
New-UDSelect -Option {
		 
          New-UDSelectOption -Name 'Select UTC Time' -Value 'Select'
          New-UDSelectOption -Name '00:00:00' -Value 'T00:00:00.0000000Z'
          New-UDSelectOption -Name '01:00:00' -Value 'T01:00:00.0000000Z'
        
             } -Id 'Time' -Label Time
         }
     }
 }

 } -OnValidate {

 if ( (Get-UDElement -Id 'Date').Value -eq $null ){New-UDFormValidationResult -ValidationError "Date is required"}

  else {

 $DateValid = $True 
 
 }


 if ($EventData.Time -eq 'Select'){ New-UDFormValidationResult -ValidationError "Time is required"
 
     Set-UDElement -Id 'btnSubmit' -Properties @{ Disabled = $true }
     Sync-UDElement -Id 'btnSubmit'
 }

  else {

 $TimeValid = $True 
 
 }

 if ($DateValid -and $TimeValid)
    {
         New-UDFormValidationResult -Valid
    }  

} -SubmitText 'Validate' -OnSubmit {

 
     Set-UDElement -Id 'btnSubmit' -Properties @{ Disabled = $false }
     Sync-UDElement -Id 'btnSubmit'
	
          
	

 }
     } -Footer {
     
        #New-UDButton -Id 'btnSubmit' -Disabled -Text "Submit" -Style @{ backgroundColor = '#3498DB' } -Icon (New-UdIcon -Size 2x -Icon thumbs_up) -OnClick { 
	New-UDButton -Id 'btnSubmit' -Disabled -Style @{ backgroundColor = "blue" } -Text "Submit" -OnClick {
     
	$Date = (Get-UDElement -Id 'Date').Value
        $SelectedDate = Get-Date $Date -Format "yyyy-MM-dd"
	$Time = (Get-UDElement -Id 'Time').Value
	$Schedule = ($SelectedDate + $Time)
	
	Try
	      {
	      
              Get-PSUScript -Name "$($EventData.Name).ps1" 
	      
	      }
	      Catch
	      {
	      $ErrorMessage = $_.Exception.Message
	      }
	if($ErrorMessage){
      } else {
	New-PSUScript -Name "$($EventData.Name).ps1" -Environment "PowerShell 7.2.3" -ScriptBlock { param($Tenant)
	
	"Hello"    
     } 
}

        $Script = Get-PSUScript -Name "$($EventData.Name).ps1"
        $SC = Get-PSUSchedule -Script $Script
        if($SC){ Remove-PSUSchedule -Schedule $SC
        New-PSUSchedule -Script $Script -TimeZone 'UTC' -OneTime $Schedule -Environment "PowerShell 7.2.3" -Tenant $($EventData.Name)
          Sync-UDElement -Id "S3" -Broadcast
	  
          } else {
            
        New-PSUSchedule -Script $Script -TimeZone 'UTC' -OneTime $Schedule -Environment "PowerShell 7.2.3" -Tenant $($EventData.Name)
          Sync-UDElement -Id "S3" -Broadcast
	  }
	  
	Hide-UDModal 
	
          }
      }
  }

     }
}

              New-UDTableColumn -Property NextExecution -Title NextExecution -Render {
	      
	     
	    
	      Try
	      {
	      
	      $ScriptTest = Get-PSUScript -Name "$($EventData.Name).ps1"
	      $ScheduleDate = Get-PSUSchedule -Script $ScriptTest | Select-Object -ExpandProperty NextExecution
	      $ScheduleDate
	      }
	      Catch
	      {
          
          $ErrorMessage = $_.Exception.Message

	      }
	      
	     
      }
  ) 
    
         New-UDTable -Title 'S3 Data' -Data $Data -Columns $Columns -Sort -Export -ShowSearch -ShowPagination
                                                
      } -LoadingComponent { New-UDProgress }  
                        
         New-UDButton -Style @{ backgroundColor = "blue" } -Text "Refresh" -OnClick {
            Start-Sleep -Seconds 2
               Sync-UDElement -Id "S3" -Broadcast 
                  Start-Sleep -Seconds 2                
         }           
      }     
   }  
}

@adam

were you able to reproduce the issue using the above code?

Not yet. I will try in a little bit.

awesome thanks.

I think I am reproducing the issue. I click new and it creates the script and schedule but then i see this happen.

Even if I reload the page it happens again. Once I got view the schedules page and then go back to the dashboard it starts working.

That is so weird. I’ll look into it.

1 Like

yep thats exactly it. it works fine in version 2.xx but since beta version 3 it starts doing this

@adam

Testing the issue on beta 7 i found that the first click to create a schedule works but if you try to click the button again to modify the time it works as well but it throws the following error every time.