web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Powershell script work...
Power Automate
Answered

Powershell script works, but in PowerAutomate it says syntax error

(0) ShareShare
ReportReport
Posted on by 16

Hi, 

 

I have this script that searches the members of a group to see which  AD accounts are disabled. 

It works perfectly if I run it in Powershell but Power Automate Desktop says it has a syntax error. 

 

Any ideas ? 

Thanks

 

 get-adgroupmember -Identity groupname | %{Get-ADUser -Identity $_.distinguishedName -Properties Enabled | Where-Object{$_.Enabled -ne $true}} | Select name, DistinguishedName,Enabled | Format-Table -Property * -Autosize

 

 

I have the same question (0)
  • Verified answer
    Nived_Nambiar Profile Picture
    18,138 Super User 2026 Season 1 on at

    Hi @BruceR 

     

    I could see you have used % sign in script 

    Nived_Nambiar_0-1682083164854.png

     

    using % in PAD mean you are trying to use variable here, May i know are you passing any variables here, 

  • BruceR Profile Picture
    16 on at

    Hi @Anonymous

     

    actually the % character is an alias for ForEach-Object . 

    But in fact you are correct that the % is the problem.

    I swapped % for ForEach-Object and the script now works. 

     

    Thanks for your help. Where should I report this bug ? 

     

    Kind Regards

     

    Bruce

     

  • BruceR Profile Picture
    16 on at

    I found the Feedback option in PAD. 

    Thanks again 

    Bruce

  • Nived_Nambiar Profile Picture
    18,138 Super User 2026 Season 1 on at

    Hi @BruceR 

     

    It should work when adding %'%'% instead of % only 

     

    Take this example of running this script in PAD

     

    Nived_Nambiar_0-1682085784077.png

     

    Output will be like below

    Nived_Nambiar_1-1682085820180.png

     

     

    In your case, you need to modify script like below

     

    Hope this helps

     

    Mark it as solution if this resolves your query 

     

     

     get-adgroupmember -Identity groupname | %'%'%{Get-ADUser -Identity $_.distinguishedName -Properties Enabled | Where-Object{$_.Enabled -ne $true}} | Select name, DistinguishedName,Enabled | Format-Table -Property * -Autosize

     

  • BruceR Profile Picture
    16 on at

    thanks @Nived_Nambiar I understand it I think now. 

    So this is a clash between the two systems Powershell and PowerAutomate.

    Both use % for different things. 

    I guess it is better to not use Powershell aliases. 

     

    Kind Regards

     

    Bruce

     

     

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Vish WR Profile Picture

Vish WR 386

#2
Valantis Profile Picture

Valantis 342

#3
Haque Profile Picture

Haque 336

Last 30 days Overall leaderboard