scansources.ps1 error

This forum is for the discussions and support for the Chocolatey For Automate plugin. Inside you will find the Documentation Project forum that describes the operation of the plugin.
frankbe
Posts: 36
Joined: Thu Jun 13, 2019 2:48 pm
5

scansources.ps1 error

Post by frankbe »

I get a error when i run the script P4A Chocolatey Sources

I was not able to assign my proget proxy to any agent.

When i add it manually with choco command, my proxy works.

Is There a BUG ?



TEST-DC
2
10.03.2025 12:41:34
Chocolatey returned -> [C:\Windows\LTSvc\C4A\scansources.ps1 : Fehlendes Argument für den Parameter "WORK". Geben Sie einen Parameter vom Typ
"System.String" an, und versuchen Sie es erneut.
In Zeile:1 Zeichen:88
+ ... ass -Scope Process -Force; C:\Windows\LTSvc\C4A\scansources.ps1 -WORK
+ ~~~~~
+ CategoryInfo : InvalidArgument: (:) [scansources.ps1], ParameterBindingException
+ FullyQualifiedErrorId : MissingArgument,scansources.ps1]
ComputerID
Hidden_ComputerID

User avatar
Cubert
Posts: 2645
Joined: Tue Dec 29, 2015 7:57 pm
9
Contact:

Re: scansources.ps1 error

Post by Cubert »

Sorry had to go translate that.


So error is saying that no data was passed along with the -WORK option.

The only way I could see that is if line 30 failed to convert line 29 in to a base64 string. Line 28 sets the WORK string to blank, Line 29 is the string we are going to convert and send. So it would only make since that this was the failure point and nothing was returned form Base64 request.
Screenshot 2025-03-11 145353.png
Screenshot 2025-03-11 145353.png (139.88 KiB) Viewed 3720 times


Can you execute the following on the agent in question to see what you get as a return

Code: Select all

[Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("AddSource|none|MyName|MyURL|MyUsername|mypass|0"))

Should return something like

Code: Select all

QWRkU291cmNlfG5vbmV8TXlOYW1lfE15VVJMfE15VXNlcm5hbWV8bXlwYXNzfDA=


Also have a look at the comands log for agent, confirm that there was no data after the -WORK switch for command

Cmmand would loo like this

Code: Select all

C:\Windows\LTSvc\C4A\scansources.ps1 -WORK 
instead of this

Code: Select all

C:\Windows\LTSvc\C4A\scansources.ps1 -WORK QWRkU291cmNlfG5vbmV8TXlOYW1lfE15VVJMfE15VXNlcm5hbWV8bXlwYXNzfDA=

frankbe
Posts: 36
Joined: Thu Jun 13, 2019 2:48 pm
5

Re: scansources.ps1 error

Post by frankbe »

These are the commands which i can see, when i started the Script
the error ist on the last execute command
sourcesscript.png
sourcesscript.png (157.22 KiB) Viewed 3708 times
here the output of the first two execute command lines (i changed host and password)

1.
cmd.exe!!! /c "@powershell Set-ExecutionPolicy Bypass -Scope Process -Force; "%LTSVCDir%\C4A\convert-to-b64.ps1 -clearString 'AddSource|none|chocorepo|http://proget.host.de:8080/nuget/chocop ... password|5'"
Output:
QWRkU291cmNlfG5vbmV8Y2hvY29yZXBvfGh0dHA6Ly9wcm9nZXQubWFuZV0L2Nob2NvcHV3xjaG9jbxNYW5kYWxhMjAyNSMzfDU=


2. cmd.exe!!! /c "@powershell Set-ExecutionPolicy Bypass -Scope Process -Force; "%LTSVCDir%\C4A\scansources.ps1 -WORK U2NhblNvdXJjZXN8bm9uZXxub25lfG5vbmV8bm9uZXxub25lfG5vbmU=""

Output:
(4693','25','chocolatey','https://community.chocolatey.org/api/v2/','0')

frankbe
Posts: 36
Joined: Thu Jun 13, 2019 2:48 pm
5

Re: scansources.ps1 error

Post by frankbe »

the command
[Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("AddSource|none|MyName|MyURL|MyUsername|mypass|0"))

works as expected

User avatar
Cubert
Posts: 2645
Joined: Tue Dec 29, 2015 7:57 pm
9
Contact:

Re: scansources.ps1 error

Post by Cubert »

Interesting...

Code: Select all

param(

      [Parameter(Mandatory = $true)]
      [string]
      $WORK
    )  
    try{
        $args = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($WORK))
        $workdata = $args.Split("|")
        $CMD = $workdata[0]
        $package = $workdata[1]
        $sourcename = $workdata[2]
        $sourceURL = $workdata[3]
        $username = $workdata[4]
        $password = $workdata[5]
        $priority = $workdata[6]


Further down the code we have the function to add source

Code: Select all

function addSourceRepo{
    try{

        if($username -eq ""){
            $xc = c:\programdata\chocolatey\bin\choco.exe source add -n="'$sourcename'" -s="'$sourceURL'" --priority="'$priority'"
            write-output $xc
        }else{
            $xc = c:\programdata\chocolatey\bin\choco.exe source add -n="'$sourcename'" -s="'$sourceURL'" -u="'$username'" -p="'$password'" --priority="'$priority'"
            write-output $xc
        }
    }catch{
        return
    }
}
Lastly the actual code that run s just a few short lines.

Code: Select all

if($CMD -eq "ScanPackages"){
    scan-packages
}elseif($CMD -eq "ScanSources"){
    scan-sources
}elseif($CMD -eq "AddSource"){
    addSourceRepo
}elseif($CMD -eq "RemoveAllSources"){
    removeAllSources
}elseif($CMD -eq "RemoveSource"){
    $xc = c:\programdata\chocolatey\bin\choco.exe source remove -n="'$sourcename'"
}else{
    write-output "Command not found"
}



So starting at the top, We take in a base64 encryptrd string called WORK, Work is then decoded to a normal string "AddSource|none|MyName|MyURL|MyUsername|mypass|0" and then split in the pipe key ( | ) in to an array and then assigned a variable name for each value.

We test the CMD variable (in this case is AddSource) which launches the addSourceRepo function above. That function takes your data and adds the repo to chocolatey as seen in function.

Code: Select all

 $xc = c:\programdata\chocolatey\bin\choco.exe source add -n="'$sourcename'" -s="'$sourceURL'" -u="'$username'" -p="'$password'" --priority="'$priority'"

If $xc = Output ->(4693','25','chocolatey','https://community.chocolatey.org/api/v2/','0')

Then I'm thinking this was a scanSource and not an addSource command.

Ths is plausable as we do send a scan request first, so we need to see if we get inside the look of the Automate script where we test for and add sourcers.


Please try running scrit in debug mode on the agent in question. Place a break at line 33 so script runs through the loop once and stops. Then lets look at script and command logs, we have a script log line that will print out "Chocolatey returned -> [@ADDSOURCE@]" in the agents script logs.

Did we get the log, did it stop at the break point if so post the log and the command input/output.
Screenshot 2025-03-12 165205.png
Screenshot 2025-03-12 165205.png (82.47 KiB) Viewed 3686 times

frankbe
Posts: 36
Joined: Thu Jun 13, 2019 2:48 pm
5

Re: scansources.ps1 error

Post by frankbe »

i have to manually set
UseintEnc to 0 to make the script run to validatesources

line 32 logs:
Chocolatey v2.4.3
Added chocorepo - http://host:8080/nuget/chocopublic/ (Priority 5)

%sqldatasetrowcount%=1

then script exits in cleanup

User avatar
Cubert
Posts: 2645
Joined: Tue Dec 29, 2015 7:57 pm
9
Contact:

Re: scansources.ps1 error

Post by Cubert »

Ok thats interesting....

On line 4 we set that value so you must have it set in the main console.



Ok lets try this, If you have the Use International Encoding selected, Run script in debug and place a break at line 90.

Screenshot 2025-03-13 105318.png
Screenshot 2025-03-13 105318.png (80.64 KiB) Viewed 3393 times



I was in the wrong area of script for your encoding selection. This is the loop that you should be in.

If you are using the same agent to test, then remove the source if it exists on agent first before running debug test.

P.s do not mind that my script image does not look like your script entirly. I am making some modifications to the script to improve it just a little and adding some more logging.

User avatar
Cubert
Posts: 2645
Joined: Tue Dec 29, 2015 7:57 pm
9
Contact:

Re: scansources.ps1 error

Post by Cubert »

I just pushed out an update to build 3.7.0.13.

It should improve the source script a little and provide some script logging to help show you where in script you are at if a failure arrises. Make sure to restart the DBagent afterwards..

https://delivery.shopifyapps.com/-/e8e9 ... 3174c10eab

frankbe
Posts: 36
Joined: Thu Jun 13, 2019 2:48 pm
5

Re: scansources.ps1 error

Post by frankbe »

i have habitat - can i use your download link or does that effect our license ?

frankbe
Posts: 36
Joined: Thu Jun 13, 2019 2:48 pm
5

Re: scansources.ps1 error

Post by frankbe »

Problem seems to be in Line
line93.png
line93.png (51.4 KiB) Viewed 2320 times
there is a shellresult, which looks like the encoded string, but
@myencodedsourceworkstring@ ist empty

so that line 94 gives the error

this is sourceworkstring:
AddSource|none|chocorepo|http://host.de:8080/nuget/chocopublic/| ... password|5

Post Reply

Return to “Chocolatey For Automate”