{"id":522,"date":"2008-07-21T09:22:32","date_gmt":"2008-07-21T17:22:32","guid":{"rendered":"http:\/\/www.sapien.com\/blog\/2008\/07\/21\/export-pscredential\/"},"modified":"2008-07-21T09:22:32","modified_gmt":"2008-07-21T17:22:32","slug":"export-pscredential","status":"publish","type":"post","link":"https:\/\/dev.sapien.com\/blog\/2008\/07\/21\/export-pscredential\/","title":{"rendered":"Export-PSCredential"},"content":{"rendered":"<p><a href=\"http:\/\/halr9000.com\" target=\"_blank\">Hal Rottenberg<\/a> has put together a very nice set of functions for <a href=\"http:\/\/halr9000.com\/article\/531\" target=\"_blank\">exporting and importing PSCredential<\/a> to a file. The export function takes a PSCredential and serializes it to an XML file. The corresponding import function reconstitutes the PSCredential to an object that you can use. Now before you start freaking out about security, the xml file can only be used by the same user account that created it. <\/p>\n<p>What I like about this is that I can now have multiple credentials easily stored for different computers.&nbsp; I&#8217;m no longer tied to using one credential. First I&#8217;ll export my credentials:<\/p>\n<p><font face=\"Consolas\" color=\"#0000ff\">PS C:\\&gt; export-pscredential -path godot.cred.xml<\/font><\/p>\n<p><font face=\"Consolas\" color=\"#0000ff\">PS C:\\&gt; export-pscredential -path jdhit.cred.xml<\/font><\/p>\n<p>Now I&#8217;ll build an associative array of computernames and their corresponding PSCredential:<\/p>\n<p><font face=\"Consolas\" color=\"#0000ff\">PS C:\\&gt; $sys=@{&#8220;godot&#8221;=(import-pscredential .\\godot.cred.xml);&#8221;jdhit-dc01&#8243;=(import-pscredential .\\jdhit.cred.xml);&#8221;dogtoy&#8221;=(import-pscredential .\\jdhit.cred.xml)}<br \/>PS C:\\scripts\\PoSH&gt; $sys <\/font> <\/p>\n<p><font face=\"Consolas\" color=\"#0000ff\">Name&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; Value<br \/>&#8212;-&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; &#8212;&#8211;<br \/>jdhit-dc01&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.Management.Automation.PSCredential<br \/>godot&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; System.Management.Automation.PSCredential<br \/>dogtoy&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.Management.Automation.PSCredential<\/font>  <\/p>\n<p>Here&#8217;s an example of how I might use this array:<\/p>\n<p><font face=\"Consolas\" color=\"#0000ff\">PS C:\\&gt; $sys.keys | ForEach {gwmi win32_computersystem -computer &#8220;$_&#8221; -cred $sys.item($_)} | Select Name,Manufacturer,Model <\/font> <\/p>\n<p><font face=\"Consolas\" color=\"#0000ff\">Name&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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p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dell Computer Corporation&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Latitude D800<br \/>DOGTOY&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; Dell Computer Corporation&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dimension 8300<\/font><\/p>\n<p>This is a wicked set of functions that are great for unattended automation.  <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hal Rottenberg has put together a very nice set of functions for exporting and importing PSCredential to a file. The export function takes a PSCredential and serializes it to an XML file. The corresponding import function reconstitutes the PSCredential to an object that you can use. Now before you start freaking out about security, the xml file can only be used by the same user account that created it. <\/p>\n<p>What I like about this is that I can now have multiple credentials easily stored for different computers.  I&#8217;m no longer tied to using one credential.<\/p>\n","protected":false},"author":3,"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,"footnotes":""},"categories":[25],"tags":[252,251,253,28,254,57,197],"class_list":["post-522","post","type-post","status-publish","format-standard","hentry","category-windows-powershell","tag-export-clixml","tag-get-credential","tag-import-clixml","tag-powershell","tag-pscredential","tag-scripting","tag-xml"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/522","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/comments?post=522"}],"version-history":[{"count":0,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/522\/revisions"}],"wp:attachment":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/media?parent=522"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/categories?post=522"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/tags?post=522"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}