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

3

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?

windows
windows-server-2008
wmi
asked on Server Fault Jul 21, 2015 by giltay

3 Answers

2

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
answered on Server Fault Jul 21, 2015 by David
1

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.

answered on Server Fault Jul 21, 2015 by Mike1980
0

There is a non WMI based EXE called Freedisk that works without admin privileges.
https://technet.microsoft.com/en-us/library/cc731162.aspx
It returns a 0 if there is enough space and a 1 if there is not enough space.

PS C:\temp> freedisk \\server1\share1 9mb
OK
PS C:\temp> $lastExitCode
0
PS C:\temp> freedisk \\server1\share1 99999999999999999mb
To small!!
PS C:\temp> $lastExitCode
1
answered on Server Fault Jul 21, 2015 by Clayton

User contributions licensed under CC BY-SA 3.0