How do I get the free space of a remote disk without admin privileges? (Windows)

I'm an admin on two servers (Win 2008 R2). I have a scheduled task that copies large files from a share on one server to another. Before I do the copy, I check that the destination disk on the other server has enough free space. I've been running these tasks under my own account and want to change to a system account with lower privileges than me.

I've been using the following recipe to get the free space ratio:

PowerShell.exe Get-WmiObject Win32_LogicalDisk -ComputerName <REMOTESERVER> -Filter "DeviceID='C:'" | Foreach-Object {$_.FreeSpace / $_.Size}

It works on my account, but gives me 0x80070005 (E_ACCESS DENIED) from the non-admin account.

Should I even be using WMI for this or is there something simpler?


You can use WMI to get the free disk space as a non-administrative user, but you first of all need to change the WMI permissions on the remote server.

From wmimgmt.msc on the remote server, and then right-click on "WMI Control (Local)", and select the Security tab, then highlight CIMv2 and click the "Security" button. From here give the user you want to be able to run the script as "Remote Enable" permission and the script should be able to get the remote WMI information.


You can get the size by mapping the drive to a letter and querying it with the Get-PSDrive cmdlet. Works without admin access on the server or even write access to the share.

net use T: \\server\share
$freebytes=(Get-PSDrive T).Free
net use T: /delete