Add a button to sharepoint that triggers a powershell script

Anonymous
2025-06-23T04:57:31+00:00

Hello Everyone,

I have a backend logic which get user's site details like sites the user is owner of, storage usage details, recycle bin usage details and members in that site. I am sending all this details to the user over mail. I need to do this action in click of a button on sharepoint. Any help is much appreciated!!

To perform this action I am using Azure application with required api permissions, Hosting the script .ps1 on azure runbook.

when users clicks the button it needs to get users UPN as input or dynamically is fine. Please feel free to reply to this if you have any questions.

Thanks!!

Microsoft 365 and Office | SharePoint | For education | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes

5 answers

Sort by: Most helpful
  1. Anonymous
    2025-06-23T06:23:02+00:00

    Hi Abivanth R

    Welcome to Microsoft Community. Thank you for reaching out.

    To better assistance, could you please provide detail information:

    • Are you using SharePoint Online or SharePoint Server (on-premises)?
    • Do you want the button to be added to a modern SharePoint page or a classic page?
    • Should the script run on behalf of the user or just use a service account with delegated permissions?
    • Is the Azure Runbook already configured with a webhook URL, or do you need help setting that up?
    • Are you using Send-MailMessage in PowerShell or Microsoft Graph API to send the email?

    Your detailed response will help us diagnose and resolve the issue more efficiently.  

    Thank you for your cooperation.  

    Best regards,  

    Alex - MSFT | Microsoft Community Support Specialist

    0 comments No comments
  2. Anonymous
    2025-06-23T09:21:14+00:00

    Hi Alex,
    Thanks for your response!

    1.I am using sharepoint online

    1. We need to add the button in modern sharepoint page
    2. Script is running with delegated permissions on a service account.
    3. Not sure about the webhook part, I need help in setting it up. Thanks for bringing it up!
    4. The mail is sent via Microsoft Graph API

    I am a newbie, Any help from you experts are very helpful to me.

    Thanks,

    Abivanth.

    0 comments No comments
  3. Anonymous
    2025-06-26T07:25:42+00:00

    Hi Abivanth,

    Thanks again for your message!

    As a forum moderator at Community Support, which about Basic Microsoft 365. So I do not have enough resources for SharePoint development. That means I don’t have access to advanced tools or coding support.

    I’ve tried my best to guide you through the setup, but building a SharePoint Framework (SPFx) Web Part needs coding and developer tools that go beyond what I can help with directly.

    I recommend you can ask for help in these Microsoft Communities

    Thank you for your cooperation and understanding.

    Warm regards

    Alex - MSFT | Microsoft Community Support Specialist,

    0 comments No comments
  4. Anonymous
    2025-06-24T04:06:46+00:00

    Hi Abivanth,

    Thanks for the detailed follow-up! Based on your providing, I suggest as below:

    Step 1: Create a Webhook for Your Azure Runbook

    Since your script is hosted in an Azure Automation Runbook, you’ll need to create a webhook to trigger it externally.

    1. Go to your Azure Automation Account.
    2. Navigate to Runbooks > select your .ps1 script.
    3. Click Edit > Webhook > Create Webhook.
    4. Copy the webhook URL, it will be used in your SharePoint button. Note: The webhook URL is sensitive. Treat it like a password.

    Step 2: Add a Button to Your Modern SharePoint Page

    You have two options here:

    • Option A: SPFx Web Part (custom development using SharePoint Framework)
    • Option B: Power Automate Button (no-code solution)

    You only need to choose one of these options to add the button.

    Step 3: Modify Your Script to Accept UPN

    Ensure your PowerShell script in the Runbook can accept the UPN as a parameter

    I hope this information is helpful. If you have any difficulties or need further clarification when trying these methods, please feel free to reach out, and we can further investigate the problem together.       

    Thanks for your patience and understanding so far.   

    -------- 

    Please understand that our initial response does not always resolve the issue immediately. However, with your help and more detailed information, we can work together to find a solution.

    Looking forward to hearing from you.         

    Best Regards,

    Alex - MSFT | Microsoft Community Support Specialist

    0 comments No comments
  5. Anonymous
    2025-06-25T06:07:56+00:00

    Hi Alex,

    Thanks for the step by step clarification.

    I can see the logic in a better POV now. But I need to use SPFx Web part to add the button and it is very much confusing. Can you please help me with that too.

    Thanks again for the help!!!

    Regards,

    Abivanth

    0 comments No comments