locked
powershell find .appref-ms file RRS feed

  • Question

  • hello, so I am trying to find *appref-ms files on a given machine. I am able to detect the files just fine on my own machine, but if I try to run it via a remote machine, my test path comes back false? am I doing something wrong? thank you.

    $path1 = get-childitem \\testme-pc\c$\ -Directory |
         ?{$_.Name -ne 'windows'} | 
         Get-ChildItem -include .appref-ms -recurse
    
    $Compliance = "Non-Compliant"
           if (Test-Path  $path1){$compliance = "Compliant"}
    $Compliance
    
    
    $path1
    

    Tuesday, September 2, 2014 3:28 PM

Answers

  • This is better:

    $results=get-childitem \\testme-pc\c$\ -Directory |
         ?{$_.Name -ne 'windows'} | 
         Get-ChildItem -include .appref-ms -recurse
    if($results){
         'Compliant'
    }else{
         'Not Compliant'
    }
    


    ¯\_(ツ)_/¯

    • Marked as answer by justin rassi Tuesday, September 2, 2014 7:34 PM
    Tuesday, September 2, 2014 4:01 PM

All replies

  • Try:

    Get-ChildItem -include *.appref-ms -recurse




    ¯\_(ツ)_/¯

    Tuesday, September 2, 2014 3:57 PM
  • This is better:

    $results=get-childitem \\testme-pc\c$\ -Directory |
         ?{$_.Name -ne 'windows'} | 
         Get-ChildItem -include .appref-ms -recurse
    if($results){
         'Compliant'
    }else{
         'Not Compliant'
    }
    


    ¯\_(ツ)_/¯

    • Marked as answer by justin rassi Tuesday, September 2, 2014 7:34 PM
    Tuesday, September 2, 2014 4:01 PM
  • thanks a lot that worked out well, I had to change the code a bit but it worked. thanks.

    $Compliance = "Non-Compliant"
    $results = get-childitem \\testme-pc\c$\ -Directory |
         ?{$_.Name -ne 'windows'} | 
         Get-ChildItem -include *.appref-ms -recurse
    if($results){
    $Compliance = "Compliant"
    $results}
    else{$Compliance}
    

    Tuesday, September 2, 2014 7:34 PM