Powershell server health script with winrm

Posted on 2011-10-04
Last Modified: 2012-05-12
I am looking for a script that I can run from a central server where I can create a report on server health on a list of servers.

The output of the script some thing pretty for managment and an spreadsheet of results for me.

I have WinRM configured, if it matters...

Things I am looking for
Verify a service is installed an running
check that the local Administrator account was renamed
Verify MTU Settings

The way I envision it is a bunch of functions, in a loop from get-content script.

Is this even possible?
Question by:brittonv
    LVL 11

    Expert Comment

    Well, it'd be something like this:
    $list = Get-Content C:\list_of_pcs.txt
    foreach ($computer in $list)
        # Unfortunately, my OS doesn't feel like providing MTU size
        $a = Get-WmiObject $computer Win32_NetworkAdapterConfiguration -ComputerName $computer | Where-Object {$_.MACAddress -ne $null} | Format-Table -HideTableHeaders DNSHostName, Description, IPAddress, MTU
        # Service name - not the friendly one. The one you use with net start/stop, sc, etc
        $b = Get-WmiObject Win32_Service -ComputerName $computer | Where-Object {$_.Name -eq "AeLookupSvc"} | Format-Table -HideTableHeaders SystemName, DisplayName, Status
        # Per MS KB:
        $c = Get-WmiObject Win32_UserAccount -ComputerName $computer | Where-Object {$_.SID -like 'S-1-5-21-*-500'} | Format-Table -HideTableHeaders Name, SID
        $a +$b +$c + "`n`n`n`n" >> \\server\path_to_file.txt

    Open in new window

    I have some problems with hash arrays and such so someone else would have to clean this mess ;)
    LVL 67

    Expert Comment

    If you tell us what you mean with such sloppy expressions like "verify MTU settings", we might be able to supply a precise solution. Else the above, when removing the first $computer from line 5, should give you an idea.
    LVL 11

    Expert Comment

    Oh, haven't noticed it...
    I think the author would like to get the MTU size. PoSh doesn't display it for me either on my Win7 or Win2008 R2. Strange.
    LVL 8

    Author Comment

    Thank you, yes, I am trying to get the MTU Settting on a 2008R2 Server.

    I can't find a way and the above script doesn't seem to give the requested information.

    Additionally the Adminsitrator name portion was taking forever, apparently hanging.  Turns out it just needed a little Tweaking and now it runs in seconds:

        $c = Get-WmiObject Win32_UserAccount -ComputerName $computer -Filter "domain='$computer'" | Where-Object {$_.SID -like 'S-1-5-21-*-500'} | Format-Table -HideTableHeaders Name, SID
    LVL 11

    Accepted Solution

    Strangely, even the registry doesn't contain a hint about MTU.
    Your best bet is to execute NETSH INTERFACE IPV4 SHOW SUBINTERFACES with Invoke-Command. You'll get the output from the NETSH though.
    LVL 8

    Author Closing Comment

    Thanks, it appears that 2k8 uses some kind of dynamic MTU thing now...

    Thansk for the help!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    A commonly asked question on the site recently has been regarding how do I share the GAL between different forests? I want a list of Contacts representing all the users in a remote domain, How do i get them? It's a problem I was posed with a litt…
    Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now