r/PowerShell • • Jul 29 '18

Announcing PS Sysadmin Toolkit

Fellow Powershellers!

A few days ago I came up with the idea for module that would be a Toolkit of useful functions for system administrators. I posted a request for ideas over in /r/sysadmin, and the response was fantastic.

I'm happy to report that development is well underway. If you'd like to review the module, you may do so here: https://github.com/steviecoaster/PSSysadminToolkit

If you have an idea for a function that could be added to the module, please file an issue, and if you have code already written, do share if you are able, and I'll get it added in. Rather post it in the issue and I'll handle the rest, or submit a PR for me to merge.

The Master branch is relatively empty at the moment, I've got everything in the Dev branch until things are built enough to warrant a Release, at which time, I'll push to Master.

Any and all feedback is most welcome, and an extra set of eyes/hands from you fine folks is more than welcome.

118 Upvotes

27 comments sorted by

9

u/MadBoyEvo Jul 29 '18

I don't get it. You announce PS Sysadmin Toolkit. You get over 100 reddit likes. I check this and there's a single command Get-SystemUpTime. Maybe I'm just weird but if that deserves 100+ likes then ImportExcel and other modules should get 50000 likes.

-2

u/Theratchetnclank Jul 29 '18

Bizzare. This module is terrible and the code is of poor quality. What a waste of time.

4

u/[deleted] Jul 29 '18

Read the post. The content is in Dev. I won't push to master until stuff is solid. There's not much in there now. I just started a few days ago.

2

u/Ta11ow Jul 29 '18

You can switch the default branch to develop no folks don't accidentally PR to master and it displays dev branch by default, if you want :)

1

u/MadBoyEvo Jul 29 '18

I see now... there's the Dev branch. It has more stuff.

2

u/Lee_Dailey [grin] Jul 29 '18

howdy steviecoaster,

have you tested the Get-SystemUptime function? [grin]

New-Object : Cannot find type [System.Collections.Generic.List]: verify that the assembly containing this type is loaded. At line:14 char:22

  • $UptimeObjects = New-Object System.Collections.Generic.List
  •                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    • CategoryInfo : InvalidType: (:) [New-Object], PSArgumentException

    • FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand

there are a lot of oddities in that bit of code. [grin] do you really want anything other than success OR a formal error? i tend to prefer to return "not found" sort of stuff, but others seem to pref feeding any errors to the error stream.

take care,
lee

5

u/[deleted] Jul 29 '18

I will admit that one is.....broken. I had it pretty well working, then changed a bunch of stuff and absentmindedly commited it to the repo. Haha.

1

u/Lee_Dailey [grin] Jul 29 '18

howdy steviecoaster,

naughty, naughty! [grin]

if i was going to include connection info, i would likely do it something like this ...

function Get-SystemUpTime_LD
    {
    <#

    Comment Based Help Here

    #>

    [CmdletBinding()]
    Param
        (
        [Parameter (
            Position = 0
            )]
            [string[]]
            $ComputerName = $env:COMPUTERNAME
        )

    begin {}

    process
        {
        foreach ($CN_Item in $ComputerName)
            {
            $Now = Get-Date
            $LastBootUpTime = $UpTime = '__ Not Available __'
            $WSMan_OK = $False

            $Connect_OK = Test-Connection -ComputerName $CN_Item -Count 1 -Quiet
            if ($Connect_OK)
                {
                $WSMan_OK = [bool](Test-WSMan -ComputerName $CN_Item -ErrorAction SilentlyContinue)
                }
            if ($Connect_OK -and $WSMan_OK)
                {
                $GCIMI_Params = @{
                    ClassName = 'CIM_OperatingSystem'
                    ComputerName = $CN_Item
                    }
                $LastBootUpTime = (Get-CimInstance @GCIMI_Params).LastBootUpTime
                }
            if ($LastBootUpTime -is [datetime])
                {
                $UpTime = $Now - $LastBootUpTime
                }


            [PSCustomObject]@{
                ComputerName = $CN_Item
                LastBootUpTime = $LastBootUpTime
                UpTime = $UpTime
                NetConnection_OK = $Connect_OK
                WSMan_OK = $WSMan_OK
                }
            }
        }

    end {}

    } # end >> Get-SystemUpTime_LD

with this call ...

Get-SystemUpTime_LD -ComputerName BetterNotBeThere, LocalHost

... i get this output ...

ComputerName     : BetterNotBeThere
LastBootUpTime   : __ Not Available __
UpTime           : __ Not Available __
NetConnection_OK : False
WSMan_OK         : False

ComputerName     : LocalHost
LastBootUpTime   : 2018-07-13 11:35:31 PM
UpTime           : 14.23:35:07.9854000
NetConnection_OK : True
WSMan_OK         : True

i would almost certainly add the local computer name to go along with the input computer name. that way you would know why it returned one name LocalHost when it really otta have returned the $env:COMPUTERNAME value. [grin]

if the connection info wasn't wanted, then i would likely wrap it around an Invoke-Command call to the CIM stuff and feed that the single/array $ComputerName and let the system run it all in parallel.

take care,
lee

2

u/[deleted] Jul 29 '18

Yeah, I just got done reworking the script. It pretty well does what you are doing here, just different strokes for different folks :)

1

u/Lee_Dailey [grin] Jul 29 '18

howdy steviecoaster,

the different ways folks get to similar goals is one reason i so very much enjoy reading code here. [grin]

take care,
lee

2

u/[deleted] Jul 29 '18

Isn’t there an environmental variable for that already?

1

u/Lee_Dailey [grin] Jul 29 '18

howdy iwifia,

not on win7. [grin] i dunno about the new win versions, tho.

take care,
lee

2

u/[deleted] Jul 29 '18

If there is I haven't discovered it. And it doesn't give you results for both last boot and uptime.

1

u/Lee_Dailey [grin] Jul 29 '18

howdy steviecoaster,

yep, i thot it was unlikely. perhaps it exists on the 'nix OSs?

take care,
lee

2

u/[deleted] Jul 29 '18

It is on windows 7 with wmf 5.1. I am 99% sure I’ve used it before.

0

u/Lee_Dailey [grin] Jul 29 '18

howdy iwifia,

if it is there, i can't find it. [blush]

os = win7x64,sp1
ps = 5.1
wmf = 5.1

here's a list of the CMD EnvVars ...

ALLUSERSPROFILE
APPDATA
asl.log
ChocolateyInstall
ChocolateyLastPathUpdate
Chocolatey_Bin_Root
CommonProgramFiles
CommonProgramFiles(x86)
CommonProgramW6432
COMPUTERNAME
ComSpec
FP_NO_HOST_CHECK
HOMEDRIVE
HOMEPATH
LOCALAPPDATA
LOGONSERVER
NUMBER_OF_PROCESSORS
OS
Path
PATHEXT
PROCESSOR_ARCHITECTURE
PROCESSOR_IDENTIFIER
PROCESSOR_LEVEL
PROCESSOR_REVISION
ProgramData
ProgramFiles
ProgramFiles(x86)
ProgramW6432
PROMPT
PSModulePath
PUBLIC
SESSIONNAME
SystemDrive
SystemRoot
TEMP
TMP
USERDOMAIN
USERNAME
USERPROFILE
VBOX_MSI_INSTALL_PATH
windir

none of them have any uptime component that i can see. [grin]

take care,
lee

4

u/tsuhg Jul 29 '18

What's the point of your UptimeObjects list?

4

u/LazamairAMD Jul 29 '18

Systems that haven’t been rebooted will most likely not have any pushed updates installed. That, or software that is so crappy that it requires a daily reboot. UptimeObjects is a good thing.

3

u/tsuhg Jul 29 '18

The list isn't used anywhere, that's my question

1

u/QlusiveNL Jul 30 '18

the script is empty for me on github..

2

u/[deleted] Jul 30 '18

I set the default branch to Dev. Could you see if you see content now?

1

u/QlusiveNL Jul 31 '18

thats better, yes :)

0

u/[deleted] Jul 29 '18

[deleted]

2

u/jantari Jul 29 '18

You can do it all yourself, I've done it before. But if you're interested in a module that is something I could look into as a project after my current one (which I'll also post here when it's ready no worries)

2

u/[deleted] Jul 29 '18

[removed] — view removed comment

2

u/[deleted] Jul 30 '18

I hadn't really thought about a prefix. Might not be a terrible idea.