{"id":3338,"date":"2019-11-18T16:26:04","date_gmt":"2019-11-18T15:26:04","guid":{"rendered":"https:\/\/www.lieben.nu\/liebensraum\/?p=3338"},"modified":"2019-11-18T16:26:04","modified_gmt":"2019-11-18T15:26:04","slug":"using-runbooks-interactively-in-powerapps","status":"publish","type":"post","link":"https:\/\/lieben.nu\/liebensraum\/2019\/11\/using-runbooks-interactively-in-powerapps\/","title":{"rendered":"Using runbooks interactively in PowerApps (Build your own app in < 10 minutes!)"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"360\" src=\"https:\/\/www.lieben.nu\/liebensraum\/wp-content\/uploads\/2019\/11\/OM9r2L.gif\" alt=\"\" class=\"wp-image-3349\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Mostly, the users of my PowerShell scripts are themselves PowerShell users. Sometimes though, the audience is less tech-savvy. In this blog post (with my first EVER video tutorial!) I&#8217;ll show you how to give your users a super user friendly interface to your scripts: Microsoft PowerApps. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You&#8217;ll need a<a href=\"https:\/\/docs.microsoft.com\/en-us\/power-platform\/admin\/pricing-billing-skus\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" PowerApps trial or license (opens in a new tab)\"> PowerApps trial or license<\/a> to follow this tutorial.<\/p>\n\n\n\n<figure class=\"wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"Capturing Azure runbook output in a PowerApp\" width=\"474\" height=\"267\" src=\"https:\/\/www.youtube.com\/embed\/m9t29Le2ox8?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">When you use the Azure AD group that was created to publish your app to when it is ready for distribution, your users will automatically be granted the correct permissions in Azure to start a runbook, as PowerApps does not use its own identity when interacting with connectors, it impersonates the user identity.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The source code for the runbook is:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: powershell; auto-links: false; title: ; notranslate\" title=\"\">\nParam(\n    &#x5B;String]$searchParameter\n)\n\n$uri = &quot;https:\/\/techcommunity.microsoft.com\/t5\/forums\/searchpage\/tab\/message?advanced=false&amp;allow_punctuation=false&amp;q=$searchParameter&quot;\n\nStart-Sleep -s 2\n\nWrite-Output &quot;Runbook started, searching for $searchParameter...&quot;\n\n$res = Invoke-WebRequest -Uri $uri -UseBasicParsing -Method GET -ErrorAction Stop\n\nStart-Sleep -s 2\n\nWrite-Output &quot;found some results, analyzing....&quot;\n\n$firstHit = $res.Links | where-object {$_.outerHTML -like &quot;*lia-link-navigation*&quot; -and $_.href -like &quot;\/t5\/*&quot;} | select href -First 1 -ExpandProperty href\n$firstHit = &quot;https:\/\/techcommunity.microsoft.com\/$firstHit&quot;\n\nStart-Sleep -s 2\n\nWrite-Output &quot;Retrieving first 100 characters of first result...&quot;\n\n$res = Invoke-WebRequest -Uri $firstHit -UseBasicParsing -Method GET -ErrorAction Stop\n$excerpt = $res.Content.Substring(($res.Content.IndexOf(&quot;class=`&quot;lia-message-body-content`&quot;&quot;)+64),100) -Replace(&#039;&lt;&#x5B;^&gt;]+&gt;&#039;,&#039;&#039;)\n\nStart-Sleep -s 2\n\nWrite-Output &quot;Result:&quot;\nWrite-Output $excerpt\nwrite-Output &quot;&quot;\nwrite-Output &quot;&quot;\nwrite-Output &quot;&quot;\nwrite-Output &quot;source: $firstHit&quot;\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">The app screen&#8217;s OnStart property&#8217;s function is: <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Set(runbookOutput,Blank());Set(runbookJobId,Blank());Set(runbookActive,false);Set(runbookResult,Blank())<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The search button&#8217;s function is:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Set(runbookResult,Blank());Set(runbookOutput,Blank());Set(runbookJobId,Blank());Set(runbookActive,true);Set(runbookJobId,'new-searchQuery'.Run(TextInput2.Text).jobid)<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The status label&#8217;s function is:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">If(IsBlank(runbookResult) &amp;&amp; runbookActive = false,\" \",If(runbookActive,\"Please wait for job to complete\u2026\",Concatenate(\"Job result: \",runbookResult)))<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The timer OnTimerStart function is:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">If(runbookActive &amp;&amp; Len(runbookJobId) &gt; 5,Set(runbookOutput,'get-searchQueryOutput'.Run(runbookJobId).joboutput))<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The timer OnTimerEnd function is:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">If(runbookActive &amp;&amp; Len(runbookJobId) &gt; 5,Set(runbookResult,'get-searchQueryStatus'.Run(runbookJobId).jobstatus));If(runbookResult = \"Completed\" Or runbookResult = \"Suspended\" Or runbookResult = \"Stopped\",Set(runbookActive,false));<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Mostly, the users of my PowerShell scripts are themselves PowerShell users. Sometimes though, the audience is less tech-savvy. In this blog post (with my first EVER video tutorial!) I&#8217;ll show you how to give your users a super user friendly interface to your scripts: Microsoft PowerApps. You&#8217;ll need a PowerApps trial or license to follow &hellip; <a href=\"https:\/\/lieben.nu\/liebensraum\/2019\/11\/using-runbooks-interactively-in-powerapps\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Using runbooks interactively in PowerApps (Build your own app in < 10 minutes!)<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[4,5,32,37,39],"tags":[],"class_list":["post-3338","post","type-post","status-publish","format-standard","hentry","category-automation","category-azure","category-office-365","category-powerapps","category-powershell"],"_links":{"self":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/posts\/3338","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/comments?post=3338"}],"version-history":[{"count":0,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/posts\/3338\/revisions"}],"wp:attachment":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/media?parent=3338"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/categories?post=3338"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/tags?post=3338"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}