{"id":2773,"date":"2013-02-04T09:30:27","date_gmt":"2013-02-04T14:30:27","guid":{"rendered":"http:\/\/jdhitsolutions.com\/blog\/?p=2773"},"modified":"2013-02-04T09:30:27","modified_gmt":"2013-02-04T14:30:27","slug":"find-files-with-wmi-and-powershell-revisited","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/wmi\/2773\/find-files-with-wmi-and-powershell-revisited\/","title":{"rendered":"Find Files with WMI and PowerShell Revisited"},"content":{"rendered":"<p><a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2012\/04\/computereye.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2012\/04\/computereye-150x150.png\" alt=\"computereye\" width=\"150\" height=\"150\" class=\"alignleft size-thumbnail wp-image-2165\" \/><\/a>Last week I posted a PowerShell function to <a href=\"http:\/\/jdhitsolutions.com\/blog\/2013\/01\/find-files-with-wmi-and-powershell\/\" title=\"read the original article\" target=\"_blank\">find files using WMI<\/a>. One of the comments I got was about finding files with wildcards. In WMI, we've been able to search via wildcards and the LIKE operator since the days of XP.  <\/p>\n<p>In a WMI query we use the % as the wildcard character. Here's an example:<\/p>\n<p><code lang=\"DOS\"><br \/>\nPS C:\\scripts> get-wmiobject win32_service -filter \"displayname LIKE 'Micro%'\" | Select Name,Displayname,State,Startmode<\/p>\n<p>Name                     Displayname              State                    Startmode<br \/>\n----                     -----------              -----                    ---------<br \/>\nMSiSCSI                  Microsoft iSCSI Initi... Stopped                  Manual<br \/>\nswprv                    Microsoft Software Sh... Stopped                  Manual<br \/>\nwlidsvc                  Microsoft Account Sig... Stopped                  Manual<br \/>\n<\/code><\/p>\n<p>So it wasn't especially difficult to revise my original function to accept wildcards as part of the file name. Since we are used to using * as the wildcard character, I assumed it would be used here as well. So all I had to do was replace the * with % and change the operator.<\/p>\n<p><code lang=\"PowerShell\"><br \/>\n#if there is * in the filename or extension, replace it with %<br \/>\n#and change the comparison operator for the WMI query<br \/>\nif ($filename -match \"\\*\" ) {<br \/>\n    Write-Verbose \"Wildcard search on filename\"<br \/>\n    $filename = $filename.Replace(\"*\",\"%\")<br \/>\n    $fileOp=\"LIKE\"<br \/>\n}<br \/>\nelse {<br \/>\n    $fileOp=\"=\"<br \/>\n}<br \/>\nif ($extension -match \"\\*\") {<br \/>\n    Write-Verbose \"Wildcard search on extension\"<br \/>\n    $extension = $extension.Replace(\"*\",\"%\")<br \/>\n    $extOp=\"LIKE\"<br \/>\n}<br \/>\nelse {<br \/>\n    $extOp=\"=\"<br \/>\n}<br \/>\n$filter = \"Filename $fileOp '$filename' AND extension $extOp '$extension' AND Drive='$drive'\"<br \/>\nWrite-Verbose $filter<br \/>\n<\/code><\/p>\n<p>The reason I didn't simply make the expression use LIKE all the time is performance. When you use the LIKE operator, there is a significant performance price to pay. So I only wanted to use LIKE if I really had to.<\/p>\n<p>The other change I made was to accept an alternate credential (using a technique Boe Prox turned me on to).<\/p>\n<p><code lang=\"PowerShell\"><br \/>\n...<br \/>\n[System.Management.Automation.Credential()]$Credential = [System.Management.Automation.PSCredential]::Empty,<br \/>\n...<br \/>\n<\/code><\/p>\n<p>If you pass a string like mydomain\\admin, you'll get prompted for the password. Or you can pass a previously created credential object. Here's the revised code, less the comment based help.<\/p>\n<p><code lang=\"PowerShell\"><br \/>\n#requires -version 2.0<\/p>\n<p>Function Get-CIMFile {<\/p>\n<p>[cmdletbinding(DefaultParameterSetName=\"Default\")]<br \/>\nParam(<br \/>\n[Parameter(Position=0,Mandatory=$True,HelpMessage=\"What is the name of the file?\")]<br \/>\n[ValidateNotNullorEmpty()]<br \/>\n[alias(\"file\")]<br \/>\n[string]$Name,<br \/>\n[ValidateNotNullorEmpty()]<br \/>\n[string]$Drive=\"C:\",<br \/>\n[ValidateNotNullorEmpty()]<br \/>\n[string[]]$Computername=$env:computername,<br \/>\n[System.Management.Automation.Credential()]$Credential = [System.Management.Automation.PSCredential]::Empty,<br \/>\n[Parameter(ParameterSetName=\"Job\")]<br \/>\n[switch]$AsJob,<br \/>\n[Parameter(ParameterSetName=\"Job\")]<br \/>\n[int32]$ThrottleLimit=32<br \/>\n)<\/p>\n<p><#\n strip off any trailing characters to drive parameter \n that might have been passed.\n#><br \/>\nIf ($Drive.Length -gt 2) {<br \/>\n    $Drive=$Drive.Substring(0,2)<br \/>\n}<\/p>\n<p>Write-Verbose \"Searching for $Name on Drive $Drive on computer $Computername.\"<\/p>\n<p><#\nNormally you might think to simply split the name on the . character. But\nyou might have a filename like myfile.v2.dll so that won't work. In a case \nlike this the extension would be everything after the last . and the filename\neverything before.\n\nSo instead I'll use the substring method to \"split\" the filename string.\n#><\/p>\n<p>#get the index of the last .<br \/>\n$index = $name.LastIndexOf(\".\")<br \/>\n#get the first part of the name<br \/>\n$filename=$Name.Substring(0,$index)<br \/>\n#get the last part of the name<br \/>\n$extension=$name.Substring($index+1)<\/p>\n<p>#if there is * in the filename or extension, replace it with %<br \/>\n#and change the comparison operator for the WMI query<br \/>\nif ($filename -match \"\\*\" ) {<br \/>\n    Write-Verbose \"Wildcard search on filename\"<br \/>\n    $filename = $filename.Replace(\"*\",\"%\")<br \/>\n    $fileOp=\"LIKE\"<br \/>\n}<br \/>\nelse {<br \/>\n    $fileOp=\"=\"<br \/>\n}<br \/>\nif ($extension -match \"\\*\") {<br \/>\n    Write-Verbose \"Wildcard search on extension\"<br \/>\n    $extension = $extension.Replace(\"*\",\"%\")<br \/>\n    $extOp=\"LIKE\"<br \/>\n}<br \/>\nelse {<br \/>\n    $extOp=\"=\"<br \/>\n}<br \/>\n$filter = \"Filename $fileOp '$filename' AND extension $extOp '$extension' AND Drive='$drive'\"<br \/>\nWrite-Verbose $filter<\/p>\n<p>#build the core command<br \/>\n$cmd=\"Get-WmiObject -Class CIM_Datafile -Filter \"\"$filter\"\" -ComputerName $Computername\"<\/p>\n<p>if ($credential) {<br \/>\n  write-Verbose \"Adding credential for $($credential.username)\"<br \/>\n  $cmd+=\" -credential `$credential\"<\/p>\n<p>} #if credential<\/p>\n<p>#get all instances of the file and write the WMI object to the pipeline<br \/>\nif ($AsJob) {<br \/>\n    Write-Verbose \"Running query as a job\"<br \/>\n     $cmd+=\" -Asjob -ThrottleLimit $ThrottleLimit\"<br \/>\n}<br \/>\nelse {<br \/>\n    #record the start time<br \/>\n    $start=Get-Date<br \/>\n}<\/p>\n<p>Write-Verbose $cmd<br \/>\nInvoke-Expression -Command $cmd<\/p>\n<p>#display how long this took if not running as a job<br \/>\nif ($start) {<br \/>\n    #get the end time and report how long the search took<br \/>\n    $end=Get-Date<br \/>\n    Write-Verbose \"Search completed in $($end-$start)\"<br \/>\n}<\/p>\n<p>} #end Get-CIMFile<br \/>\n<\/code><\/p>\n<p>The last major change is that I construct a Get-WmiObject command string based on the parameter values. I start with a core command.<\/p>\n<p><code lang=\"PowerShell\"><br \/>\n#build the core command<br \/>\n$cmd=\"Get-WmiObject -Class CIM_Datafile -Filter \"\"$filter\"\" -ComputerName $Computername\"<br \/>\n<\/code><\/p>\n<p>And then add other parameters based on the user's input. I use Invoke-Expression to run the final command.<\/p>\n<p>You can download my revised version of <a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/02\/Get-CIMFile2.txt\" target=\"_blank\">Get-CIMFile<\/a><\/p>\n<p>Finally, while I was working on this revision PowerShell madman <a href=\"https:\/\/twitter.com\/proxb\" title=\"Follow Boe on Twitter\" target=\"_blank\">Boe Prox<\/a> was working up his own version which has even more bells and whistles. Many of the articles I write here are intended as tutorials and not necessarily production ready tools. Boe's version on the other hand is on PEDs (PowerShell Enhancing Drug). <a href=\"http:\/\/learn-powershell.net\/2013\/02\/01\/use-powershell-and-wmi-to-locate-multiple-files-on-any-drive-in-your-domain\/\" target=\"_blank\">Check it out<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Last week I posted a PowerShell function to find files using WMI. One of the comments I got was about finding files with wildcards. In WMI, we&#8217;ve been able to search via wildcards and the LIKE operator since the days of XP. In a WMI query we use the % as the wildcard character. Here&#8217;s&#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":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[19],"tags":[224,534,540,547],"class_list":["post-2773","post","type-post","status-publish","format-standard","hentry","category-wmi","tag-function","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>Find Files with WMI and PowerShell Revisited &#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\/wmi\/2773\/find-files-with-wmi-and-powershell-revisited\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Find Files with WMI and PowerShell Revisited &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"Last week I posted a PowerShell function to find files using WMI. One of the comments I got was about finding files with wildcards. In WMI, we&#039;ve been able to search via wildcards and the LIKE operator since the days of XP. In a WMI query we use the % as the wildcard character. Here&#039;s...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/wmi\/2773\/find-files-with-wmi-and-powershell-revisited\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2013-02-04T14:30:27+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2012\/04\/computereye-150x150.png\" \/>\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=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wmi\\\/2773\\\/find-files-with-wmi-and-powershell-revisited\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wmi\\\/2773\\\/find-files-with-wmi-and-powershell-revisited\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"Find Files with WMI and PowerShell Revisited\",\"datePublished\":\"2013-02-04T14:30:27+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wmi\\\/2773\\\/find-files-with-wmi-and-powershell-revisited\\\/\"},\"wordCount\":322,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wmi\\\/2773\\\/find-files-with-wmi-and-powershell-revisited\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2012\\\/04\\\/computereye-150x150.png\",\"keywords\":[\"Function\",\"PowerShell\",\"Scripting\",\"WMI\"],\"articleSection\":[\"WMI\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wmi\\\/2773\\\/find-files-with-wmi-and-powershell-revisited\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wmi\\\/2773\\\/find-files-with-wmi-and-powershell-revisited\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wmi\\\/2773\\\/find-files-with-wmi-and-powershell-revisited\\\/\",\"name\":\"Find Files with WMI and PowerShell Revisited &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wmi\\\/2773\\\/find-files-with-wmi-and-powershell-revisited\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wmi\\\/2773\\\/find-files-with-wmi-and-powershell-revisited\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2012\\\/04\\\/computereye-150x150.png\",\"datePublished\":\"2013-02-04T14:30:27+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wmi\\\/2773\\\/find-files-with-wmi-and-powershell-revisited\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wmi\\\/2773\\\/find-files-with-wmi-and-powershell-revisited\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wmi\\\/2773\\\/find-files-with-wmi-and-powershell-revisited\\\/#primaryimage\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2012\\\/04\\\/computereye.png\",\"contentUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2012\\\/04\\\/computereye.png\",\"width\":\"896\",\"height\":\"1024\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wmi\\\/2773\\\/find-files-with-wmi-and-powershell-revisited\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"WMI\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/wmi\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Find Files with WMI and PowerShell Revisited\"}]},{\"@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":"Find Files with WMI and PowerShell Revisited &#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\/wmi\/2773\/find-files-with-wmi-and-powershell-revisited\/","og_locale":"en_US","og_type":"article","og_title":"Find Files with WMI and PowerShell Revisited &#8226; The Lonely Administrator","og_description":"Last week I posted a PowerShell function to find files using WMI. One of the comments I got was about finding files with wildcards. In WMI, we've been able to search via wildcards and the LIKE operator since the days of XP. In a WMI query we use the % as the wildcard character. Here's...","og_url":"https:\/\/jdhitsolutions.com\/blog\/wmi\/2773\/find-files-with-wmi-and-powershell-revisited\/","og_site_name":"The Lonely Administrator","article_published_time":"2013-02-04T14:30:27+00:00","og_image":[{"url":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2012\/04\/computereye-150x150.png","type":"","width":"","height":""}],"author":"Jeffery Hicks","twitter_card":"summary_large_image","twitter_creator":"@JeffHicks","twitter_site":"@JeffHicks","twitter_misc":{"Written by":"Jeffery Hicks","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jdhitsolutions.com\/blog\/wmi\/2773\/find-files-with-wmi-and-powershell-revisited\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/wmi\/2773\/find-files-with-wmi-and-powershell-revisited\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"Find Files with WMI and PowerShell Revisited","datePublished":"2013-02-04T14:30:27+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/wmi\/2773\/find-files-with-wmi-and-powershell-revisited\/"},"wordCount":322,"commentCount":0,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/wmi\/2773\/find-files-with-wmi-and-powershell-revisited\/#primaryimage"},"thumbnailUrl":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2012\/04\/computereye-150x150.png","keywords":["Function","PowerShell","Scripting","WMI"],"articleSection":["WMI"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/wmi\/2773\/find-files-with-wmi-and-powershell-revisited\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/wmi\/2773\/find-files-with-wmi-and-powershell-revisited\/","url":"https:\/\/jdhitsolutions.com\/blog\/wmi\/2773\/find-files-with-wmi-and-powershell-revisited\/","name":"Find Files with WMI and PowerShell Revisited &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/wmi\/2773\/find-files-with-wmi-and-powershell-revisited\/#primaryimage"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/wmi\/2773\/find-files-with-wmi-and-powershell-revisited\/#primaryimage"},"thumbnailUrl":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2012\/04\/computereye-150x150.png","datePublished":"2013-02-04T14:30:27+00:00","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/wmi\/2773\/find-files-with-wmi-and-powershell-revisited\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/wmi\/2773\/find-files-with-wmi-and-powershell-revisited\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jdhitsolutions.com\/blog\/wmi\/2773\/find-files-with-wmi-and-powershell-revisited\/#primaryimage","url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2012\/04\/computereye.png","contentUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2012\/04\/computereye.png","width":"896","height":"1024"},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/wmi\/2773\/find-files-with-wmi-and-powershell-revisited\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"WMI","item":"https:\/\/jdhitsolutions.com\/blog\/category\/wmi\/"},{"@type":"ListItem","position":2,"name":"Find Files with WMI and PowerShell Revisited"}]},{"@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":515,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/515\/find-that-service\/","url_meta":{"origin":2773,"position":0},"title":"Find That Service","author":"Jeffery Hicks","date":"November 19, 2009","format":false,"excerpt":"Once again, the fine forum members at ScriptingAnswers.com come through and help get my PowerShell idea engine revving. The latest post posed this basic question: \u201cI need to query my servers and find all services using a specific service account.\u201d The poster thought this would be a good opportunity to\u2026","rel":"","context":"In &quot;CommandLine&quot;","block_context":{"text":"CommandLine","link":"https:\/\/jdhitsolutions.com\/blog\/category\/commandline\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":4211,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4211\/friday-fun-arent-you-special\/","url_meta":{"origin":2773,"position":1},"title":"Friday Fun: Aren\u2019t You Special","author":"Jeffery Hicks","date":"January 30, 2015","format":false,"excerpt":"If you've been following my work for any length of time you know I am constantly going on about \"objects in the pipeline\". But PowerShell is flexible enough that you should be able to use it as it meets your needs, provided you know the limitations for whatever path you\u2026","rel":"","context":"In &quot;Friday Fun&quot;","block_context":{"text":"Friday Fun","link":"https:\/\/jdhitsolutions.com\/blog\/category\/friday-fun\/"},"img":{"alt_text":"crayons","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/11\/crayons-150x150.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":2072,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2072\/ping-a-service-with-powershell\/","url_meta":{"origin":2773,"position":2},"title":"Ping a Service with PowerShell","author":"Jeffery Hicks","date":"February 7, 2012","format":false,"excerpt":"The other day I came across a PowerShell question on StackOverflow about testing if a service was running on a group of machines.This sparked an idea for a tool to \"ping\" a service, in much the same way we ping a computer to see if it is up and running,\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":[]},{"id":3497,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3497\/resolving-sids-with-wmi-wsman-and-powershell\/","url_meta":{"origin":2773,"position":3},"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":[]},{"id":14,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/14\/finding-service-uptime\/","url_meta":{"origin":2773,"position":4},"title":"Finding Service Uptime","author":"Jeffery Hicks","date":"January 10, 2006","format":false,"excerpt":"Ever wonder how long a particular service has been running? With WMI you can come pretty close to getting a handle on this. We start with Win32_Service to get the current process handle. Once we have that, we can query the Win32_Process class and get the creation time for that\u2026","rel":"","context":"In &quot;Scripting&quot;","block_context":{"text":"Scripting","link":"https:\/\/jdhitsolutions.com\/blog\/category\/scripting\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3555,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3555\/get-powershell-version-with-wmi\/","url_meta":{"origin":2773,"position":5},"title":"Get PowerShell Version with WMI","author":"Jeffery Hicks","date":"November 13, 2013","format":false,"excerpt":"With the release of PowerShell 4.0, it is possible you might end up with a mix of systems in your environment. I know I do because I do a lot of writing, testing and development that requires multiple versions in my test network. Recently I was doing some Group Policy\u2026","rel":"","context":"In &quot;Group Policy&quot;","block_context":{"text":"Group Policy","link":"https:\/\/jdhitsolutions.com\/blog\/category\/group-policy\/"},"img":{"alt_text":"get-wmipshell","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/11\/get-wmipshell-1024x244.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/11\/get-wmipshell-1024x244.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/11\/get-wmipshell-1024x244.png?resize=525%2C300 1.5x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/2773","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=2773"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/2773\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=2773"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=2773"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=2773"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}