title: get-wmi to delete user profiles by matching the local path attribute
body: <p>I am working on a script to audit a server for profiles, determine which belong to users who are disabled in AD and then deleting just those from the server.  I almost have it working but I think the code I am using to actually run the delete is not quite right.  here is the script I have so far:</p>
  
  <pre><code># grabbing name of server we want to run the commands on
  $cname = read-host "enter computer name:"
  #
  #using get-wmi to populate a csv file called paths.csv with the localpath 
  info for any user profiles on the server named in $cname
  get-wmiobject -class win32_userprofile -computername $cname | select-object 
  localpath | where localpath -like "c:\users*" | export-csv paths.csv -
  NoTypeInformation
  #
  #grabbing just the leaf of the local path for each user
  $users = Import-Csv paths.csv | ForEach-Object { Split-Path $_.localpath -
  leaf } | out-file users.csv
  #
  #Grabbing the usernames and Asking Active Directory for the status of the 
  enabled property for each
  $AD = @(gc users.csv | % {Get-ADUser $_ | select samaccountname,enabled})
  #
  #Exporting ONLY the DISABLED users to a new csv file.
  $AD | ? { -not($_.enabled) } | export-csv -notypeinformation disabled.csv
  #
  #Adding a new column to the disabled csv that recreates the folder path 
  based on the username.
  import-csv disabled.csv | Select-Object *,@{Name="localpath";Expression=
  {"C:\Users\$($_.samaccountname)"}} | export-csv -notypeinformation 
  dispaths.csv
  #
  #using get-wmi to delete any profiles that have a localpath property which 
  matches one of the local path fields in the dispaths.csv file
  $dispaths = import-csv dispaths.csv
  Foreach ($localpath in $dispaths) 
  {get-wmiobject -class win32_userprofile -computername $cname | where 
  {$_.localpath -eq $localpath} | foreach {$_.Delete()}
  }
  </code></pre>
  
  <p>the dispaths.csv file ends up with a column that has the correct data but when the get-wmi command runs at the end, it doesn't actually delete any profiles.  It's like nothing returned by the get-wmi is matching the target I set.  I am sure I have a logical or syntax error but I need a little guidance to find it.</p>
  
  <p>I am trying to have the code look at each field in a column called "localpath" and delete any profiles it finds on the server which have a matching string in their localpath attribute.  when I run the script it just returns a new line but none of the profiles have been removed.</p>