{"id":2182,"date":"2012-04-10T10:40:56","date_gmt":"2012-04-10T14:40:56","guid":{"rendered":"http:\/\/jdhitsolutions.com\/blog\/?p=2182"},"modified":"2012-04-10T10:40:56","modified_gmt":"2012-04-10T14:40:56","slug":"scripting-with-pscredential","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2182\/scripting-with-pscredential\/","title":{"rendered":"Scripting with PSCredential"},"content":{"rendered":"<p>I see this question often: how can I pass a parameter value for a PSCredential that might be a credential object or it might be a user name?  In the past I've used code like this:<\/p>\n<p><code lang=\"PowerShell\"><br \/>\nbegin {<br \/>\n\tWrite-Verbose -Message \"Starting  $($myinvocation.mycommand)\"<br \/>\n\twrite-verbose -Message \"Using volume $($volume.toUpper())\"<br \/>\n\t#convert credential to a PSCredential if a string was passed.<br \/>\n\tif ( $credential -is [system.management.automation.psCredential]) {<br \/>\n\t\tWrite-Verbose \"Using PSCredential for $($credential.username)\"<br \/>\n\t}<br \/>\n\tElseIf ($Credential) {<br \/>\n\t\tWrite-Verbose \"Getting PSCredential for $credential\"<br \/>\n\t\t$Credential=Get-Credential $credential<br \/>\n\t}<br \/>\n} #Begin<br \/>\n<\/code><\/p>\n<p>This assumes $Credential is a parameter. But then I realized, why not take advantage of parameter validation? I could use the [ValidateScript()] parameter attribute and insert some code to test the incoming value. If it is already a PSCredential, don't do anything. But if it is a string, call Get-Credential and use the result.<\/p>\n<p><code lang=\"PowerShell\"><br \/>\nParam (<br \/>\n[Parameter(Position=0)]<br \/>\n[ValidateNotNullorEmpty()]<br \/>\n[string]$Computername=$env:Computername,<br \/>\n[ValidateScript({<br \/>\n  if ($_ -is [System.Management.Automation.PSCredential]) {<br \/>\n    $True<br \/>\n  }<br \/>\n  elseif ($_ -is [string]) {<br \/>\n    $Script:Credential=Get-Credential -Credential $_<br \/>\n    $True<br \/>\n  }<br \/>\n  else {<br \/>\n    Write-Error \"You passed an unexpected object type for the credential.\"<br \/>\n  }<br \/>\n})]<br \/>\n[object]$Credential<br \/>\n<\/code><\/p>\n<p>When using ValidateScript your code has to return True or False. Or you can also Write and error if you want to customize the exception message a bit. That's what I've done here.  With this code I can either use -Credential with a value like jdhitsolutions\\administrator or a saved PSCredential object.  Let me show you a simple script with this in action, plus I'll address another common question about using credentials with WMI-based scripts and functions.<\/p>\n<p><code Lang=\"PowerShell\"><br \/>\n#requires -version 2.0<\/p>\n<p><#\nThis function demonstrates how you might pass a credential\nobject as a parameter\n#><\/p>\n<p>Function Get-OSName {<br \/>\n[cmdletbinding()]<\/p>\n<p>Param (<br \/>\n[Parameter(Position=0)]<br \/>\n[ValidateNotNullorEmpty()]<br \/>\n[string]$Computername=$env:Computername,<br \/>\n[ValidateScript({<br \/>\n  if ($_ -is [System.Management.Automation.PSCredential]) {<br \/>\n    $True<br \/>\n  }<br \/>\n  elseif ($_ -is [string]) {<br \/>\n    $Script:Credential=Get-Credential -Credential $_<br \/>\n    $True<br \/>\n  }<br \/>\n  else {<br \/>\n    Write-Error \"You passed an unexpected object type for the credential.\"<br \/>\n  }<br \/>\n})]<br \/>\n[object]$Credential<\/p>\n<p>)<\/p>\n<p>#Never write the same line of code more than once if you can avoid it<br \/>\n$wmiCommand=\"Get-WmiObject -Class Win32_Operatingsystem -Property Caption,CSName -ComputerName $Computername\"<br \/>\nWrite-Verbose $wmiCommand<\/p>\n<p>if ($Credential) {<br \/>\n    #add the credential to the command string<br \/>\n    Write-Verbose \"Adding credential\"<br \/>\n    #escape the $ sign so that the command uses the variable name<br \/>\n    $wmiCommand+=\" -credential `$Script:Credential\"<br \/>\n}<\/p>\n<p>  Write-Verbose \"Creating a scriptblock from the command string\"<br \/>\n  $sb=[scriptblock]::Create($wmiCommand)<\/p>\n<p>  Try {<br \/>\n      Write-Verbose \"Invoking the command\"<br \/>\n      Invoke-Command -ScriptBlock $sb -errorAction Stop |<br \/>\n      Select @{Name=\"Computername\";Expression={$_.CSName}},<br \/>\n      @{Name=\"OperatingSystem\";Expression={$_.Caption}}<br \/>\n  }<br \/>\n  Catch {<br \/>\n    Write-Warning $_.Exception.Message<br \/>\n  }<br \/>\n  Finally {<br \/>\n    Write-Verbose \"Finished\"<br \/>\n  }<\/p>\n<p>} #close function<br \/>\n<\/code><\/p>\n<p>So the challenge is if I have a credential I need to use a Get-Wmiobject expression that uses it, otherwise run an expression without it. I'm a big believer in avoiding writing the same line of code more than once so I'll create a command <em>string<\/em> with my basic WMI command.<\/p>\n<p><code lang=\"PowerShell\"><br \/>\n$wmiCommand=\"Get-WmiObject -Class Win32_Operatingsystem -Property Caption,CSName -ComputerName $Computername\"<br \/>\n<\/code><\/p>\n<p>In this example the value for $Computername will be expanded and inserted into the string. If no credential is passed then this is the command I'll run. But if a credential is passed, then all I need to do is append it to my command string.<\/p>\n<p><code lang=\"PowerShell\"><br \/>\n$wmiCommand+=\" -credential `$Script:Credential\"<br \/>\n<\/code><\/p>\n<p>You must pay attention to a very subtle detail: I am escaping the $ sign in the variable name. I do not want PowerShell to expand the variable. I want the command string to use the variable as variable. That is, if using a credential I need the command to be: Get-WmiObject -Class Win32_Operatingsystem -Property Caption,CSName -ComputerName SERVER01 -credential $Script:Credential\"<\/p>\n<p>The last step is to turn this command string into a script block so it can be executed.<\/p>\n<p><code lang=\"PowerShell\"><br \/>\n$sb=[scriptblock]::Create($wmiCommand)<br \/>\n<\/code><\/p>\n<p>Armed with a scriptblock I can use Invoke-Command.<\/p>\n<p><code lang=\"PowerShell\"><br \/>\n Invoke-Command -ScriptBlock $sb -errorAction Stop |<br \/>\n Select @{Name=\"Computername\";Expression={$_.CSName}},<br \/>\n @{Name=\"OperatingSystem\";Expression={$_.Caption}}<br \/>\n<\/code><\/p>\n<p>The end result is a function that I can run with no credentials. If I use a credential value like jdhitsolutions\\administrator, I'll get prompted for the password from Get-Credential. Or if I pass a saved credential, the function will use it.<\/p>\n<p>These techniques are by no means the only solution but I find them simple to follow and effective.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I see this question often: how can I pass a parameter value for a PSCredential that might be a credential object or it might be a user name? In the past I&#8217;ve used code like this: begin { Write-Verbose -Message &#8220;Starting $($myinvocation.mycommand)&#8221; write-verbose -Message &#8220;Using volume $($volume.toUpper())&#8221; #convert credential to a PSCredential if a string&#8230;<\/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,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4,62,19],"tags":[32,534,105,82,540,547],"class_list":["post-2182","post","type-post","status-publish","format-standard","hentry","category-powershell","category-security","category-wmi","tag-functions","tag-powershell","tag-pscredential","tag-scriptblock","tag-scripting","tag-wmi"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Scripting with PSCredential &#8226; The Lonely Administrator<\/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:\/\/jdhitsolutions.com\/blog\/powershell\/2182\/scripting-with-pscredential\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Scripting with PSCredential &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"I see this question often: how can I pass a parameter value for a PSCredential that might be a credential object or it might be a user name? In the past I&#039;ve used code like this: begin { Write-Verbose -Message &quot;Starting $($myinvocation.mycommand)&quot; write-verbose -Message &quot;Using volume $($volume.toUpper())&quot; #convert credential to a PSCredential if a string...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/2182\/scripting-with-pscredential\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2012-04-10T14:40:56+00:00\" \/>\n<meta name=\"author\" content=\"Jeffery Hicks\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@JeffHicks\" \/>\n<meta name=\"twitter:site\" content=\"@JeffHicks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jeffery Hicks\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2182\\\/scripting-with-pscredential\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2182\\\/scripting-with-pscredential\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"Scripting with PSCredential\",\"datePublished\":\"2012-04-10T14:40:56+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2182\\\/scripting-with-pscredential\\\/\"},\"wordCount\":424,\"commentCount\":14,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"keywords\":[\"functions\",\"PowerShell\",\"PSCredential\",\"ScriptBlock\",\"Scripting\",\"WMI\"],\"articleSection\":[\"PowerShell\",\"security\",\"WMI\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2182\\\/scripting-with-pscredential\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2182\\\/scripting-with-pscredential\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2182\\\/scripting-with-pscredential\\\/\",\"name\":\"Scripting with PSCredential &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"datePublished\":\"2012-04-10T14:40:56+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2182\\\/scripting-with-pscredential\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2182\\\/scripting-with-pscredential\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2182\\\/scripting-with-pscredential\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"PowerShell\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/powershell\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Scripting with PSCredential\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/\",\"name\":\"The Lonely Administrator\",\"description\":\"Practical Advice for the Automating IT Pro\",\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\",\"name\":\"Jeffery Hicks\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"caption\":\"Jeffery Hicks\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Scripting with PSCredential &#8226; The Lonely Administrator","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:\/\/jdhitsolutions.com\/blog\/powershell\/2182\/scripting-with-pscredential\/","og_locale":"en_US","og_type":"article","og_title":"Scripting with PSCredential &#8226; The Lonely Administrator","og_description":"I see this question often: how can I pass a parameter value for a PSCredential that might be a credential object or it might be a user name? In the past I've used code like this: begin { Write-Verbose -Message \"Starting $($myinvocation.mycommand)\" write-verbose -Message \"Using volume $($volume.toUpper())\" #convert credential to a PSCredential if a string...","og_url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2182\/scripting-with-pscredential\/","og_site_name":"The Lonely Administrator","article_published_time":"2012-04-10T14:40:56+00:00","author":"Jeffery Hicks","twitter_card":"summary_large_image","twitter_creator":"@JeffHicks","twitter_site":"@JeffHicks","twitter_misc":{"Written by":"Jeffery Hicks","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2182\/scripting-with-pscredential\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2182\/scripting-with-pscredential\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"Scripting with PSCredential","datePublished":"2012-04-10T14:40:56+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2182\/scripting-with-pscredential\/"},"wordCount":424,"commentCount":14,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"keywords":["functions","PowerShell","PSCredential","ScriptBlock","Scripting","WMI"],"articleSection":["PowerShell","security","WMI"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/2182\/scripting-with-pscredential\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2182\/scripting-with-pscredential\/","url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2182\/scripting-with-pscredential\/","name":"Scripting with PSCredential &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"datePublished":"2012-04-10T14:40:56+00:00","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2182\/scripting-with-pscredential\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/2182\/scripting-with-pscredential\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2182\/scripting-with-pscredential\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"PowerShell","item":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},{"@type":"ListItem","position":2,"name":"Scripting with PSCredential"}]},{"@type":"WebSite","@id":"https:\/\/jdhitsolutions.com\/blog\/#website","url":"https:\/\/jdhitsolutions.com\/blog\/","name":"The Lonely Administrator","description":"Practical Advice for the Automating IT Pro","publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jdhitsolutions.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9","name":"Jeffery Hicks","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","url":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","caption":"Jeffery Hicks"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg"}}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":1511,"url":"https:\/\/jdhitsolutions.com\/blog\/wmi\/1511\/get-wmi-namespace\/","url_meta":{"origin":2182,"position":0},"title":"Get WMI Namespace","author":"Jeffery Hicks","date":"June 16, 2011","format":false,"excerpt":"PowerShell and WMI just seem to go together like peanut butter and jelly, beer and pretzels, or salt and pepper. However, discovering things about WMI isn't always so easy. There are plenty of tools and scripts that will help you uncover WMI goodness, but here's another one anyway. Today's PowerShell\u2026","rel":"","context":"In &quot;WMI&quot;","block_context":{"text":"WMI","link":"https:\/\/jdhitsolutions.com\/blog\/category\/wmi\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3036,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3036\/test-64-bit-operating-system\/","url_meta":{"origin":2182,"position":1},"title":"Test 64-Bit Operating System","author":"Jeffery Hicks","date":"May 16, 2013","format":false,"excerpt":"One of the great features of PowerShell is how much you can get from a relatively simple one line command. For example. you might want to test if a computer is running a 64-bit operating system. You can find out with a command as simple as this. PS C:\\> (get-wmiobject\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"osarchitecture-fail","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/05\/osarchitecture-fail-1024x298.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/05\/osarchitecture-fail-1024x298.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/05\/osarchitecture-fail-1024x298.png?resize=525%2C300 1.5x"},"classes":[]},{"id":449,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/449\/drive-report-console-chart\/","url_meta":{"origin":2182,"position":2},"title":"Drive Report Console Chart","author":"Jeffery Hicks","date":"October 15, 2009","format":false,"excerpt":"In thinking about some of my recent posts, I realize I should make clear that these scripts and functions are not necessarily good PowerShell examples. They don\u2019t take advantage of objects and the pipeline. They are single purpose and one-dimensional. Not that there\u2019s anything wrong with that. My recent examples,\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"drivereport screenshot","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2009\/10\/drivereport_thumb.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":519,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/519\/get-disk-quota\/","url_meta":{"origin":2182,"position":3},"title":"Get Disk Quota","author":"Jeffery Hicks","date":"November 23, 2009","format":false,"excerpt":"During a recent class I was teaching, a student asked about a way to get disk quota reports from Windows file servers.\u00a0 I knew there was a WMI class, Win32_DiskQuota, and had some old VBScript files. However, they were pretty basic and not as robust as I would have liked.\u2026","rel":"","context":"In &quot;PowerShell v2.0&quot;","block_context":{"text":"PowerShell v2.0","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell-v2-0\/"},"img":{"alt_text":"captured_Image.png","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2009\/11\/captured_Image1.png_thumb1.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":945,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/945\/new-event-report\/","url_meta":{"origin":2182,"position":4},"title":"New Event Report","author":"Jeffery Hicks","date":"September 20, 2010","format":false,"excerpt":"For a number of years I wrote the popular Mr. Roboto column for REDMOND magazine. When I first started the column, many of my scripts were written in VBScript. Then as PowerShell came along that became the preferred tool. Over time I realized there were some VBScripts that could be\u2026","rel":"","context":"In &quot;Mr. Roboto&quot;","block_context":{"text":"Mr. Roboto","link":"https:\/\/jdhitsolutions.com\/blog\/category\/mr-roboto\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3497,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3497\/resolving-sids-with-wmi-wsman-and-powershell\/","url_meta":{"origin":2182,"position":5},"title":"Resolving SIDs with WMI, WSMAN and PowerShell","author":"Jeffery Hicks","date":"October 15, 2013","format":false,"excerpt":"In the world of Windows, an account SID can be a very enigmatic thing. Who is S-1-5-21-2250542124-3280448597-2353175939-1019? Fortunately, many applications, such as the event log viewer resolve the SID to an account name. The downside, is that when you are accessing that same type of information from PowerShell, you end\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"win32_sid-fail","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/10\/win32_sid-fail-1024x330.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/10\/win32_sid-fail-1024x330.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/10\/win32_sid-fail-1024x330.png?resize=525%2C300 1.5x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/2182","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=2182"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/2182\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=2182"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=2182"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=2182"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}