{"id":1431,"date":"2019-11-22T12:49:12","date_gmt":"2019-11-22T10:49:12","guid":{"rendered":"https:\/\/www.provisior.nl\/techblog\/?p=1431"},"modified":"2019-11-22T14:29:19","modified_gmt":"2019-11-22T12:29:19","slug":"storing-credentials-safely-with-powershell","status":"publish","type":"post","link":"https:\/\/www.provisior.nl\/techblog\/2019\/11\/22\/storing-credentials-safely-with-powershell\/","title":{"rendered":"Storing credentials safely with PowerShell"},"content":{"rendered":"<p>When you do a lot of automation at one point you will run into the situation that you need credentials for accessing some application or API. Obviously you don&#8217;t want to store those credentials somewhere in plain text. With PowerShell, one way to store sensitive data in a secure way is to store them encrypted in a text file. Using an example I will explain how this can be done very easily using PowerShell.<\/p>\n<h4>Store credentials<\/h4>\n<p>First we need to store the data encrypted, for instance a password.<\/p>\n<pre><code>$password = \"&lt;some_password&gt;\" | ConvertTo-SecureString -AsPlainText -Force\r\n$password | ConvertFrom-SecureString | Set-Content \"&lt;some_filepath&gt;\"<\/code><\/pre>\n<p>The ConvertFrom-SecureString and ConvertTo-SecureString cmdlets use DPAPI (Windows Data Protection API) for encrypting and decrypting data. So when you store the credentials using the Service account Provisior uses, then only the Service account can be used to retrieve the credentials. <\/p>\n<h4>Retrieve credentials<\/h4>\n<p>To retrieve the credentials from the text file, you simply do this:<\/p>\n<pre><code>$password = Get-Content \"&lt;some_filepath&gt;\" | ConvertTo-SecureString<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>When you do a lot of automation at one point you will run into the situation that you need credentials for accessing some application or API. Obviously you don&#8217;t want to store those credentials somewhere in plain text. With PowerShell, one way to store sensitive data in a secure way<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[92,111,112,97],"class_list":["post-1431","post","type-post","status-publish","format-standard","hentry","category-provisior","tag-automation","tag-credentials","tag-encryption","tag-powershell"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Storing credentials safely with PowerShell - Provisior Tech Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.provisior.nl\/techblog\/2019\/11\/22\/storing-credentials-safely-with-powershell\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Storing credentials safely with PowerShell - Provisior Tech Blog\" \/>\n<meta property=\"og:description\" content=\"When you do a lot of automation at one point you will run into the situation that you need credentials for accessing some application or API. Obviously you don&#8217;t want to store those credentials somewhere in plain text. With PowerShell, one way to store sensitive data in a secure way\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.provisior.nl\/techblog\/2019\/11\/22\/storing-credentials-safely-with-powershell\/\" \/>\n<meta property=\"og:site_name\" content=\"Provisior Tech Blog\" \/>\n<meta property=\"article:published_time\" content=\"2019-11-22T10:49:12+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-11-22T12:29:19+00:00\" \/>\n<meta name=\"author\" content=\"Stefan Krul-Donkersloot\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Stefan Krul-Donkersloot\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.provisior.nl\\\/techblog\\\/2019\\\/11\\\/22\\\/storing-credentials-safely-with-powershell\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.provisior.nl\\\/techblog\\\/2019\\\/11\\\/22\\\/storing-credentials-safely-with-powershell\\\/\"},\"author\":{\"name\":\"Stefan Krul-Donkersloot\",\"@id\":\"https:\\\/\\\/www.provisior.nl\\\/techblog\\\/#\\\/schema\\\/person\\\/a43e8689cceb46a716db67f06fee6877\"},\"headline\":\"Storing credentials safely with PowerShell\",\"datePublished\":\"2019-11-22T10:49:12+00:00\",\"dateModified\":\"2019-11-22T12:29:19+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.provisior.nl\\\/techblog\\\/2019\\\/11\\\/22\\\/storing-credentials-safely-with-powershell\\\/\"},\"wordCount\":147,\"commentCount\":0,\"keywords\":[\"Automation\",\"Credentials\",\"Encryption\",\"PowerShell\"],\"articleSection\":[\"Provisior\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.provisior.nl\\\/techblog\\\/2019\\\/11\\\/22\\\/storing-credentials-safely-with-powershell\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.provisior.nl\\\/techblog\\\/2019\\\/11\\\/22\\\/storing-credentials-safely-with-powershell\\\/\",\"url\":\"https:\\\/\\\/www.provisior.nl\\\/techblog\\\/2019\\\/11\\\/22\\\/storing-credentials-safely-with-powershell\\\/\",\"name\":\"Storing credentials safely with PowerShell - Provisior Tech Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.provisior.nl\\\/techblog\\\/#website\"},\"datePublished\":\"2019-11-22T10:49:12+00:00\",\"dateModified\":\"2019-11-22T12:29:19+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.provisior.nl\\\/techblog\\\/#\\\/schema\\\/person\\\/a43e8689cceb46a716db67f06fee6877\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.provisior.nl\\\/techblog\\\/2019\\\/11\\\/22\\\/storing-credentials-safely-with-powershell\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.provisior.nl\\\/techblog\\\/2019\\\/11\\\/22\\\/storing-credentials-safely-with-powershell\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.provisior.nl\\\/techblog\\\/2019\\\/11\\\/22\\\/storing-credentials-safely-with-powershell\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.provisior.nl\\\/techblog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Storing credentials safely with PowerShell\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.provisior.nl\\\/techblog\\\/#website\",\"url\":\"https:\\\/\\\/www.provisior.nl\\\/techblog\\\/\",\"name\":\"Provisior Tech Blog\",\"description\":\"Blogs to help you get the best out of Provisior, the leading Self-service and Automation platform.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.provisior.nl\\\/techblog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.provisior.nl\\\/techblog\\\/#\\\/schema\\\/person\\\/a43e8689cceb46a716db67f06fee6877\",\"name\":\"Stefan Krul-Donkersloot\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/1b2f0b419a9fee792d6a39c1a7bc92b84a848dc7859123a556058736b6481ea7?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/1b2f0b419a9fee792d6a39c1a7bc92b84a848dc7859123a556058736b6481ea7?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/1b2f0b419a9fee792d6a39c1a7bc92b84a848dc7859123a556058736b6481ea7?s=96&d=mm&r=g\",\"caption\":\"Stefan Krul-Donkersloot\"},\"sameAs\":[\"https:\\\/\\\/www.provisior.com\"],\"url\":\"https:\\\/\\\/www.provisior.nl\\\/techblog\\\/author\\\/stefanprovisior\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Storing credentials safely with PowerShell - Provisior Tech Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.provisior.nl\/techblog\/2019\/11\/22\/storing-credentials-safely-with-powershell\/","og_locale":"en_US","og_type":"article","og_title":"Storing credentials safely with PowerShell - Provisior Tech Blog","og_description":"When you do a lot of automation at one point you will run into the situation that you need credentials for accessing some application or API. Obviously you don&#8217;t want to store those credentials somewhere in plain text. With PowerShell, one way to store sensitive data in a secure way","og_url":"https:\/\/www.provisior.nl\/techblog\/2019\/11\/22\/storing-credentials-safely-with-powershell\/","og_site_name":"Provisior Tech Blog","article_published_time":"2019-11-22T10:49:12+00:00","article_modified_time":"2019-11-22T12:29:19+00:00","author":"Stefan Krul-Donkersloot","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Stefan Krul-Donkersloot","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.provisior.nl\/techblog\/2019\/11\/22\/storing-credentials-safely-with-powershell\/#article","isPartOf":{"@id":"https:\/\/www.provisior.nl\/techblog\/2019\/11\/22\/storing-credentials-safely-with-powershell\/"},"author":{"name":"Stefan Krul-Donkersloot","@id":"https:\/\/www.provisior.nl\/techblog\/#\/schema\/person\/a43e8689cceb46a716db67f06fee6877"},"headline":"Storing credentials safely with PowerShell","datePublished":"2019-11-22T10:49:12+00:00","dateModified":"2019-11-22T12:29:19+00:00","mainEntityOfPage":{"@id":"https:\/\/www.provisior.nl\/techblog\/2019\/11\/22\/storing-credentials-safely-with-powershell\/"},"wordCount":147,"commentCount":0,"keywords":["Automation","Credentials","Encryption","PowerShell"],"articleSection":["Provisior"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.provisior.nl\/techblog\/2019\/11\/22\/storing-credentials-safely-with-powershell\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.provisior.nl\/techblog\/2019\/11\/22\/storing-credentials-safely-with-powershell\/","url":"https:\/\/www.provisior.nl\/techblog\/2019\/11\/22\/storing-credentials-safely-with-powershell\/","name":"Storing credentials safely with PowerShell - Provisior Tech Blog","isPartOf":{"@id":"https:\/\/www.provisior.nl\/techblog\/#website"},"datePublished":"2019-11-22T10:49:12+00:00","dateModified":"2019-11-22T12:29:19+00:00","author":{"@id":"https:\/\/www.provisior.nl\/techblog\/#\/schema\/person\/a43e8689cceb46a716db67f06fee6877"},"breadcrumb":{"@id":"https:\/\/www.provisior.nl\/techblog\/2019\/11\/22\/storing-credentials-safely-with-powershell\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.provisior.nl\/techblog\/2019\/11\/22\/storing-credentials-safely-with-powershell\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.provisior.nl\/techblog\/2019\/11\/22\/storing-credentials-safely-with-powershell\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.provisior.nl\/techblog\/"},{"@type":"ListItem","position":2,"name":"Storing credentials safely with PowerShell"}]},{"@type":"WebSite","@id":"https:\/\/www.provisior.nl\/techblog\/#website","url":"https:\/\/www.provisior.nl\/techblog\/","name":"Provisior Tech Blog","description":"Blogs to help you get the best out of Provisior, the leading Self-service and Automation platform.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.provisior.nl\/techblog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.provisior.nl\/techblog\/#\/schema\/person\/a43e8689cceb46a716db67f06fee6877","name":"Stefan Krul-Donkersloot","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/1b2f0b419a9fee792d6a39c1a7bc92b84a848dc7859123a556058736b6481ea7?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/1b2f0b419a9fee792d6a39c1a7bc92b84a848dc7859123a556058736b6481ea7?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1b2f0b419a9fee792d6a39c1a7bc92b84a848dc7859123a556058736b6481ea7?s=96&d=mm&r=g","caption":"Stefan Krul-Donkersloot"},"sameAs":["https:\/\/www.provisior.com"],"url":"https:\/\/www.provisior.nl\/techblog\/author\/stefanprovisior\/"}]}},"_links":{"self":[{"href":"https:\/\/www.provisior.nl\/techblog\/wp-json\/wp\/v2\/posts\/1431","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.provisior.nl\/techblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.provisior.nl\/techblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.provisior.nl\/techblog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.provisior.nl\/techblog\/wp-json\/wp\/v2\/comments?post=1431"}],"version-history":[{"count":7,"href":"https:\/\/www.provisior.nl\/techblog\/wp-json\/wp\/v2\/posts\/1431\/revisions"}],"predecessor-version":[{"id":1438,"href":"https:\/\/www.provisior.nl\/techblog\/wp-json\/wp\/v2\/posts\/1431\/revisions\/1438"}],"wp:attachment":[{"href":"https:\/\/www.provisior.nl\/techblog\/wp-json\/wp\/v2\/media?parent=1431"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.provisior.nl\/techblog\/wp-json\/wp\/v2\/categories?post=1431"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.provisior.nl\/techblog\/wp-json\/wp\/v2\/tags?post=1431"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}