Help with the running the script in all the Drives with the Drive Type 3 RRS feed

  • Question

  • Hi All,

    I have the following  code to get the child items under the path provided by the variable $Loc .  I have two drives C:\ and D:\ .  But the code below always runs only on the D Drive because the variable always use the latest value.  Is there a way I can run the below first on C: and then on D :\

    $Extensions = @('*.dll','*.so','*.a','*.lib')

    $Drives = (Get-CimInstance Win32_LogicalDisk -Filter "Drivetype=3").DeviceID ForEach ($Loc in $Drives){ Get-ChildItem -Path $Loc -Include $Extensions -Recurse -ErrorAction SilentlyContinue | ForEach-Object {

    • Edited by Chennai600101 Wednesday, March 20, 2019 6:21 PM
    • Moved by Bill_Stewart Wednesday, September 4, 2019 7:09 PM This is not "fix/debug/rewrite script for me" forum
    Wednesday, March 20, 2019 6:06 PM

All replies

  • Writing correctly structured code and formatting it correctly would help you to understand what is happening and to see issues.

    $extensions = '*.dll','*.so', '*.a', '*.lib'
    Get-CimInstance Win32_LogicalDisk -Filter 'Drivetype=3' |
            Write-Host ('Processing:' + $_.DeviceID) -fore Green
            Get-ChildItem $_.DeviceID -Include $extensions -Recurse -ErrorAction 0 |
                    # other enumerted code steps


    Wednesday, March 20, 2019 6:50 PM
  • Thanks.  This is what I see in the output.  It displays both and then runs on D
    PS C:\PC\Libaudit> C:\PC\Libaudit\Libaudit_v1.ps1

    Wednesday, March 20, 2019 7:09 PM
  • That is because it finds no files on C. 


    Wednesday, March 20, 2019 7:27 PM
  • If I hard code values it is able to find them
    Wednesday, March 20, 2019 7:29 PM
  • Do I have to append the \ ?  because it works if it is like this 

    -Path C:\

    but not when it is 

    -Path C:

    Wednesday, March 20, 2019 7:32 PM
  • That is how the file system works.

    If you always want the root then add the \.


    Wednesday, March 20, 2019 9:37 PM