Because of the only build-in solution to get the datalog-files of a Siemens S7-1200 is through the webservice, I wrote a script that automatically
download all datalogs. ‘Additional the script can delete all log files of the machine with a parameter switch.

The first step of the script is to login in to the webservice to create an actually cookie with the tool wget. With the session IDs I can get all available datalogs and start the download with the help of curl.

The script is not verfy flexibel, so you have to change a few lines to environment.

First install GnuWin32 -> to get wget for Windows. Download

Copy all files to C:\Curlwget\

Open the script with any editor and change the IP-Adresses:

Also change the path where the datalog files will be saved:
Line 36 “\\server\share\”

To automatically download the files create a task in the Taskplaner:
Programm/script: powershell.exe
Add arguments (Optional): -command “& ‘C:\Curlwget\Download.ps1′
Start in (optional): C:\Curlwget

To delete all log files, run the script with the parameter -loeschen.

That’s it.


write-host $loeschen
(C:\Curlwget\GnuWin32\bin\wget --user-agent=Mozilla --no-check-certificate --cookies=on --save-cookies C:\Curlwget\cookies.txt --keep-session-cookies --post-data "Login=rc&Password=rc"
Remove-Item "C:\Curlwget\Default.mwsl"

$ad_secure_session = Get-content C:\Curlwget\cookies.txt | select-string -Pattern siemens_ad_secure_session
$ad_session = Get-content C:\Curlwget\cookies.txt | select-string -Pattern siemens_ad_session

$ad_secure_session = $ad_secure_session.toString().SubString(54)
$ad_session = $ad_session.toString().SubString(48)
write-host C:\Curlwget\curl.exe "" -H "Cookie: siemens_automation_language=de; siemens_ad_session=$ad_session; siemens_ad_secure_session=$ad_secure_session" --compressed --insecure
$output = (C:\Curlwget\curl.exe "" -H "Cookie: siemens_automation_language=de; siemens_ad_session=$ad_session; siemens_ad_secure_session=$ad_secure_session" --compressed --insecure) | Out-String

$anfang = Select-String "<input type='hidden' name='OldName' value='" -input $output -AllMatches
$ende = Select-String "csv'>" -input $output -AllMatches

$dateien = @()
for($i=0;$i -ne $anfang.matches.count;$i++)
	$temp = $ende.matches.index[$i] - $anfang.matches.index[$i]
	$dateien += $output.Substring($anfang.matches.index[$i]+43,$temp-40)


$dateien | foreach-object{
if($_ -ne "Vorlage44.csv") {
(C:\Curlwget\curl.exe "$_&x=9&y=5" -H "Referer:" -H "Cookie: siemens_automation_language=de; siemens_ad_session=$ad_session; siemens_ad_secure_session=$ad_secure_session" -H "Connection: keep-alive" --compressed --insecure)
#Dateien löschen
$dateien | foreach-object{
(C:\Curlwget\curl.exe "$_" -H "Referer:" -H "Cookie: siemens_automation_language=de; siemens_ad_session=$ad_session; siemens_ad_secure_session=$ad_secure_session" -H "Connection: keep-alive" --compressed --insecure --output "\\server\share\$_")


Wenn dir dieser Artikel gefallen hat, kannst du ihn mit einem Klick auf die folgenden Buttons weiterempfehlen. Möchtest du in Zukunft keine neuen Beiträge mehr verpassen? Dann abonniere doch den RSS Feed dieses Blogs. Vielen Dank!

2 Kommentare für “Siemens Simatic S7-1200 download Datalog files automatically”

  1. Hallo,

    läuft leider nicht , steigt beim analysieren der Webpage aus:

    <script src…" wird analysiert – Geschachtelter Quantifizierer +.
    Bei C:\Curlwget\Download.ps1:29 Zeichen:24
    + $anfang = Select-String <<<< "<input type='hidden' name='OldName' value='' -input $output -AllMatches
    + CategoryInfo : NotSpecified: (:) [Select-String], ArgumentException
    + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.SelectStringCommand

    12.08.2016 um 10:01

  2. Hallo,

    bitte das Skript mit Powershell V4 ausführen.
    Dann sollte es eigentlich funktionieren.


    30.08.2016 um 14:22

Kommentar abgeben

Current month ye@r day *