none
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' |
        ForEach-Object{
            Write-Host ('Processing:' + $_.DeviceID) -fore Green
            Get-ChildItem $_.DeviceID -Include $extensions -Recurse -ErrorAction 0 |
                ForEach-Object{
                    # 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
    Processing:C:
    Processing:D:
    f=7z.dll,p=D:\3Apps\Deployments\DR\**-9.2.0.2913\Database\7z.dll,h=***ADM0001,a=ETPAWindows,s=344FAF61C3EB76F4A2FB6452E83ED16C9CCE73E0,s2=A1E1D1F0FFF4FCCCFBDFA313F3BDFEA
    4D3DFE2C2D9174A615BBC39A0A6929338,v=9.20,Live=N


    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