{"id":3874,"date":"2014-01-10T15:17:09","date_gmt":"2014-01-10T14:17:09","guid":{"rendered":"http:\/\/contoso.se\/blog\/?p=3874"},"modified":"2014-01-10T15:22:55","modified_gmt":"2014-01-10T14:22:55","slug":"copy-or-rename-a-sma-runbook","status":"publish","type":"post","link":"http:\/\/contoso.se\/blog\/?p=3874","title":{"rendered":"Copy or rename a SMA runbook"},"content":{"rendered":"<p>You may have notice that in the Windows Azure portal there is no way to copy or rename a SMA runbook. But it is of course possible with a small Powershell script. The script in this blog post will copy a source SMA runbook and store all settings in a new SMA runbook. The script will also import the new runbook and delete the old one. You can comment (#) the last part if you just want to copy your source runbook and not delete it. If you keep the last part, delete source runbook, then the result of the script will be a rename of the runbook.<\/p>\n<p><code><br \/>\n$path = \"C:\\temp\"<br \/>\n$targetrunbookname = \"newdebugexample\"<br \/>\n$sourcerunbookname = \"debugexample\"<br \/>\n$WebServiceEndpoint = \"https:\/\/wap01\"<br \/>\n##<br \/>\n## Get source runbook<br \/>\n##<br \/>\n$sourcesettings = Get-SmaRunbook -WebServiceEndpoint $WebServiceEndpoint -Name $sourcerunbookname<br \/>\n$source = Get-SmaRunbookDefinition -WebServiceEndpoint $WebServiceEndpoint -name $sourcerunbookname -Type Published<br \/>\n##<br \/>\n## Create the new runbook as a file with source workflow and replace workflow name<br \/>\n##<br \/>\nNew-item $path\\$targetrunbookname.ps1 -type file<br \/>\nadd-content -path $path\\$targetrunbookname.ps1 $source.content<br \/>\n$word = \"workflow $sourcerunbookname\"<br \/>\n$replacement = \"workflow $targetrunbookname\"<br \/>\n$text = get-content $path\\$targetrunbookname.ps1<br \/>\n$newText = $text -replace $word,$replacement<br \/>\n$newText &gt; $path\\$targetrunbookname.ps1<br \/>\n##<br \/>\n## Import new runbook to SMA and set runbook configuration<br \/>\n##<br \/>\nImport-SMArunbook -WebServiceEndpoint $WebServiceEndpoint -Path $path\\$targetrunbookname.ps1 -Tags $sourcesettings.Tags<br \/>\nSet-SmaRunbookConfiguration -WebServiceEndpoint $WebServiceEndpoint -Name $targetrunbookname -LogDebug $sourcesettings.LogDebug -LogVerbose $sourcesettings.LogVerbose -LogProgress $sourcesettings.LogProgress -Description $sourcesettings.Description<br \/>\n##<br \/>\n## Delete sourcerunbook<br \/>\n##<br \/>\nRemove-SmaRunbook -WebServiceEndpoint $WebServiceEndpoint -name $sourcerunbookname -Confirm:$false<\/code><\/p>\n<p>Note that this is provided \u00e2\u20ac\u0153AS-IS\u00e2\u20ac\u009d with no warranties at all. This is not a production ready solution, just an idea and an example.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You may have notice that in the Windows Azure portal there is no way to copy or rename a SMA runbook. But it is of course possible with a small Powershell script. The script in this blog post will copy a source SMA runbook and store all settings in a new SMA runbook. The script &hellip; <a href=\"http:\/\/contoso.se\/blog\/?p=3874\">Continue reading <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":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[13,62],"tags":[],"_links":{"self":[{"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3874"}],"collection":[{"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3874"}],"version-history":[{"count":6,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3874\/revisions"}],"predecessor-version":[{"id":3880,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3874\/revisions\/3880"}],"wp:attachment":[{"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3874"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3874"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3874"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}