Yes, just copy the code into notepad, save as a .bat or .cmd file
If you need CSV output, we can add the /format:csv switch to the command. This causes the PC name to be included in the output for some reason, so I've changed the header line as well:
Code:
@echo off
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:The following may vary depending on your Regional settings
:This assumes US format, i.e. echo %date% gives Mon 04/01/2008
:_t1=Day (Mon), _t2=Month (04), _t3=Date (01), and _t4=Year (2008)
:_t5 is filename to use, ie, 2008-04-08-PCName.csv
:_t6 should be set to the UNC path to the server where the file will be stored
:You must have write access to that share from the Target PC account that
:this batch file is run under
:Example, to store them on server 1 in the DriveInfo folder under the Logs share:
:set _t6=\\Server1\Logs\DriveInfo\
:Change the order on the Set _t5 line if you want the PC name first
:_t7 is the drive type to find
:2 Removable (floppy/Flash)
:3 Hard Drive
:4 Mapped Drive
:5 CD Rom
:If you want to list all drive types, comment the line
:with the find statement and un-comment the line
:without the find statement
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
for /f "tokens=1-4 delims=/ " %%I in ("%date%") do Set _t1=%%I& Set _t2=%%J& Set _t3=%%K& Set _t4=%%L
set _t5=%_t4%-%_t2%-%_t3%-%ComputerName%.csv
set _t6=\\Server1\Logs\DriveInfo\
set _t7=3
>%_t6%%_t5% echo.PC Name,Drive,Type,Free Space,Total Space
:This lists all drives
:>>%_t6%%_t5% (wmic logicaldisk get DeviceID,DriveType,Size,FreeSpace /format:csv
:This lists just the specified Drive Type
>>%_t6%%_t5% (wmic logicaldisk get DeviceID,DriveType,Size,FreeSpace /format:csv |find /i ",%_t7%,")
for /L %%I in (0,1,7) do set _t%%I= Just copy the code into a .bat or .cmd file. You can then run this file on each PC when needed, or set it as a scheduled task.
A better option instead of running this on each PC is to run it from the server and have it access the systems over the network. This also has the advantage of working with Win2K systems.
This will create a single file listing the info for each PC. If you need separate files for each PC, a simple for statement can read this single file and create individual files.
First, create a list in notepad of the PC names you want to check, one name per line.
Save this as pcnames.txt on the server and note the path
Then use this code, which will create a file named
currentdateDriveinfo.csv
Code:
@echo off
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:The following may vary depending on your Regional settings
:This assumes US format, i.e. echo %date% gives Mon 04/01/2008
:_t1=Day (Mon), _t2=Month (04), _t3=Date (01), and _t4=Year (2008)
:_t5 is filename to use, ie, 2008-04-08-DriveInfo.csv
:_t6 should be set to the folder on the server where the file will be stored
:the pcnames.txt file should be in this same folder
:Example, to store them on server 1 in the DriveInfo folder under c:\Logs
:set _t6=c:\Logs\DriveInfo\
:Change the order on the Set _t5 line if you want the PC name first
:_t7 is the drive type to find
:2 Removable (floppy/Flash)
:3 Hard Drive
:4 Mapped Drive
:5 CD Rom
:If you want to list all drive types, comment the line
:with the find statement and un-comment the line
:without the find statement
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
for /f "tokens=1-4 delims=/ " %%I in ("%date%") do Set _t1=%%I& Set _t2=%%J& Set _t3=%%K& Set _t4=%%L
set _t5=%_t4%-%_t2%-%_t3%-DriveInfo.csv
set _t6=C:\Logs\DriveInfo\
set _t7=3
>%_t6%%_t5% echo.PC Name,Drive,Type,Free Space,Total Space
:This lists all drives
:>>%_t6%%_t5% (wmic /failfast:on /node:@%_t6%pcnames.txt logicaldisk get DeviceID,DriveType,Size,FreeSpace /format:csv
:This lists just the specified Drive Type
>>%_t6%%_t5% (wmic /failfast:on /node:@%_t6%pcnames.txt logicaldisk get DeviceID,DriveType,Size,FreeSpace /format:csv |find /i ",%_t7%,")
for /L %%I in (0,1,7) do set _t%%I= If you have firewalls enabled on the PCs, you may get the following error:
- Node - [i]pcname[\i]
- ERROR:
- Code = 0x800706ba
- Description = The RPC server is unavailable.
- Facility = Win32
This means you'll need to allow Remote Administration through the firewall.
For the Windows firewall, goto the system named on the above Node line.
For Vista, enable Remote Administration on the Exceptions tab in Control Panel | Windows Firewall
For XP enter this at a command prompt:
netsh firewall set service remoteadmin enable subnet
or, to limit access to just the one server
netsh firewall set service remoteadmin enable custom 192.168.1.1
You can also set this from the Group Policy Editor (XP Pro/Vista)
Start | Run type
gpedit.msc press enter
Navigate to
Computer Configuration\Administrative Templates\Network\Network Connections\Windows Firewall folder.
If the computer is on a domain, then open the
Domain Profile, otherwise, open the
Standard Profile folder.
Double click
Windows Firewall: Allow remote administration exception and set to
enabled. Add the server address if you want to restrict address to one machine, or you can enter a subnet or the localsubnet (instructions on the properties page)
You can get help on any of these batch commands from the command prompt, just type the command name followed by /?, ie
for /? will explain the for command.
Google can find tons of info as well.
HTH
Jerry