> For the complete documentation index, see [llms.txt](https://docs.videc.de/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.videc.de/june5-3.7/en/web-api/web-api-client-code-beispiele/powershell-code-beispiele.md).

# PowerShell Code Examples

The following code examples are scripted with *PowerShell*.

### PowerShell Quick Introduction

1. To use PowerShell, start the IDE. (Run as Administrator)

C:\Windows\system32\WindowsPowerShell\v1.0\PowerShell\_ISE.exe

{% hint style="info" %}
There is a 32-bit and 64-bit variant!
{% endhint %}

2. The following command must be executed to allow PS (PowerScript) execution:

Set-ExecutionPolicy Unrestricted

Confirm the message with "Yes". Windows now allows the execution of PowerScripts.

To test the scripts below, copy the code into a file with the extension .ps1

This file can then be executed in the PowerShell application (ISE).

|   |   |
| - | - |

<table data-header-hidden><thead><tr><th></th></tr></thead><tbody><tr><td><pre><code># Entry into the PowerShell / WebAPI world of JUNE5
# For testing, you can use the portal server at https://portal.videc.info
# This script authenticates against the JUNE5 API and only retrieves some information
$MyUser = 'admin'
$MyPassword = 'admin'
$J5Base = "https://portal.videc.info/api/v3.6/"
$MyVersion = Invoke-RestMethod -Uri "$J5Base/System/GetVersion"
"The following JUNE5 version is used: " + $MyVersion
" "
$Body = @{
Logon = "admin"
Password = "admin"
LoginType = 0
}
$MyJUNE5 = Invoke-RestMethod -Uri "$J5Base/auth/authenticate" -Method Post -Body $Body -SessionVariable sess
" "
"001 - Token String    = " + $MyJUNE5.Token
" "
" "
"002 - Token Identity  = " + $MyJUNE5.IdentityToken
" "
"003 - Client Uid               = " + $MyJUNE5.IdentityToken.ClientUid
"004 - DataSource Read          = " + $MyJUNE5.IdentityToken.DataSourceRead
"005 - DataSource Read / Hidden = " + $MyJUNE5.IdentityToken.DataSourceRead.Hidden
</code></pre></td></tr></tbody></table>

|   |   |
| - | - |

<table data-header-hidden><thead><tr><th></th></tr></thead><tbody><tr><td><pre><code># This script authenticates against the JUNE5 API and retrieves the object list (all objects, or depending on requirements, only certain object types)
# SV = Standard View
# Further information can be queried for each object.
Define base data
$MyUser = 'admin'
$MyPassword = 'admin'
$Base = "https://portal.videc.info/api/v3.6/"
Login and get token
$MyJUNE5 = Invoke-RestMethod -Uri "$Base/auth/authenticate" -Method Post -Body @{"Logon" = $MyUser; "Password" = $MyPassword}
Get data from GetList
$MyData = Invoke-RestMethod -Uri "$Base/ViewModel/GetList?viewModelStrongName=SV" -Headers @{"June5-Token" = $MyJUNE5.Token}
Output data as table
# $MyData | ft                          # All data# $MyData | ft DataSourceKey, Name      # Only two columns# $MyData | Out-GridView                # If some filters are desired# All objects, sorted by type, formatted in a table# $MyData | Sort-Object ObjectModelType | ft -Property DataSourceKey, Name, ObjectModelType -GroupBy ObjectModelType
If you want to search through individual items:
foreach($Item in $MyData){
&#x3C;#
e.g: only objects of type "Dashboard"
- .Created = Time when the object was created
- .DataSourceKey = The unique DataSourceKey
- .Uid = The unique object ID
- .UidCreated = The person who created the object (Dashboard).
Now conclusions can be drawn about the user, or the object can be deleted
#>
if ($Item.ObjectModelType -eq 16){
$Item.ObjectPermission.Created + "   " + ($Item.DataSourceKey).PadRight(40, ' ')  + "   " + $Item.Uid + "   " + $Item.Object.UidCreated
}
}
&#x3C;#
Available columns
ShortAndLongName           // Short and long name
LongAndShortName           // Long and short name
ClientUid                  // Tenant ID
Uid
Name
DataSourceKey              // Unique "hard" key
ParentUid                  // For hierarchies the parent element
Object
ObjectModelType            // See below
ObjectModelItemUid
Items
ItemCount
HierarchyLevel
RootViewUid
DataSourceType             // See below
SortIndex
ObjectPermission           // Access rights
#>
</code></pre></td></tr></tbody></table>

|   |   |
| - | - |

<table data-header-hidden><thead><tr><th></th></tr></thead><tbody><tr><td><pre><code># This script authenticates against the JUNE5 API and retrieves the measurement data of a measurement variable over a defined time period
Define base data
$MyUser = 'admin'
$MyPassword = 'admin'
$Base = "https://portal.videc.info/api/v3.6/"
Login and get token
Write-Host -ForegroundColor Yellow "Login"
$MyJUNE5 = Invoke-RestMethod -Uri "$Base/auth/authenticate" -Method Post -Body @{"Logon" = $MyUser; "Password" = $MyPassword}
$MyJUNE5.Token
" "
Write-Host -ForegroundColor Yellow "Wait 4 seconds"
Start-Sleep -Seconds 4
" "
Define request payload
Minimum specification is the DataSourceKey
$ReqPay = @{
Parameters = @(
@{
DataSourceKey = 'J5001DE.TA'
From = '2023-01-01T00:00:00.000'
To = '2024-06-01T00:00:00.000'
DataKind = '0'    # 0=Pro, 1=Int1, 2=Int2, ...,20=Day, 50=Week, 51=Month, 52=Year, 300=Manual
ValueKind = '0'   # 0=VAL, 5=PMIN, 6=PMAX...
Resolution = '0'  # -1, 2000
  # Optional parameters:  # ObjectModelStrongName = &#x26;#x27;string&#x26;#x27;  # ObjectModelItemUid =  &#x26;quot;00000000-0000-0000-0000-000000000000&#x26;quot;  # Handle = &#x26;quot;00000000-0000-0000-0000-000000000000&#x26;quot;  # OrderBy = &#x26;quot;true&#x26;quot;  # IgnoreNullValues = &#x26;#x27;true&#x26;#x27;}
)}
$JSON = $ReqPay | ConvertTo-Json
Write-Host -ForegroundColor Yellow "This is what the JSON object looks like"
$JSON
" "
#"Query a variable"
$MyData = Invoke-RestMethod -Uri "$Base/ViewModel/GetProcessVariableListValuesByDataSourceKey" -Method Post -Headers @{"June5-Token" = $MyJUNE5.Token} -Body $JSON -ContentType 'application/json'
Write-Host -ForegroundColor Yellow "Number of values"
$MyData.ObjectList.Values.Count
Write-Host -ForegroundColor Yellow "Output of raw data of a variable"
$MyData.ObjectList.Values | ft
" "
</code></pre></td></tr></tbody></table>

|   |   |
| - | - |

<table data-header-hidden><thead><tr><th></th></tr></thead><tbody><tr><td><pre><code># This script authenticates against the JUNE5 API and retrieves the measurement data of multiple measurement variables
Define base data
$MyUser = 'admin'
$MyPassword = 'admin'
$Base = "https://portal.videc.info/api/v3.6/"
Login and get token
Write-Host -ForegroundColor Yellow "Login"
$MyJUNE5 = Invoke-RestMethod -Uri "$Base/auth/authenticate" -Method Post -Body @{"Logon" = $MyUser; "Password" = $MyPassword}
$MyJUNE5.Token
" "
Write-Host -ForegroundColor Yellow "Wait 2 seconds"
Start-Sleep -Seconds 2
" "
Define request payload
$ReqPay = @{
Parameters = @(
@{
DataSourceKey = 'J5001DE.TA'
From = '2025-01-01T00:00:00.000'
To = '2025-01-04T00:00:00.000'
DataKind = '0'  # 0=Pro, 1=Int1, 2=Int2, ...,20=Day, 50=Week, 51=Month, 52=Year, 300=Manual
ValueKind = '0' # 0=VAL, 5=PMIN, 6=PMAX...
Resolution = '2000'
IgnoreNullValues = 'true'}
@{
DataSourceKey = 'J5001DE.LD'
From = '2025-02-01T00:00:00.000'
To = '2025-02-04T00:00:00.000'
DataKind = '0'  # 0=Pro, 1=Int1, 2=Int2, ...,20=Day, 50=Week, 51=Month, 52=Year, 300=Manual
ValueKind = '0' # 0=VAL, 5=PMIN, 6=PMAX...
Resolution = '2000'}
)}
$JSON = $ReqPay | ConvertTo-Json
Write-Host -ForegroundColor Yellow "This is what the JSON object of the request looks like"
$JSON
" "
#"Execute query"
$MyData = Invoke-RestMethod -Uri "$Base/ViewModel/GetProcessVariableListValuesByDataSourceKey" -Method Post -Headers @{"June5-Token" = $MyJUNE5.Token} -Body $JSON -ContentType 'application/json'
Write-Host -ForegroundColor Yellow "Output of all variables and the data TimeStamp, Value"
Outer loop for the variables
foreach($Var in $MyData.ObjectList){
$Var.DataSourceKey + " (" + $Var.Name + ") [" + $Var.ProcessUnit + "]"
Inner loop for the values
foreach($Item in $Var.Values){
$Item.TimeStamp + ";" + $Item.Value
}
" "
}
Write-Host -ForegroundColor Yellow "Number of values of all variables"
$MyData.ObjectList.Values.Count
</code></pre></td></tr></tbody></table>

|   |   |
| - | - |

<table data-header-hidden><thead><tr><th></th></tr></thead><tbody><tr><td><pre><code># This script authenticates against the JUNE5 API and retrieves the user list
Define base data
$MyUser = 'admin'
$MyPassword = 'admin'
$Base = "https://portal.videc.info/api/v3.6/"
Login and get token
$MyJUNE5 = Invoke-RestMethod -Uri "$Base/auth/authenticate" -Method Post -Body @{"Logon" = $MyUser; "Password" = $MyPassword}
Get data from GetList
$MyData = Invoke-RestMethod -Uri "$Base/UserAdministration/GetUsers?userType=0" -Headers @{"June5-Token" = $MyJUNE5.Token}
Output data as table
 $MyData | ft Logon, LastName, Firstname, Uid, IsEnabled, UidCreated      # Only the most important columns# $MyData | Out-GridView                                      # If some filters are desired
If you want to search through individual items:
foreach($Item in $MyData){
$Item.Logon
$Item.UidCreated
}
</code></pre></td></tr></tbody></table>

|   |   |
| - | - |

<table data-header-hidden><thead><tr><th></th></tr></thead><tbody><tr><td><pre><code># This script authenticates against the JUNE5 API and retrieves a PDF report and saves it as a local PDF file.
# The query is performed via the following steps:
# Step 1: Log in and get token
# Step 2: Determine the measurement variable list, but only the report objects
# Step 3: With a UID of a report object, get the PDF stream and write it as a file if necessary
# Background information
URL encoded character for
$ = %24
! = %25
&#x26; = %26
? = %3F
Define base data
$MyUser = 'admin'
$MyPassword = 'admin'
$Base = "https://portal.videc.info/api/v3.6/"
Step 1: Login and get token
Write-Host -ForegroundColor Yellow "Step 1: Login with token"
$MyJUNE5 = Invoke-RestMethod -Uri "$Base/auth/authenticate" -Method Post -Body @{"Logon" = $MyUser; "Password" = $MyPassword}
$MyJUNE5.Token
" "
Step 2: Determine the measurement variable list, but only the report objects
Create all parameters for GetListPaged
ObjectModelType 128 is for reports
Other ObjectModelTypes:
4 = Group
16 = ProcessVariable (Auto)
32 = ProcessVariable (Calculated)
64 = ProcessVariable (Manual)
128 = Reports
256 = Chart
$Filter = "$filter=ObjectModelType eq Videc.June5.Entities.ObjectModelType&#x26;#x27;128&#x26;#x27;&#x26;quot; $Top = &#x26;quot;&#x26;amp;$top=500"  #Top and Skip are OData!
$Skip = "&#x26;$skip=0&#x26;quot; $Order = &#x26;quot;&#x26;amp;$orderby = DataSourceKey asc, Name asc"
Create and output overall URI
Write-Host -ForegroundColor Yellow "Step 2: Determine the measurement variable list, but only the report objects of type 128:"
$Uri = $Base + "ViewModel/GetListPaged?" + $Filter + $Top + $Skip + $Order
$Uri
" "
$MyData = Invoke-RestMethod -Uri $Uri -Method Get -Headers @{"June5-Token" = $MyJUNE5.Token}
#$MyData.Items | Out-GridView
Step 3: Get the PDF stream using a report object UID
UID of the first report, type is unknown here, so it can be month or year, etc.
Now the UID of a report is known. With the UID of the report, you can get the PDF stream
$MyPDFReportUID = $MyData.Items[0].ObjectModelItemUid
The token is passed again because the web application can output the report in a separate frame.
For PrintReportExt, all parameters must be specified.
$Token = "june5Token=" + [System.Web.HttpUtility]::UrlEncode($MyJUNE5.Token)
$Uid = "&#x26;uid=" + $MyPDFReportUid
$From = "&#x26;from=2022-05-01T00:00:00.000"
$To = "&#x26;to=2022-06-01T00:00:00.000"
$widthIntervall = "&#x26;widthIntervall=60"
$filterName = "&#x26;filterName="
$isPlantFilter = "&#x26;isPlantFilter=true"
$Uri = $Base + "ViewModel/PrintReportExt?" + $Token + $Uid + $From + $To + $widthIntervall + $filterName + $isPlantFilter
Write-Host -ForegroundColor Yellow "Step 3: Get PDF stream and write to file if necessary"
Write directly as file
$MyStream = Invoke-RestMethod -Uri $Uri -Method Get -Headers @{"June5-Token" = $MyJUNE5.Token} -OutFile ".\MyReport2.pdf"
</code></pre></td></tr></tbody></table>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.videc.de/june5-3.7/en/web-api/web-api-client-code-beispiele/powershell-code-beispiele.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
