{"id":15021,"date":"2011-04-03T00:01:00","date_gmt":"2011-04-03T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2011\/04\/03\/discover-which-powershell-providers-support-credentials\/"},"modified":"2011-04-03T00:01:00","modified_gmt":"2011-04-03T00:01:00","slug":"discover-which-powershell-providers-support-credentials","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/discover-which-powershell-providers-support-credentials\/","title":{"rendered":"Discover Which PowerShell Providers Support Credentials"},"content":{"rendered":"<p><b>Summary<\/b>: Microsoft Scripting Guy Ed Wilson shows how to discover which Windows PowerShell providers support credentials.<\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, here. When I was in Redmond, Washington a couple of weeks ago teaching a Windows PowerShell class to a group of Microsoft networking engineers, a question came up about using alternate credentials. For example, the <b>New-Item<\/b> cmdlet has a <i>credential<\/i> parameter. The <b>New-Item<\/b> cmdlet can be used when operating the different PS drives that are supplied with the PS Provider. The cool thing about this is that I should be able to use <b>New-Item<\/b> to create a new file, and I should be able to supply credentials to this operation. This would enable me to create files in locations where the current user did not have rights. <\/p>\n<p>Unfortunately, that exact scenario does not work. I remembered a &ldquo;Lessons Learned&rdquo; sidebar that I wrote in my Microsoft Press book, <a target=\"_blank\" href=\"http:\/\/www.amazon.com\/Windows-PowerShell-2-0-Best-Practices\/dp\/0735626464\/ref=sr_1_1?ie=UTF8&amp;s=books&amp;qid=1255959455&amp;sr=8-1\"><i>Windows PowerShell 2.0 Best Practices<\/i><\/a>, and I referred the student to that page in my book<i>. <\/i>Since then, the question has come up again via the <a href=\"mailto:scripter@microsoft.com\">scripter@microsoft.com<\/a> email alias. <i><\/i>Therefore, I decided to share my sidebar with you here today. <\/p>\n<p>The <i>&ndash;credential<\/i> switch was present in Windows PowerShell 1.0 in only one cmdlet: <b>Get-WmiObject<\/b>.<b> <\/b>This switch allows for the use of alternate credentials when making remote connections. This switch has been added to several cmdlets such as <b>Add-Content<\/b> and <b>Get-Content<\/b>. However, when I tested this by trying to access a file on a remote computer, it came back with the error message shown here. <\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/7080.hsg-4-3-11-1_44FE230B.jpg\"><img decoding=\"async\" height=\"279\" width=\"604\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2703.hsg-4-3-11-1_thumb_3CB9D7A7.jpg\" alt=\"Image of error\" border=\"0\" title=\"Image of error\" style=\"border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px\" \/><\/a><\/p>\n<p>We can investigate this by examining the capabilities of the providers. First we need to see what types of capabilities the providers could support. To do this, we use the <b>GetValues()<\/b> static method from the <b>System.Enum<\/b> .NET Framework class. The <b>GetValues()<\/b> method takes one argument, the name of the .NET Framework class where it is to retrieve the enumeration values. The <b>System.Management.Automation.Provider.ProviderCapabilities<\/b><i> <\/i>class contains the enumeration values that we are interested in. The code that obtains these values is shown here.<\/p>\n<blockquote>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span style=\"font-family:\"><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000;font-size: 10pt\">[enum]::getValues(&ldquo;System.Management.Automation.Provider.ProviderCapabilities&#8221;)<\/span><\/span><\/span><\/p>\n<\/blockquote>\n<p>We obtain the following list of provider capabilities. <\/p>\n<blockquote>\n<p class=\"CodeBlock\" style=\"line-height: 10pt;list-style-type: disc;margin: 4pt 0in 7pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000;font-size: 10pt\">None<\/span><\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"line-height: 10pt;list-style-type: disc;margin: 4pt 0in 7pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000;font-size: 10pt\">Include<\/span><\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"line-height: 10pt;list-style-type: disc;margin: 4pt 0in 7pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000;font-size: 10pt\">Exclude<\/span><\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"line-height: 10pt;list-style-type: disc;margin: 4pt 0in 7pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000;font-size: 10pt\">Filter<\/span><\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"line-height: 10pt;list-style-type: disc;margin: 4pt 0in 7pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000;font-size: 10pt\">ExpandWildcards<\/span><\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"line-height: 10pt;list-style-type: disc;margin: 4pt 0in 7pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000;font-size: 10pt\">ShouldProcess<\/span><\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"line-height: 10pt;list-style-type: disc;margin: 4pt 0in 7pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000;font-size: 10pt\">Credentials<\/span><\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"line-height: 10pt;list-style-type: disc;margin: 4pt 0in 7pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000;font-size: 10pt\">Transactions<\/span><\/span><\/span><\/p>\n<\/blockquote>\n<p>Now that we have a listing of the capabilities available to providers, we need to see which default Windows PowerShell 2.0 providers support the <b>Credentials<\/b> capability. To see this, we can use the <b>Get-PsProvider<\/b> cmdlet. As seen here, none of the default Windows PowerShell 2.0 providers support the use of capabilities. <\/p>\n<blockquote>\n<p class=\"CodeBlock\" style=\"line-height: 10pt;list-style-type: disc;margin: 4pt 0in 7pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000;font-size: 10pt\">Get-PSProvider<\/span><\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"line-height: 10pt;list-style-type: disc;margin: 4pt 0in 7pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000;font-size: 10pt\">Name<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Capabilities<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Drives<\/span><\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"line-height: 10pt;list-style-type: disc;margin: 4pt 0in 7pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000;font-size: 10pt\">&#8212;-<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>&#8212;&#8212;&#8212;&#8212;<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>&#8212;&#8212;<\/span><\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"line-height: 10pt;list-style-type: disc;margin: 4pt 0in 7pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000;font-size: 10pt\">Alias<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>ShouldProcess<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>{Alias}<\/span><\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"line-height: 10pt;list-style-type: disc;margin: 4pt 0in 7pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000;font-size: 10pt\">Environment<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>ShouldProcess<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>{Env}<\/span><\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"line-height: 10pt;list-style-type: disc;margin: 4pt 0in 7pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000;font-size: 10pt\">FileSystem<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Filter, ShouldProcess<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>{C, D, dle, apw&#8230;}<\/span><\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"line-height: 10pt;list-style-type: disc;margin: 4pt 0in 7pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000;font-size: 10pt\">Function<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>ShouldProcess<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>{Function}<\/span><\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"line-height: 10pt;list-style-type: disc;margin: 4pt 0in 7pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000;font-size: 10pt\">Registry<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>ShouldProcess, Transactions<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>{HKLM, HKCU, HKCR}<\/span><\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"line-height: 10pt;list-style-type: disc;margin: 4pt 0in 7pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000;font-size: 10pt\">Variable<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>ShouldProcess<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>{Variable}<\/span><\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"line-height: 10pt;list-style-type: disc;margin: 4pt 0in 7pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000;font-size: 10pt\">Certificate<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>ShouldProcess<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>{cert, certCU}<\/span><\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"line-height: 10pt;list-style-type: disc;margin: 4pt 0in 7pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000;font-size: 10pt\">WSMan<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>None<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>{WSMan}<\/span><\/span><\/span><\/p>\n<\/blockquote>\n<p>I invite you to follow me on <a target=\"_blank\" href=\"http:\/\/bit.ly\/scriptingguystwitter\">Twitter<\/a> and <a target=\"_blank\" href=\"http:\/\/bit.ly\/scriptingguysfacebook\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"mailto:scripter@microsoft.com\">scripter@microsoft.com<\/a>, or post your questions on the <a target=\"_blank\" href=\"http:\/\/bit.ly\/scriptingforum\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p><b>Ed Wilson, Microsoft Scripting Guy<\/b><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Microsoft Scripting Guy Ed Wilson shows how to discover which Windows PowerShell providers support credentials. Microsoft Scripting Guy, Ed Wilson, here. When I was in Redmond, Washington a couple of weeks ago teaching a Windows PowerShell class to a group of Microsoft networking engineers, a question came up about using alternate credentials. For example, [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[51,3,4,61,45],"class_list":["post-15021","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-getting-started","tag-scripting-guy","tag-scripting-techniques","tag-weekend-scripter","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Microsoft Scripting Guy Ed Wilson shows how to discover which Windows PowerShell providers support credentials. Microsoft Scripting Guy, Ed Wilson, here. When I was in Redmond, Washington a couple of weeks ago teaching a Windows PowerShell class to a group of Microsoft networking engineers, a question came up about using alternate credentials. For example, [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/15021","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=15021"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/15021\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=15021"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=15021"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=15021"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}