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

  • 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.

  • 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

  • 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.

  • 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!

  • 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.

  • 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;

    ....

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply