Reputation: 1
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
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