Deepan s
Deepan s

Reputation: 1

Get-ChildItem : The network path was not found

While running my power shell script to get largest files from multiple servers, am facing this error. Could some one help me to resolve this error.

Script:

$computers = get-content -Path "D:\Automation_space_check\Servers.txt."
foreach($_ in (Get-WmiObject win32_volume -ComputerName $computer)){
if($_.drivetype -eq 3 -and $_.driveletter -ne $null){
Get-ChildItem "\\$computer\$($_.driveletter.replace(':','$'))" -force -recurse -ErrorAction silentlycontinue | select Name,DirectoryName,@{Name="size";Expression={"{0:N1}" -f($_.length/1mb)}} |
 Sort Size -descending | select -first 10}}

Error:

Get-ChildItem : The network path was not found At D:\Automation_space_check\Untitled3.ps1:18 char:1 + Get-ChildItem "\$computer$($_.driveletter.replace(':','$'))" -force ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Get-ChildItem], IOException + FullyQualifiedErrorId : System.IO.IOException,Microsoft.PowerShell.Commands.GetChildItemCommand

Servers.txt

Computer1
computer2
computer3
computer4

Upvotes: 0

Views: 433

Answers (1)

Hazrelle
Hazrelle

Reputation: 856

$computers = get-content -Path "D:\Automation_space_check\Servers.txt."
foreach($computer in  $computers) {
  foreach($drive in (Get-WmiObject win32_volume -ComputerName $computer)) {
    if($drive.drivetype -eq 3 -and $drive.driveletter -ne $null){
        Get-ChildItem "\\$computer\$($_.driveletter.replace(':','$'))" -force -recurse -ErrorAction silentlycontinue | select Name,DirectoryName,@{Name="size";Expression={"{0:N1}" -f($_.length/1mb)}} |
        Sort Size -descending | select -first 10
     }
  }
}

Upvotes: 0

Related Questions