Closed RubenT91 closed 3 weeks ago
@RubenT91 Your Invoke-PSUScript
command is missing a reference to which script it should run. The code should look like:
$Data = Invoke-PSUScript -Script $Script -Integrated -Wait
It looks like you were trying to do this with the -Name $Script
section, but it should be -Script
instead of -Name
.
@JessePeden here is a part of the code, I tried using -script
and -name
the result is the same.
code:
$Script = "$($Module)\$($Command)"
Line 20:
New-UDButton -Text 'Run Report' -OnClick {
Show-UDToast "Running report..."
Invoke-PSUScript -Script $Script -Integrated | Wait-PSUJob -Integrated
Sync-UDElement -Id "$($Title)_Table"
Show-UDToast "Report complete."
} -Icon (New-UDIcon -Icon 'Play') -ShowLoading
Logs:
[5/29/2024 10:03:10 AM] [Error] [App-Management Active Directory] An error occurred: Cannot retrieve the dynamic parameters for the cmdlet. Script not found.
Endpoint: 20395542-7bd9-4559-a058-eacd6ff28faf
Session: 0d1796c0-459a-4b4f-8fb4-8c199a28337f, User: user@example.com
at 20395542-7bd9-4559-a058-eacd6ff28faf: line 3
at 20395542-7bd9-4559-a058-eacd6ff28faf: line 1
at Reports-home-page.ps1 : line 20
at 20395542-7bd9-4559-a058-eacd6ff28faf: line 3
at 20395542-7bd9-4559-a058-eacd6ff28faf: line 1
at Reports-home-page.ps1 : line 20
[5/29/2024 10:03:10 AM] [Error] [App-Management Active Directory] Cannot retrieve the dynamic parameters for the cmdlet. Script not found.
[5/29/2024 10:02:39 AM] [Information] [App-Management Active Directory] Dashboard configuration complete.
[5/29/2024 10:02:38 AM] [Information] [App-Management Active Directory] Starting scheduler.
[5/29/2024 10:02:35 AM] [Information] [App-Management Active Directory] Creating services.
@RubenT91 @DDRosenxt Can you add Write-Output $Script
somewhere after you've filled the variable, to verify that it's actually being populated correctly and there's not a formatting issue or anything, and share the output here?
@JessePeden @RubenT91 I added New-UDAlert -Severity ‘info’ -Title $Script -Id ‘alert3’
to the New-UDStack
BaseAlert block, it displays the contents of the $script
variable on the report form.
$Script = "$($Module)\$($Command)"
#$Script = "$($Command)"
New-UDPage -Name $Title -Url $Url -Content {
New-UDStack -Direction row -Content {
New-UDButton -Text 'Back to Reports' -Icon (New-UDIcon -Icon ArrowAltCircleLeft) -OnClick {
Invoke-UDRedirect "/reports"
}
**New-UDAlert -Severity 'info' -Title $Script -Id 'alert3'**
New-UDButton -Text 'Run Report' -OnClick {
Show-UDToast "Running report..."
Invoke-PSUScript -Script $Script -Integrated | Wait-PSUJob -Integrated
Sync-UDElement -Id "$($Title)_Table"
Show-UDToast "Report complete."
} -Icon (New-UDIcon -Icon 'Play') -ShowLoading
}
That was the easiest way to check the value of the variable. report:
I can see all the scripts:
and this script Get-UDDisabledComputers:
function Get-UDDisabledComputers {
<#
.SYNOPSIS
Gets a list of disabled computers.
.DESCRIPTION
Gets a list of disabled computers.
#>
[System.ComponentModel.DisplayName("Disabled Computers")]
param()
Get-ADComputer -Filter { (Enabled -eq $False) } -ResultPageSize 2000 -ResultSetSize $null -Properties Name, OperatingSystem, SamAccountName, DistinguishedName | Select-Object Name, OperatingSystem, SamAccountName, DistinguishedName
}
@DDRosenxt Is that function the only code that's in the script file? Where are you actually calling the function inside the script?
@JessePeden In Platform / Modules
we see installed modules, not scripts.
All available scripts are available in the Automation / Scripts
section.
so I know it's right.
@DDRosenxt I think was confused. You were showing code blocks from within the module and the scripts it automatically created/installed, not custom code you created yourself. Is that correct?
A coupe of things that I noticed after installing the Universal.Apps.ActiveDirectory
module in my PSU instance that differ with what your screenshots show, are:
The scripts it installed are under a folder named Universal.Apps.ActiveDirectory
and not Management.ActiveDirectory
like they are in your screenshot.
None of the installed scripts have code wrapped within function
blocks.
What version of the module do you have installed? I installed the latest available, which is 0.0.3
.
@JessePeden Module name was changed, but the latest version 0.0.3
is installed.
- None of the installed scripts have code wrapped within
function
blocks.
if you look at the source code in the file with an editor, you will see the function
. In the web interface the function will not be shown, because the Module refers to a function
and not to a script.
New-PSUScript -Module "Management.ActiveDirectory" -Command "Get-UDDisabledComputers" -InformationAction "SilentlyContinue"
it's explained here Module management for PowerShell Universal.
@DDRosenxt Nope. function
is not shown anywhere in the script files it generated, even when opened in an external editor (such as VS Code). The scripts look identical to how they are within the PSU code editor interface. This is my point, though. There seem to be some differences between what you have and what I have, even though we're both using PSU version 4.2.21
and both using version 0.0.3
of the Universal.Apps.ActiveDirectory
module.
Are you saying that you renamed the module after installing it, to Management.ActiveDirectory
?
@JessePeden installed the original version without any changes.
this is what I see in VS Code
:
@JessePeden After the original installation Universal.Apps.ActiveDirectory, the Reports partition, did not work initially. There was another error that I fixed.
[5/29/2024 3:50:13 PM] [Error] [App-Active Directory] An error occurred: Cannot bind argument to parameter 'Url' because it is an empty string.
Endpoint: c770ae8f-5d6a-4ace-ad9d-2537fbf87029onClick
Session: 5fe84ae7-1292-4e06-bb5b-91231757eb58, User: user@example.com
at c770ae8f-5d6a-4ace-ad9d-2537fbf87029onClick: line 2
at c770ae8f-5d6a-4ace-ad9d-2537fbf87029onClick: line 1
at Universal.Apps.ActiveDirectory.psm1 : line 181
I adapt the Universal.Apps.ActiveDirectory
module for our company, so I changed the name to Management.ActiveDirectory
.
Ahh. I see the issue. We're talking about 2 different things. Within PSU, if you go to Automation\Scripts\Repository\Univeral.Apps.ActiveDirectory
and edit the scripts you'll see there, those are what I was referring to not having function
blocks.
What you're looking at, instead, are the .ps1
files in a completely different path (Automation\Scripts\Repository\Modules\Universal.Apps.ActiveDirectory\0.0.3\Reports\<file>.ps1
).
The ones I was looking at seem to only exist inside of PSU and don't appear to actually be part of the repository, despite their path saying otherwise.
@JessePeden No, that's right, it's the same script.
Here's a little test. I modified the script in VS Code.
restarted the PSU service.
The comment can be seen in the PSU interface.
I found information that PSU has changed this module and instead of a script file they register functions in the module. I hope I've explained it correctly.
You did. I see what it's doing now. Sorry for the confusion.
I think this was an issue with PSU itself. 4.3 seems to work fine after a fix to how we load functions from modules. I put in a patch to fix the URL error on the reports page.
Version
4.2.21
Severity
Low
Environment
msi
Steps to Reproduce
Installed UPS standard using MSI. Only reports do not work in the Universal.Apps.ActiveDirectory module.
As far as I understand, calling the script does not work
$Data = Invoke-PSUScript -Integrated -Name $Script -Wait
Expected behavior
Actual behavior
Additional Environment data
PowerShell Universal Version: 4.2.21 (Licensed) PowerShell Version: 5.1.20348.2400 and 7.4.2 PowerShell Universal Environment: Windows PowerShell 5.1, PowerShell 7, Integrated, Agent and 7.4.2 Execution Policy: RemoteSigned Permissions: the application requires roles - Administrator, AD Admin, AD Users or AD Groups. My account has Administrator. Verbose Logging: the log shows the same messages. Logs data attached to case
Screenshots/Animations
No response