none
Run the power shell on the existing drives RRS feed

  • Question

  • Hi All,

    I hard coded the drives like this in my script.  Is there any way I can get the drives to run automatically through power shell . I tried commands where I get the plain letter Drives like (A , C, D, E) not like "C:\" .

    Please help me out

    $LocStr=@("C:\","D:\","E:\")
    
    ForEach ($Loc in $LocStr){
    

    Thanks

    S

    • Moved by Bill_Stewart Wednesday, September 4, 2019 6:47 PM Unanswerable drive-by question
    Monday, March 18, 2019 9:21 PM

All replies

  • Get-PSDrive
    # or
    Get-CimInstance -ClassName CIM_LogicalDisk
    Did you try to search for it?

    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''


    • Edited by BOfH-666 Monday, March 18, 2019 9:43 PM
    Monday, March 18, 2019 9:43 PM
  •   Is there any way I can get the drives to run automatically through power shell . 

    It depends on what you mean by "run automatically through power shell". You had a good start. Here's one example. 

    $LocStr=@("C:\","D:\","E:\")
    
    ForEach ($Loc in $LocStr){
        $count = (Get-ChildItem $Loc).count
        "There are {0} files in the root of {1}" -f $count, $Loc
    }

    Monday, March 18, 2019 10:14 PM
  • Thanks .   I tried the below.  I got the drive letters repeated.  Do you know why?
    $drive=(Get-CimInstance Win32_LogicalDisk -Filter "Drivetype=3").DeviceID
    
     ForEach ($Loc in $drive){
     Write-Output $drive
     }
    PS C:\PC\Libaudit> C:\PC\Libaudit\t.ps1
    C:
    D:
    C:
    D:
    Monday, March 18, 2019 10:26 PM
  • Thanks .  I found out the issue.  Please ignore
    Monday, March 18, 2019 10:46 PM
  • Thanks .  I found out the issue.  Thanks again for your help
    Monday, March 18, 2019 10:47 PM