Forum Discussion
Create Power BI Gateway restart Automation script by power shell
- 3 months ago
Happy to help clarify.
From address => This is just the sender name that appears in the email, it doesn't have to be a real mailbox, but it should look professional, just replace [email protected] with your actual company domain, something like [email protected] you can think of it like a "no-reply" email address.To address => You already have this right, just put your admin group email [email protected] there and everyone in that group will receive the alert.
SMTP & Port => Since you're on Office 365, keep smtp.office365.com and port 587 as they are, these are Microsoft's default settings for sending emails securely, nothing to change here.
Credentials => Use your admin account that has an Office 365 mailbox and to avoid the script asking for your password every time it runs, do this once:
Get-Credential | Export-Clixml -Path "C:\Scripts\gateway-cred.xml"
Then swap
(Get-Credential) in the script with:Import-Clixml -Path "C:\Scripts\gateway-cred.xml"You would not need Azure App Registration at all for this setup.
Did it work? 👍 A kudos would be appreciated
🟨 Mark it as a solution to help spread knowledge 💡
Hi Manas0396 ,
Here's how to set up the automation, you would need firstly:
- Admin rights
- PowerShell 5.0+
- Email access (Office 365/SMTP)
Then create a script file such check-gateway.ps1 with this code:
$service = Get-Service -Name "PBIEgwService"
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
if ($service.Status -ne "Running") {
Restart-Service -Name "PBIEgwService" -Force
Send-MailMessage -From "[email protected]" `
-To "[email protected]" `
-Subject "ALERT: Gateway Restarted" `
-Body "Restarted at $timestamp" `
-SmtpServer "smtp.office365.com" `
-Port 587 -UseSsl `
-Credential (Get-Credential)
}
Later, you will need to schedule running that script:
- Open Task Scheduler of windows
- Create Basic Task
- Set trigger: Repeat every 5 minutes
- Set action: Run the PowerShell script
- Run as admin
Did it work? 👍 A kudos would be appreciated
🟨 Mark it as a solution to help spread knowledge 💡
Hi DataVitalizer Thank you for your replay I am admin with have access to powershell in on premises gateway machine I have couple of doubts from above script if you could explain me so I will get easily from my environment and apply this set up.
Send-MailMessage -From "[email protected]" - what is this email and where I can find out
-To "[email protected]" ` - This is our group email like [email protected]
-Subject "ALERT: Gateway Restarted" ` - email subject
-Body "Restarted at $timestamp" ` - email with time
-SmtpServer "smtp.office365.com" ` - what is this smtp.office365.com is it require as it send to [email protected]
-Port 587 -UseSsl `- where I get this port what is this ssl do I need to give these details if yes where find these details
-Credential (Get-Credential)- whom credential I need to provide here
Another thing do I need to do App registration in Azure or not
- DataVitalizer3 months agoSuper User
Happy to help clarify.
From address => This is just the sender name that appears in the email, it doesn't have to be a real mailbox, but it should look professional, just replace [email protected] with your actual company domain, something like [email protected] you can think of it like a "no-reply" email address.To address => You already have this right, just put your admin group email [email protected] there and everyone in that group will receive the alert.
SMTP & Port => Since you're on Office 365, keep smtp.office365.com and port 587 as they are, these are Microsoft's default settings for sending emails securely, nothing to change here.
Credentials => Use your admin account that has an Office 365 mailbox and to avoid the script asking for your password every time it runs, do this once:
Get-Credential | Export-Clixml -Path "C:\Scripts\gateway-cred.xml"
Then swap
(Get-Credential) in the script with:Import-Clixml -Path "C:\Scripts\gateway-cred.xml"You would not need Azure App Registration at all for this setup.
Did it work? 👍 A kudos would be appreciated
🟨 Mark it as a solution to help spread knowledge 💡- Manas03962 months agoFrequent Visitor
Hi v-nmadadi-msft , DataVitalizer I have another doubt can I use my email and password in the Get credential or use admin account O356 mail box like [email protected] and password or something else.