I have built a Job, using the Job Agent, as well as a SSIS packages within a local Server ( a Replica) using Microsoft SQL Management Studio, the Job has a Powershell script that , that via a REST API ( dot-walking technique) grabs info from ServiceNow and posts the info into a CSV file. This whole system works fine and without any hiccups.
We need to " convert" this methodology into a Power Automate flow ( Cloud flow), the first hiccup I found was, how to have an Action to execute a Powershell script with the PowerAutomate flow, without using Premium connectors, or mechanism whereby I need an expensive Azure subscription.
Could someone help me to find out whether it is possible to create this PowerAutomate flow calling the (Action) a Powershell script?
My Powershell script ( currently working fine. User and password removed) is:
$user = "xxxxxxxxx.scorecard.service"
$pass = "$$$$$$$$$$$$$$$$"
# Build auth header
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user, $pass)))
# Set proper headers
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add('Authorization',('Basic {0}' -f $base64AuthInfo))
$headers.Add('Accept','application/json')
# Specify endpoint uri
$url_base = "https://xxxxxxxxx.service-now.com/api/now/table/x_lsmcb_fm_room"
#$url_endpoint = "?sysparm_query=id=SPL_13-0.020&sysparm_fields=u_specification,u_function,name,id,type.value,display_name,gla,capacity,fm_location.full_name"
# Only non-empty IDs
$url_endpoint = "?sysparm_query=idISNOTEMPTY&sysparm_fields=u_specification,u_function,name,id,type.value,display_name,gla,capacity,fm_location.full_name"
$uri = $url_base + $url_endpoint
# Specify HTTP method
$method = "get"
$contentType = "application/xml"
$ExportFolder = "Filesystem::C:\DBA\scripts\P\Scorecard\"
$ExportFile = "Export_Ruimtes.csv"
$ExportPath = Join-Path $ExportFolder $ExportFile
$Ruimteslist = @()
Function Get-Mobilenummers
{
# Change any TLS protocol
[Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls"
# Invoke-RestMethd to get the Contents
$MN_response = Invoke-RestMethod -Headers $headers -Method $method -Uri $uri -ContentType $contentType
#Loop trough into an ordered hash table
foreach ($item in $MN_response.result)
{
$Ruimteslist = [ARRAY]$Ruimteslist + [PSCustomObject] @{
Naam = $item.'name'
Ruimtenummer = $item.'id'
Type = $item.'type.value'
Vestiging = $item.'fm_location.full_name'
Gebruiksfunctie = $item.'u_function'
Specificatie = $item.'u_specification'
Capaciteit = $item.'capacity'
Vloeroppervlakte = $item.'gla'
Verhuurbaar_oppervlakte = $item.'gla'
Bruto_vloeroppervlakte = 0
}
}
# Return the full hash table
Return $Ruimteslist
}
$Ruimteslijst = Get-Mobilenummers
# Export the list to a CSV file
$Ruimteslijst| ForEach-Object{ [pscustomobject]$_ } | Export-CSV -Path $ExportPath -NoTypeInformation -Delimiter ";" -Encoding utf8 -Force