Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Get hard drive information of a remote server using Powershell 1,0 Expand / Collapse
Author
Message
Posted Friday, February 11, 2011 5:31 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Monday, July 14, 2014 12:12 AM
Points: 26, Visits: 303
ello All,

I wanted to know if there is a method that I can use to get the hard drive information of a remote server using powershell 1.0. The WMI class that has been introduced in Powershell 2.0 does have the option to fetch the same information but the server environment that I work in does not have the option for Powershell 2.0 on the servers..



I do have powershell 2.0 on the machine from which i want to execute the command and fetch the information.

What I am looking for is to have the information like free space, name of the hard drives on a remote server.

Thanks in advance for any help that you can provide.
Post #1062488
Posted Tuesday, February 15, 2011 4:49 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Today @ 2:59 AM
Points: 201, Visits: 227
Try this:

Param([string]$ComputerName="$env:computername")

clear;

function GetDrivetypeName([int]$DriveType) {
switch($DriveType) {
0 {'Unknown'}
1 {'No Root Directory'}
2 {'Removable Disk'}
3 {'Local Disk'}
4 {'Network Drive'}
5 {'Compact Disk'}
6 {'RAM Disk'}
default {'?'}
}
}

get-wmiobject -Computername $ComputerName win32_volume |
format-table Driveletter,`
Label,`
@{Name="DriveType"; Expression = {GetDrivetypeName($_.DriveType)}},`
@{Name="Capacity [GB]"; Expression = {[Math]::Round($_.Capacity/1024/1024/1024, 1)}},`
@{Name="Free Space [GB]"; Expression = {[Math]::Round($_.FreeSpace/1024/1024/1024, 1)}},`
@{Name="Free Space [%]"; Expression = {[Math]::Round(($_.FreeSpace/$_.Capacity)*100)}}`
-autosize

Post #1064164
Posted Tuesday, February 15, 2011 5:17 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Monday, July 14, 2014 12:12 AM
Points: 26, Visits: 303
Hi e-ghetto,

Appreciate your effort for writing the script but as I mentioned that I do not have powershell 2.0 on my server environment. The WMIobject class and -computername attributes were introduced in Powershell 2.0 only but as I am working on Powershell 1.0 environment I do not have an option to use both.

But thanks for the effort anyways.
Post #1064178
Posted Tuesday, February 15, 2011 6:28 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Today @ 2:59 AM
Points: 201, Visits: 227
Oh, I see... What about this:

$d = New-Object -typename System.IO.DriveInfo -argumentlist "C:"
$d

http://technet.microsoft.com/en-us/library/ee692723.aspx

Should also work with PS 1.0. Check it out!
Post #1064219
Posted Tuesday, February 15, 2011 7:11 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Monday, July 14, 2014 12:12 AM
Points: 26, Visits: 303
Well using the mentioned, I can not run it on a server and get the drive info of a remote server. as when this will be execute it will collect the information of the local drives to that server.

Let me try and explain the full scenario that might be helpful (to me eventually :))

what I am trying to achieve is to run a script that copies an installation file from one location to many servers on their E drive under a folder (lets call it as) Temp. Now this part is easy as I can use copy-item member and give copy from and copy to locations, but what I need to check before a copy, is to what is the free space on the E drive of that server so that the servers drive does not run out of space while copying. For the same I need to verify that the free space on every server is enough before I copy the file.

Execution mode :

1. Run a Foreach loop to consider one server at a time (example : foreach($server in $servers))
2. Test if E drive exists on the server
3. Test if the space on E drive is greater then 700 mb
4. Create a new folder Temp on E drive(if it does not exist)
5. Copy the file from a shared path into the Temp folder.

Hope this helps in explaining what I am trying to do and as mentioned earlier Remoting is not an option for me as I do not have powershell 2.0 on all my servers.
Post #1064252
Posted Thursday, April 7, 2011 12:37 PM
SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: Today @ 1:19 PM
Points: 624, Visits: 1,592
Partial solution for you to explore...

foreach($server in $servers)
{
# Get fixed drive info
$disks = Get-WmiObject -ComputerName $server -Class Win32_LogicalDisk -Filter "DriveType = 3";
foreach($disk in $disks)
{
$deviceID = $disk.DeviceID;
[float]$size = $disk.Size;
[float]$freespace = $disk.FreeSpace;

....
Post #1090161
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse