I have a batch file which deletes some files from the network drives and then calls a powershell script. The powershell script gets the space details of all the network drives, and send out a mail. Below is the command used to getting the space details :
$disks = Get-WmiObject -ComputerName "ABCD001" -Class Win32_LogicalDisk -Filter "DriveType = 4";
$deviceID = $disk.DeviceID;
foreach($disk in $disks)
{
$totalSpaceGB = [Math]::Round([float]$disk.Size / 1073741824, 2);
$freeSpaceGB = [Math]::Round([float]$disk.FreeSpace / 1073741824, 2);
$disk, 'TotalSize = ', $totalSpaceGB + " Gb", 'FreeSpace = ', $freeSpaceGB + " Gb", $disk.ProviderName -join ' ' | Out-File -FilePath $FilePath -Append -Width 200;
}
Below is the command used to get the space details of the local drives:
$disks = Get-WmiObject -ComputerName $computer -Class Win32_LogicalDisk -Filter "DriveType = 3";
The issue is, when I run this batch file manually, it runs fine. But when scheduled or run from the Task Scheduler, the result for the network drives comes as below:
TotalSize = 0 Gb FreeSpace = 0 Gb
Looks like it is unable to connect to the network drives. As I said earlier, when I go in and run the batch script manually, it returns the desired result.
Please help!!!