{"id":1532,"date":"2011-07-01T09:55:52","date_gmt":"2011-07-01T13:55:52","guid":{"rendered":"http:\/\/jdhitsolutions.com\/blog\/?p=1532"},"modified":"2011-07-01T09:55:52","modified_gmt":"2011-07-01T13:55:52","slug":"get-local-administrators-with-wmi-and-powershell","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/scripting\/1532\/get-local-administrators-with-wmi-and-powershell\/","title":{"rendered":"Get Local Administrators with WMI and PowerShell"},"content":{"rendered":"<p>Earlier this week I was helping someone out on a problem working with the local administrators group. There are a variety of ways to enumerate the members of a local group. The code he was using involved WMI. I hadn't really worked with the WMI approach in any great detail so I thought I'd see how this might work in PowerShell. I ended up with a function to enumerate members of the local administrators group on a computer, as well as test if an account belongs to the group.<!--more--><\/p>\n<p>The first function, Get-LocalAdministrators, will connect to a remote computer (it defaults to the local) and returns an object for each member like this:<\/p>\n<p>[cc lang=\"DOS\"]<br \/>\nName         : LocalAdmins<br \/>\nFullname     :<br \/>\nCaption      : JDHLAB\\LocalAdmins<br \/>\nDescription  :<br \/>\nDomain       : JDHLAB<br \/>\nSID          : S-1-5-21-3957442467-353870018-3926547339-1148<br \/>\nLocalAccount : False<br \/>\nDisabled     :<br \/>\nComputer     : CLIENT1<br \/>\n[\/cc]<\/p>\n<p>If I simply wanted a name, that would be pretty easy and I'd use a different approach. But I wanted richer information so that I could sort out what accounts were local, or disabled. I worked under the assumption that I would query a group of machines and save the data to a CSV file so I could later slice and dice the data. Or work with it further in PowerShell. Here's the function.<\/p>\n<p>[cc lang=\"PowerShell\"]<br \/>\nFunction Get-LocalAdministrators {<\/p>\n<p>[cmdletbinding()]<\/p>\n<p>Param(<br \/>\n[Parameter(Position=0,ValueFromPipeline=$True,ValueFromPipelineByPropertyName=$True)]<br \/>\n[ValidateNotNullorEmpty()]<br \/>\n[string[]]$Computername=$env:computername,<br \/>\n[switch]$AsJob)<\/p>\n<p>Begin {<\/p>\n<p>    Set-StrictMode -Version latest<br \/>\n    Write-Verbose \"Starting $($myinvocation.mycommand)\"<\/p>\n<p>    #define an new array for computernames if this is run as a job<br \/>\n    $computers=@()<br \/>\n}<\/p>\n<p>Process {<br \/>\n    foreach ($computer in $computername) {<br \/>\n     $computers+=$Computer<br \/>\n     $sb={Param([string]$computer=$env:computername)<br \/>\n        Try {<br \/>\n            Write-Verbose \"Querying $computer\"<br \/>\n            $AdminsGroup=Get-WmiObject -Class Win32_Group -computername $Computer -Filter \"SID='S-1-5-32-544' AND LocalAccount='True'\" -errorAction \"Stop\"<br \/>\n            Write-Verbose \"Getting members from $($AdminsGroup.Caption)\" <\/p>\n<p>            $AdminsGroup.GetRelated() | Where {$_.__CLASS -match \"Win32_UserAccount|Win32_Group\"} |<br \/>\n            Select Name,Fullname,Caption,Description,Domain,SID,LocalAccount,Disabled,<br \/>\n            @{Name=\"Computer\";Expression={$Computer.ToUpper()}}<br \/>\n        }<br \/>\n        Catch {<br \/>\n            Write-Warning \"Failed to get administrators group from $computer\"<br \/>\n            Write-Error $_<br \/>\n         }<br \/>\n      } #end scriptblock<br \/>\n      if (!$AsJob) {<br \/>\n        Invoke-Command -ScriptBlock $sb -ArgumentList $computer<br \/>\n      }<br \/>\n     } #foreach computer<br \/>\n} #process <\/p>\n<p> End {<br \/>\n    #create a job is specified<br \/>\n    if ($AsJob) {<br \/>\n     Write-Verbose \"Creating remote job\"<br \/>\n     #create a single job targeted against all the computers. This will execute on each<br \/>\n     #computer remotely<br \/>\n     Invoke-Command -ScriptBlock $sb -ComputerName $computers -asJob<br \/>\n    }<\/p>\n<p>    Write-Verbose \"Ending $($myinvocation.mycommand)\"<br \/>\n}<br \/>\n} #end function<br \/>\n[\/cc]<\/p>\n<p>The main part of the function uses WMI to query the Win32_Group class. Because the group may have been renamed, the filter searches for it by well-known SID.<\/p>\n<p>[cc lang=\"PowerShell\"]<br \/>\n$AdminsGroup=Get-WmiObject -Class Win32_Group -computername $Computer -Filter \"SID='S-1-5-32-544' AND LocalAccount='True'\" -errorAction \"Stop\"\"<br \/>\n[\/cc]<\/p>\n<p>Once the group is found, you could use an Associators Of query to find all the related objects, whcih would include the group members. But Associators Of queries are not easy to construct, assuming you even knew about them. Instead, in PowerShell the WMI object has a method called GetRelated(). This method in essence runs an Associators Of query for you. But obviously this is much easier.<\/p>\n<p>[cc lang=\"PowerShell\"]<br \/>\n$AdminsGroup.GetRelated() | Where {$_.__CLASS -match \"Win32_UserAccount|Win32_Group\"} |<br \/>\n Select Name,Fullname,Caption,Description,Domain,SID,LocalAccount,Disabled,<br \/>\n @{Name=\"Computer\";Expression={$Computer.ToUpper()}}<br \/>\n[\/cc]<\/p>\n<p>The method allows you to specify a resultant class as a parameter, but it doesn't speed up the process. It only filters the output. So I didn't bother and instead piped the results to Where-Object to get user and group accounts. I also select a few key properties to write to the pipeline. This query takes a little time to run and there isn't any way to speed it up. Although I have something to alleviate the pain.<\/p>\n<p>I decided this would be a good reason to use a background job. So I included a function parameter to run the entire command as a job. You'll notice that in the process block I'm creating a script block.<\/p>\n<p>[cc lang=\"PowerShell\"]<br \/>\nProcess {<br \/>\n    foreach ($computer in $computername) {<br \/>\n     $computers+=$Computer<br \/>\n     $sb={Param([string]$computer=$env:computername)<br \/>\n        Try {<br \/>\n[\/cc]<\/p>\n<p>The script block takes a computername as a parameter. If I'm running the command normally (ie no job), then the script block executes for each computer passed as a parameter or piped in.<\/p>\n<p>[cc lang=\"PowerShell\"]<br \/>\nif (!$AsJob) {<br \/>\n        Invoke-Command -ScriptBlock $sb -ArgumentList $computer<br \/>\n      }<br \/>\n[\/cc]<\/p>\n<p>The command runs locally and queries the remote computer. But if I decide to run this as a job, I wait until the End scriptblock since I wanted to create one job. In order for this to work, I need to keep track of all the pipelined computer names so I keep adding them to $computers in the Process script block. After I've built the list, I again use Invoke-Command, but this time I also specify that the command runs ON the remote machines.<\/p>\n<p>[cc lang=\"PowerShell\"]<br \/>\nif ($AsJob) {<br \/>\n     Write-Verbose \"Creating remote job\"<br \/>\n     #create a single job targeted against all the computers. This will execute on each<br \/>\n     #computer remotely<br \/>\n     Invoke-Command -ScriptBlock $sb -ComputerName $computers -asJob<br \/>\n    }<br \/>\n[\/cc]<\/p>\n<p>The end result is a job created locally with child jobs that run on all the computers specified. This allows me to keep working in PowerShell, and get the results when I want. Because the command is executing simultaneously it runs a little faster overall. I realize the WMI queries aren't the speediest, but I end up with valuable information.<\/p>\n<p>The other function is a simple test: does this account belong to the administrators group?<\/p>\n<p>[cc lang=\"PowerShell\"]<br \/>\nFunction Test-IsLocalAdministrator {<\/p>\n<p>[cmdletbinding()]<\/p>\n<p>Param(<br \/>\n[Parameter(Position=0,HelpMessage=\"Enter a user or group name in the domain\\username format\")]<br \/>\n[ValidatePattern(\"\\w+\\\\\\w+\")]<br \/>\n[string]$Name=\"$env:userdomain\\$env:username\",<br \/>\n[Parameter(Position=1)]<br \/>\n[ValidateNotNullorEmpty()]<br \/>\n[string]$Computername=$env:computername<br \/>\n)<\/p>\n<p>Set-StrictMode -Version latest<\/p>\n<p>Write-Verbose \"Starting $($myinvocation.mycommand)\"<br \/>\n#Split Name into domain and name parts<br \/>\n$Domain=$Name.Split(\"\\\")[0]<br \/>\n$Member=$Name.Split(\"\\\")[1]<\/p>\n<p>Try {<br \/>\n    Write-Verbose \"Querying $computername\"<\/p>\n<p>    $AdminsGroup=Get-WmiObject -Class Win32_Group -computername $Computername -Filter \"SID='S-1-5-32-544' AND LocalAccount='True'\" -errorAction \"Stop\"<br \/>\n    Write-Verbose \"Getting members from $($AdminsGroup.Caption)\"<br \/>\n    Write-Verbose \"Testing $($name.ToUpper())\"<br \/>\n    $Found=$AdminsGroup.GetRelationships(\"Win32_GroupUser\") | Where {$_.PartComponent -match \"Domain=\"\"$Domain\"\",Name=\"\"$Member\"\"\"}<\/p>\n<p>    If ($found) {<br \/>\n        Write $True<br \/>\n    }<br \/>\n    else {<br \/>\n        Write $False<br \/>\n    }<br \/>\n}<br \/>\nCatch {<br \/>\n    Write-Warning \"Failed to get administrators group from $computername\"<br \/>\n    Write-Error $_<br \/>\n }<\/p>\n<p>Finally {<br \/>\n    Write-Verbose \"Ending $($myinvocation.mycommand)\"<br \/>\n}<\/p>\n<p>} #end function<br \/>\n[\/cc]<\/p>\n<p>Here I took a slightly different approach. I still get the admins group with the same WMI query. But this time I use the GetRelationships() method which is a .NET equivalent of a References WMI query.<\/p>\n<p>[cc lang=\"PowerShell\"]<br \/>\n  $Found=$AdminsGroup.GetRelationships(\"Win32_GroupUser\") | Where {$_.PartComponent -match \"Domain=\"\"$Domain\"\",Name=\"\"$Member\"\"\"}<br \/>\n[\/cc]<\/p>\n<p>This type of query is quick, at least for groups and returns WMI paths of related objects. All I have to do is parse the PartComponent property and use a regular expression match to see if the domain and account name match. You have to specify the name in domain\\name format. If $found exists, the function writes $True. I think Test functions should be simple, quick and concise.<\/p>\n<p>These functions have limited error handling and don't support alternate credentials, although you could certainly add that. I'll be the first to admit that these may not be the best ways to achieve these results, but they are viable options and I am happy with the way I incorporated support for background jobs in the function.<\/p>\n<p>If you would like to try these out, download <a href='http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/07\/get-wmiadmin.txt' target='_blank'>get-wmiadmin.ps1<\/a> and load the functions into your PowerShell session.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Earlier this week I was helping someone out on a problem working with the local administrators group. There are a variety of ways to enumerate the members of a local group. The code he was using involved WMI. I hadn&#8217;t really worked with the WMI approach in any great detail so I thought I&#8217;d see&#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":[75,8,19],"tags":[300,32,103,122,202,534,540,547],"class_list":["post-1532","post","type-post","status-publish","format-standard","hentry","category-powershell-v2-0","category-scripting","category-wmi","tag-administrators","tag-functions","tag-get-wmiobject","tag-invoke-command","tag-jobs","tag-powershell","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>Get Local Administrators with WMI and PowerShell &#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\/scripting\/1532\/get-local-administrators-with-wmi-and-powershell\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Get Local Administrators with WMI and PowerShell &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"Earlier this week I was helping someone out on a problem working with the local administrators group. There are a variety of ways to enumerate the members of a local group. The code he was using involved WMI. I hadn&#039;t really worked with the WMI approach in any great detail so I thought I&#039;d see...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/scripting\/1532\/get-local-administrators-with-wmi-and-powershell\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2011-07-01T13:55:52+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=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/1532\\\/get-local-administrators-with-wmi-and-powershell\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/1532\\\/get-local-administrators-with-wmi-and-powershell\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"Get Local Administrators with WMI and PowerShell\",\"datePublished\":\"2011-07-01T13:55:52+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/1532\\\/get-local-administrators-with-wmi-and-powershell\\\/\"},\"wordCount\":1240,\"commentCount\":12,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"keywords\":[\"Administrators\",\"functions\",\"Get-WMIObject\",\"Invoke-Command\",\"Jobs\",\"PowerShell\",\"Scripting\",\"WMI\"],\"articleSection\":[\"PowerShell v2.0\",\"Scripting\",\"WMI\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/1532\\\/get-local-administrators-with-wmi-and-powershell\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/1532\\\/get-local-administrators-with-wmi-and-powershell\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/1532\\\/get-local-administrators-with-wmi-and-powershell\\\/\",\"name\":\"Get Local Administrators with WMI and PowerShell &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"datePublished\":\"2011-07-01T13:55:52+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/1532\\\/get-local-administrators-with-wmi-and-powershell\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/1532\\\/get-local-administrators-with-wmi-and-powershell\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/1532\\\/get-local-administrators-with-wmi-and-powershell\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"PowerShell v2.0\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/powershell-v2-0\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Get Local Administrators with WMI and PowerShell\"}]},{\"@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":"Get Local Administrators with WMI and PowerShell &#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\/scripting\/1532\/get-local-administrators-with-wmi-and-powershell\/","og_locale":"en_US","og_type":"article","og_title":"Get Local Administrators with WMI and PowerShell &#8226; The Lonely Administrator","og_description":"Earlier this week I was helping someone out on a problem working with the local administrators group. There are a variety of ways to enumerate the members of a local group. The code he was using involved WMI. I hadn't really worked with the WMI approach in any great detail so I thought I'd see...","og_url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/1532\/get-local-administrators-with-wmi-and-powershell\/","og_site_name":"The Lonely Administrator","article_published_time":"2011-07-01T13:55:52+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":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/1532\/get-local-administrators-with-wmi-and-powershell\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/1532\/get-local-administrators-with-wmi-and-powershell\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"Get Local Administrators with WMI and PowerShell","datePublished":"2011-07-01T13:55:52+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/1532\/get-local-administrators-with-wmi-and-powershell\/"},"wordCount":1240,"commentCount":12,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"keywords":["Administrators","functions","Get-WMIObject","Invoke-Command","Jobs","PowerShell","Scripting","WMI"],"articleSection":["PowerShell v2.0","Scripting","WMI"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/scripting\/1532\/get-local-administrators-with-wmi-and-powershell\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/1532\/get-local-administrators-with-wmi-and-powershell\/","url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/1532\/get-local-administrators-with-wmi-and-powershell\/","name":"Get Local Administrators with WMI and PowerShell &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"datePublished":"2011-07-01T13:55:52+00:00","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/1532\/get-local-administrators-with-wmi-and-powershell\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/scripting\/1532\/get-local-administrators-with-wmi-and-powershell\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/1532\/get-local-administrators-with-wmi-and-powershell\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"PowerShell v2.0","item":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell-v2-0\/"},{"@type":"ListItem","position":2,"name":"Get Local Administrators with WMI and PowerShell"}]},{"@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":2338,"url":"https:\/\/jdhitsolutions.com\/blog\/wmi\/2338\/query-local-administrators-with-wmi\/","url_meta":{"origin":1532,"position":0},"title":"Query Local Administrators with WMI","author":"Jeffery Hicks","date":"May 23, 2012","format":false,"excerpt":"I have a quick post today on using WMI to list members of the local administrators group. It is very simple to get the group itself with the Win32_Group class. PS S:\\> get-wmiobject win32_group -filter \"name='Administrators'\" Caption Domain Name SID ------- ------ ---- --- SERENITY\\Adminis... SERENITY Administrators S-1-5-32-544 But the\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":2342,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/2342\/query-local-administrators-with-cim\/","url_meta":{"origin":1532,"position":1},"title":"Query Local Administrators with CIM","author":"Jeffery Hicks","date":"May 24, 2012","format":false,"excerpt":"Yesterday I posted an article on listing members of the local administrators group with PowerShell and Get-WmiObject. PowerShell 3.0 offers an additional way using the CIM cmdlets. The CIM cmdlets query the same WMI information, except instead of using the traditional RPC\/DCOM connection, these cmdlets utilize PowerShell's remoting endpoint so\u2026","rel":"","context":"In &quot;Powershell 3.0&quot;","block_context":{"text":"Powershell 3.0","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell-3-0\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2012\/05\/talkbubble-v3-150x150.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":6082,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/6082\/searching-for-a-cim-wmi-class-with-powershell\/","url_meta":{"origin":1532,"position":2},"title":"Searching for a CIM\/WMI Class with PowerShell","author":"Jeffery Hicks","date":"September 18, 2018","format":false,"excerpt":"I got a question on Twitter about an older function I has posted to get antivirus information via WMI. The function continues to work fine with Windows 10, although there's always room for improvement. However, the question was that the function did not seem to work when querying a server\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/09\/image_thumb.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/09\/image_thumb.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/09\/image_thumb.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/09\/image_thumb.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":2910,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2910\/get-local-admin-group-members-in-a-new-old-way\/","url_meta":{"origin":1532,"position":3},"title":"Get Local Admin Group Members in a New Old Way","author":"Jeffery Hicks","date":"April 2, 2013","format":false,"excerpt":"Yesterday I posted a quick article on getting the age of the local administrator account password. It seemed appropropriate to follow up on a quick and dirty way to list all members of the local administrator group. Normally, I would turn to WMI (and have written about this in the\u2026","rel":"","context":"In &quot;CommandLine&quot;","block_context":{"text":"CommandLine","link":"https:\/\/jdhitsolutions.com\/blog\/category\/commandline\/"},"img":{"alt_text":"get-netlocalgroup","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/04\/get-netlocalgroup-1024x500.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/04\/get-netlocalgroup-1024x500.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/04\/get-netlocalgroup-1024x500.png?resize=525%2C300 1.5x"},"classes":[]},{"id":170,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/170\/friendly-wmi-dates\/","url_meta":{"origin":1532,"position":4},"title":"Friendly WMI Dates","author":"Jeffery Hicks","date":"August 5, 2009","format":false,"excerpt":"Gee..you think you know something only to find out you don\u2019t. Or maybe this falls into the category of teaching an old dog new tricks. When I first started using PowerShell several years ago, I learned about how to convert a WMI date to a more user friendly format...","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":103,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/103\/more-with-process-and-service-uptime\/","url_meta":{"origin":1532,"position":5},"title":"More with Process and Service uptime","author":"Jeffery Hicks","date":"February 20, 2007","format":false,"excerpt":"Like most things scripting, there's usually more than one way to do things. I thought I had a nice solution for getting service uptime via WMI. But alas, there is an even easier way. PowerShell has a ConvertToDateTime method which will convert a WMI time to a standard date time\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/1532","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=1532"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/1532\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=1532"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=1532"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=1532"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}