PowerShell Live - being retired

Please go to http://www.shelltools.net for more information

Welcome to PowerShell Live - being retired Sign in | Join | Help
Home Main Site Blogs Forums Videos Chat Customer Support

Re: Running PS1 scripts to retrieve data from multiple servers?

  •  05-03-2007, 9:15 PM

    Re: Running PS1 scripts to retrieve data from multiple servers?

    Well i haven't read that book, but hear that it is popular and good for the beginner. Powershell In Action, is more my sort of book.

     Anyhow if you are running scripts on a bunch of servers, then yes, powershell has to be installed on those machines

    However, alot of what you want to do can be done through WMI.. and thus you can run the whole script on your computer, which goes out through WMI and as long as the user that is running the script has permissions on those servers, via WMI it can query information from them.

     run

    get-WmiObject -list

    to see what different wmi classes are availble (on your own computer, but most are generic, i often get it working against my own computer first..

    that list can be long so i try to filter it with a keyword like the following

     

    gwmi -l | ? { $_ -match "disk*" }

    and try a few out

    get-WmiObject Win32_diskdrive
    get-WmiObject Win32_LogicalDisk

    the first was the physical info of the harddrive/('s) in the system, the other is the logical disk, which includes network drive mappings

    get-WmiObject Win32_LogicalDisk |Select-Object *

    then i run the above see all the WMI properties for this class.
    I can make sense of this data some, see the freespace, the name of the drives , and various other things.. some of the values like DriveType contain a number, and i don't know what t hat number means, so we can search MSN for win32_LogicalDisk

    http://msdn2.microsoft.com/en-us/library/aa394173.aspx

    now we are trying to find out how to determine if its a local disk, so that we can ignore the network disks. I see that Local Fixed Disk is type 3.. so we can update our powershell query

    get-WmiObject Win32_LogicalDisk |Where-Object { $_.DriveType -eq 3 }

    and then only get the freespace property as thats is what you are after:

    get-WmiObject Win32_LogicalDisk |Where-Object { $_.DriveType -eq 3 }| % { $_.freespace }

    Now from here you get-wmiobject has a ComputerName  property which allows you to specify the name of a remote computer.

    get-WmiObject Win32_LogicalDisk -computersystem myserver |Where-Object { $_.DriveType -eq 3 }| % { $_.freespace }

    Then frrom there it is easy to pipe a link of machines in put the default variable $_ as the computersystem and away you go.

    -Karl

    Filed under: ,
View Complete Thread