Skip to main content

Notifications

Community site session details

Community site session details

Session Id : /ky77vVwYiPmGQ1pDyX8x8
Power Automate - General Discussion
Unanswered

Running a Powershell Script in Power Automate

Like (0) ShareShare
ReportReport
Posted on 17 May 2024 09:31:30 by 354

Hello. 

I have a Powershell script which i run daily. 

 

In its simplest form, its just grabbing a whole bunch of power bi workspaces and outputting the data into a .csv file. 

 

I want to automate this process. 

 

I tried using Task Scheduler, however, the problem here is when i run the Powershell script i am using the Connect-PowerBIServiceAccount  & then authenticating with the admin account (as this account has access to retrieve all the workspaces). With task scheudler, i dont know how to run the script without storing the service account password in the script. 

 

 

1. Can i automate this process in Power Automate? - i cant see a Powershell connector. 

2. Or can someone tell me how i can run this as a Task Schedule without storing the admin account in the ps1 script. 

 

Thanks 

  • SudeepGhatakNZ Profile Picture
    14,318 Most Valuable Professional on 22 May 2024 at 20:59:43
    Re: Running a Powershell Script in Power Automate

    Even if you use Power Automate Desktop, you should store the creds in Azure Vault or Windows Credential Manager.

    The Power Sheel script will go something like this

     

    Install-Module -Name 'PSCredentialManager' -Force
    # Import the PSCredentialManager module
    Import-Module -Name 'PSCredentialManager'

    # Define the target name of the credential
    $targetName = "example.com"

    # Retrieve the stored credential
    $credential = Get-StoredCredential -Target $targetName

    if ($credential -ne $null) {
    Write-Host "Username: $($credential.UserName)"
    Write-Host "Password: $($credential.GetNetworkCredential().Password)"
    } else {
    Write-Host "No credential found for target: $targetName"
    }

     

  • Vstar19 Profile Picture
    354 on 22 May 2024 at 09:38:01
    Re: Running a Powershell Script in Power Automate

    Storing in windows credential manager seems like a good solution. I will read more into this. 

     

    If i was to use Power Automate Desktop to run a ps.1 file - would i still have to supply the credentials to PA Desktop?

     

  • SudeepGhatakNZ Profile Picture
    14,318 Most Valuable Professional on 20 May 2024 at 00:14:37
    Re: Running a Powershell Script in Power Automate

    @Vstar19 

    There are several options

    1. To run a PowerShell script with PA, you will need to use Power Automate Desktop

    Solved: Invoke PowerShell script using Power Automate Desk... - Power Platform Community (microsoft.com)

    2. You can also use the cloud flow along with Azure Automation

    Getting started with Azure Automation and Power Automate (youtube.com)

    3. Instead of storing the credentials in script, use the Windows Credential Manager to store your credentials and retrieve them within the script

    # Retrieve credentials from Windows Credential Manager
    $credential = Get-Credential -UserName "PowerBIAutomation" -Message "Enter PowerBI Admin Credentials"

    # Connect to Power BI Service
    Connect-PowerBIServiceAccount -Credential $credential

    4. Use a Service principal instead of Service Account

     Embed Power BI content in an embedded analytics application with service principal and an application secret - Power BI | Microsoft Learn

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,776 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,093 Most Valuable Professional

Leaderboard