How to import and export data from Sage 50 using PowerShell?

SUGGESTED

Hello, I need some help with importing and exporting data from Sage 50 using PowerShell. I received an email from a service consultant from Sage that contained a PowerShell script that runs an import or export state with a command line launch. The script uses a text file (SgScp) that contains the instructions for the synchronization between Sage 50 and another application. The email also explained the steps and parameters involved in the process, and warned me about some possible issues and requirements. The script I received in the email is the following:

#RunSage50.ps V1.0
#Exemple de lancement de Sage50 par ligne de commande Powershell
#By P.Demerliac Sage


#Obtention du path de l'exe installé dans $AppPath -----------------------------------
$registryPath = "Registry::HKEY_CLASSES_ROOT\CielGestionCommerciale.Application\CLSID"
$Clsid=Get-ItemProperty -Path $registryPath
$Clsid=$Clsid.'(default)'

#Select location vs OSType
If ((Get-WmiObject Win32_OperatingSystem).OSArchitecture -eq '64-bit')
{ $registryPath = "Registry::HKEY_CLASSES_ROOT\WOW6432Node\CLSID\$Clsid\LocalServer32" }
Else 
{ $registryPath = "Registry::HKEY_CLASSES_ROOT\CLSID\$Clsid\LocalServer32" }


$AppPath=Get-ItemProperty -Path $registryPath
$AppPath=$AppPath.'(default)'

#Nom de la société cible à ouvrir -------------------------------------------------------------------
$CompagnyName="Acme"

# Utilisateur et mot de passe si la base le nécessite ------------------------------------------------
# NOTE : Dans cet exemple le mot de passe est dans le script pour simplifier
# en prod, le stocker de manière sécurisée, voir par exemple https://www.it-connect.fr/powershell-comment-chiffrer-un-mot-de-passe-dans-un-script/

$User="Mo-Riss"        #laisser vide si défaut
$PassWord="Secret#85"  #laisser vide si défaut

#Construction de la chaine de paramétres
$Params=""

#Credential éventuels 

if (![string]::IsNullOrEmpty($User)) {
    $Params += '-User="'+$User+'" '
}

if (![string]::IsNullOrEmpty($PassWord)) {
    $Params += '-Password="'+$PassWord+'" '
}

# Lancement d'un script éventuel-------------------------------------------------------------------------
# Changer le chemin d'accés au besoin

$Params +='-RunTask{ Task=100070012 Param(ScpName)="C:\Users\Admin\Desktop\PocS50Cli\PocSync.SgScp" , Param(ScpOpt)="_UsePrm-SrcExt-ModAuto" , Param(RwMode)="Par défaut" }'

#Il est possible éventuellement de passer des paramétres au script (Le caractère ¤ est requis comme délimiteur)
#Ici par exemple le chemin du fichier de commandes à importer

$Params +='/Custom=¤-SCP_CmdPath="C:\Users\Admin\Desktop\PocS50Cli\Commandes.Txt"¤ '

# Options possibles -------------------------------------------------------------------------
# (Commenter les lignes selon les besoins)

$Params +='/NoStart '  # Ne pas exécuter les tâches auto à l'ouverture de la base

$Params +='/NoEnd '    # Ne pas exécuter les tâches auto à la fermeture de la base

$Params +='/PostQuit ' # Quitte après exécution des tâches (Elles doivent être synchrones)


#Ajout Companie à ouvrir
$Params += $CompagnyName

#Run exe
start-process -FilePath $AppPath -ArgumentList $Params

However, I am not very familiar with PowerShell and I have some questions about the script and the SgScp file. I hope someone can help me understand them better and guide me through the process. Here are my questions:

- The registry path Registry::HKEY_CLASSES_ROOT\CielGestionCommerciale.Application\CLSID isn't available, I have the path HKEY_CLASSES_ROOT\CielGestionCommerciale.Application but there's no CLSID inside. What could be the issue and how can I solve it?

 

- What is the syntax and structure of the SgScp file, and how can I write and customize it to suit my needs?

- What should I expect to happen after I run the commands in PowerShell, and how can I get some feedback or output from the script?

- What does the Task=100070012 represent? And how is this ID being selected?

I appreciate any help or advice from the community. Thank you!