ironmansoftware / powershell-universal

Issue tracker for PowerShell Universal
https://powershelluniversal.com
34 stars 3 forks source link

Scripts: Moving not working properly when base folder set #3072

Open ricoroodenburg opened 8 months ago

ricoroodenburg commented 8 months ago

Version

4.2.11

Severity

Critical

Steps to Reproduce

Please follow the following steps in an EMPTY environment!

  1. Create the following folder structure in the Scripts overview.

    • Repository -- Scripts --- Microsoft ---- Active Directory ----- Users ----- Computers
  2. Set the Script Base Folder to "Scripts"

  3. Add a new script to the folder "Scripts\Microsoft\Active Directory\Users" and save it.

In scripts.ps1 the following line is added: New-PSUScript -Name "Get AD User.ps1" -Description "Get AD User" -Path "Microsoft\Active Directory\Users\Get AD User.ps1" -Environment "Windows PowerShell 7.4" -InformationAction "SilentlyContinue"

  1. Move the newly created script to folder "Scripts\Microsoft\Active Directory\Computers" and save it.

  2. Issue 1: In the admin console browse to the folder Scripts\Microsoft\Active Directory\Computers. As you can see, the script isn't there.

In scripts.ps1, the following line is present: New-PSUScript -Name "Get AD User.ps1" -Description "Get AD User" -Path "**<PATH_TO_REPO_DEFINED_IN_APPSETTINGS>\Repository\**Microsoft\Active Directory\Computers\Get AD User.ps1" -Environment "Windows PowerShell 7.4" -InformationAction "SilentlyContinue"

In the background when moving a script, following is happened:

  1. Add a new script, in a random folder and save it.

  2. Issue 2: Open script.ps1 file, as you can see, the previously created script is gone.

When adding a new script, the previously created script reference is deleted, since PowerShell Universal can't find a script is the desired folder.

The following error is shown in the notification area; Cannot process argument because the value of argument "path" is null. Change the value of argument "path" to a non-null value.

Root Cause

I think the root cause is a invalid fullpath property in the body while calling the PUT /scripts API endpoint:

fullPath
: 
"\\\\domainname\\folder\\Software\\Repository\\\\Microsoft\\Active Directory\\Computers\\Test 2.ps1"

As you can see, between "Repository" and "Microsoft" there is a gap. Between these folders, the Script Base Folder value should be stored.

Expected behavior

Scripts.PS1:
New-PSUScript -Name "Get AD User.ps1" -Description "Get AD User" -Path "Microsoft\Active Directory\Computers\Get AD User.ps1" -Environment "Windows PowerShell 7.4" -InformationAction "SilentlyContinue"

Actual behavior

Scripts.PS1:
New-PSUScript -Name "Get AD User.ps1" -Description "Get AD User" -Path "<PATH_TO_REPO_DEFINED_IN_APPSETTINGS>\Repository\Microsoft\Active Directory\Computers\Get AD User.ps1" -Environment "Windows PowerShell 7.4" -InformationAction "SilentlyContinue"

Additional Environment data

No response

Visuals

No response

ricoroodenburg commented 8 months ago

If you like, we can set up a remote call.