Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Get hard drive information of a remote server using Powershell 1,0


Get hard drive information of a remote server using Powershell 1,0

Author
Message
rahulr.sharma
rahulr.sharma
SSC Rookie
SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)

Group: General Forum Members
Points: 44 Visits: 313
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.
e-ghetto
e-ghetto
SSC Veteran
SSC Veteran (209 reputation)SSC Veteran (209 reputation)SSC Veteran (209 reputation)SSC Veteran (209 reputation)SSC Veteran (209 reputation)SSC Veteran (209 reputation)SSC Veteran (209 reputation)SSC Veteran (209 reputation)

Group: General Forum Members
Points: 209 Visits: 247
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


rahulr.sharma
rahulr.sharma
SSC Rookie
SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)

Group: General Forum Members
Points: 44 Visits: 313
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.
e-ghetto
e-ghetto
SSC Veteran
SSC Veteran (209 reputation)SSC Veteran (209 reputation)SSC Veteran (209 reputation)SSC Veteran (209 reputation)SSC Veteran (209 reputation)SSC Veteran (209 reputation)SSC Veteran (209 reputation)SSC Veteran (209 reputation)

Group: General Forum Members
Points: 209 Visits: 247
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!
rahulr.sharma
rahulr.sharma
SSC Rookie
SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)

Group: General Forum Members
Points: 44 Visits: 313
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 Smile)

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.
chrisn-585491
chrisn-585491
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1200 Visits: 2384
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;

....

Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search