Skip to content

Commit

Permalink
Merge pull request #28 from KnarrStudio/module-testing
Browse files Browse the repository at this point in the history
Module testing
  • Loading branch information
OgJAkFy8 authored Aug 2, 2021
2 parents 0592b04 + 1b81ae8 commit 4568e81
Show file tree
Hide file tree
Showing 20 changed files with 1,596 additions and 1,699 deletions.
Binary file modified ITPS.OMCS.Tools.psd1
Binary file not shown.
690 changes: 690 additions & 0 deletions Modules/ConnectionsModule.psm1

Large diffs are not rendered by default.

432 changes: 432 additions & 0 deletions Modules/FoldersModule.psm1

Large diffs are not rendered by default.

106 changes: 97 additions & 9 deletions Scripts/Test-PrinterStatus.ps1 → Modules/PrintersModule.psm1
Original file line number Diff line number Diff line change
@@ -1,9 +1,100 @@
#requires -Version 3.0 -Modules PrintManagement
# Printer Module
function Add-NetworkPrinter
{
<#
.SYNOPSIS
Retrieves all of the printers you are allowed to see on a print server that you designate.
Allows you to select it and adds the printer to your local workstation.
.PARAMETER PrintServer
Name of the print server you will using.
.PARAMETER Location
The location as indicated on the printer properties
.EXAMPLE
Add-NetworkPrinter -PrintServer Value -Location Value
Finds all of the printers with the location set to the value indicated.
.OUTPUTS
Connection to a networked printer
#>


[cmdletbinding()]
param
(
[Parameter(Mandatory,HelpMessage = 'Enter the printserver name',Position=0)]
[String]$PrintServer,
[Parameter(Position=1)]
[AllowNull()]
[String]$Location

$PrinterSplat = @{
'PrintServer' = 'PrinterServerName'
'PingReportFolder' = '\\FileServerName\Share\Reports'
'Verbose' = $true
)

try
{
if(!(Get-Module -Name PrintManagement))
{
Write-Verbose -Message 'Importing Print Management Module'
Import-Module -Name PrintManagement
}
Write-Verbose -Message 'Print Management Module Imported'
if(Test-Connection -ComputerName $PrintServer -Count 1 -Quiet)
{
if($Location)
{
$PrinterSelection = Get-Printer -ComputerName $PrintServer |
Select-Object -Property Name, Location, DriverName, PortName |
Where-Object{$_.location -match $Location} |
Out-GridView -PassThru -Title 'Printer Select-O-Matic!' -ErrorAction Stop
Write-Verbose -Message ('Printer Selected {0}' -f $PrinterSelection)
}
else
{
$PrinterSelection = Get-Printer -ComputerName $PrintServer |
Select-Object -Property Name, DriverName, PortName |
Out-GridView -PassThru -Title 'Printer Select-O-Matic!' -ErrorAction Stop
Write-Verbose -Message ('Printer Selected {0}' -f $PrinterSelection)
}
$PrinterName = $PrinterSelection.name
Write-Verbose -Message ('Printer Name {0}' -f $PrinterName)

#$PrintServer # = 'test'
Add-Printer -ConnectionName ('\\{0}\{1}' -f $PrintServer, $PrinterName) -ErrorAction Stop
Write-Verbose -Message ('Printer Connected \\{0}\{1}' -f $PrintServer, $PrinterName)
}
else
{
Write-Warning -Message ('Unable to connect to {0}.' -f $PrintServer)
}


#Add-NetworkPrinter -PrintServer ServerName
}
# NOTE: When you use a SPECIFIC catch block, exceptions thrown by -ErrorAction Stop MAY LACK
# some InvocationInfo details such as ScriptLineNumber.
# REMEDY: If that affects you, remove the SPECIFIC exception type [Microsoft.Management.Infrastructure.CimException] in the code below
# and use ONE generic catch block instead. Such a catch block then handles ALL error types, so you would need to
# add the logic to handle different error types differently by yourself.
catch [Microsoft.Management.Infrastructure.CimException]
{
# get error record
[Management.Automation.ErrorRecord]$e = $_

# retrieve information about runtime error
$info = [PSCustomObject]@{
Exception = $e.Exception.Message
Reason = $e.CategoryInfo.Reason
Target = $e.CategoryInfo.TargetName
Script = $e.InvocationInfo.ScriptName
Line = $e.InvocationInfo.ScriptLineNumber
Column = $e.InvocationInfo.OffsetInLine
}

# output information. Post-process collected info, and log info (optional)
$info
}
}

function Test-PrinterStatus
Expand Down Expand Up @@ -160,7 +251,4 @@ $PingPortResult = 'N/A'
Write-Verbose -Message ('Total Printers not responding to a PING: {0}' -f $BadCount)
Write-Verbose -Message "This test was run by $env:USERNAME from $env:COMPUTERNAME"
Write-Verbose -Message ('You can find the full report at: {0}' -f $PrinterStatusReport)
}

Test-PrinterStatus @PrinterSplat

}
203 changes: 168 additions & 35 deletions Scripts/Get-InstalledSoftware.ps1 → Modules/SystemInfoModule.psm1
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#requires -Version 3.0
Function Get-InstalledSoftware
Function Get-InstalledSoftware
{
<#
.SYNOPSIS
Expand Down Expand Up @@ -155,36 +154,170 @@ Function Get-InstalledSoftware
}
}

#
# Get-InstalledSoftware -SortList InstallDate | select -First 10 #| Format-Table -AutoSize
# Get-InstalledSoftware -SoftwareName 'Mozilla Firefox',vlc, Acrobat
# Get-InstalledSoftware





# SIG # Begin signature block
# MIID/AYJKoZIhvcNAQcCoIID7TCCA+kCAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB
# gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR
# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQU68eLK70VkQcSXSRjnLoNkl2j
# pjugggIRMIICDTCCAXagAwIBAgIQapk6cNSgeKlJl3aFtKq3jDANBgkqhkiG9w0B
# AQUFADAhMR8wHQYDVQQDDBZLbmFyclN0dWRpb1NpZ25pbmdDZXJ0MB4XDTIwMDIx
# OTIyMTUwM1oXDTI0MDIxOTAwMDAwMFowITEfMB0GA1UEAwwWS25hcnJTdHVkaW9T
# aWduaW5nQ2VydDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAxtuEswl88jvC
# o69/eD6Rtr5pZikUTNGtI2LqT1a3CZ8F6BCC1tp0+ftZLppxueX/BKVBPTTSg/7t
# f5nkGMFIvbabMiYtfWTPr6L32B4SIZayruDkVETRH74RzG3i2xHNMThZykUWsekN
# jAer+/a2o7F7G6A/GlH8kan4MGjo1K0CAwEAAaNGMEQwEwYDVR0lBAwwCgYIKwYB
# BQUHAwMwHQYDVR0OBBYEFGp363bIyuwL4FI0q36S/8cl5MOBMA4GA1UdDwEB/wQE
# AwIHgDANBgkqhkiG9w0BAQUFAAOBgQBkVkTuk0ySiG3DYg0dKBQaUqI8aKssFv8T
# WNo23yXKUASrgjVl1iAt402AQDHE3aR4OKv/7KIIHYaiFTX5yQdMFoCyhXGop3a5
# bmipv/NjwGWsYrCq9rX2uTuNpUmvQ+0hM3hRzgZ+M2gmjCT/Pgvia/LJiHuF2SlA
# 7wXAuVRh8jGCAVUwggFRAgEBMDUwITEfMB0GA1UEAwwWS25hcnJTdHVkaW9TaWdu
# aW5nQ2VydAIQapk6cNSgeKlJl3aFtKq3jDAJBgUrDgMCGgUAoHgwGAYKKwYBBAGC
# NwIBDDEKMAigAoAAoQKAADAZBgkqhkiG9w0BCQMxDAYKKwYBBAGCNwIBBDAcBgor
# BgEEAYI3AgELMQ4wDAYKKwYBBAGCNwIBFTAjBgkqhkiG9w0BCQQxFgQUmFlzjq9m
# 5xREyOHXRWWpgaPVEGMwDQYJKoZIhvcNAQEBBQAEgYCD5c4lTnEyIh/FRxomeeft
# zA1nxtM1LDOgp8KfK8+3BMg9KHUBoseA/bgZlUooB4/ZGFeYve7vHyv0hEdwfqnX
# BDmc4DnkpBAVm0zWhfhOdv4qGd/A/g/0JHt5y8o7FQ2z9UhmWwA2BqU8CeigRpo2
# J7WE0Be13hKGbiYC7KL/0Q==
# SIG # End signature block
function Get-SystemUpTime
{
<#PSScriptInfo
.VERSION 1.7
.GUID 4f5d3d64-7d6e-407e-a902-cdbc1b6175cd
.AUTHOR Erik
.COMPANYNAME KnarrStudio
.COPYRIGHT
.TAGS
.LICENSEURI
.PROJECTURI https://knarrstudio.github.io/ITPS.OMCS.Tools/
.ICONURI
.EXTERNALMODULEDEPENDENCIES
.REQUIREDSCRIPTS
.EXTERNALSCRIPTDEPENDENCIES
.RELEASENOTES
.PRIVATEDATA
#>

<#
.SYNOPSIS
Returns the last boot time and uptime in hours for one or many computers
.DESCRIPTION
Returns system uptime
.PARAMETER ComputerName
One or Many Computers
.PARAMETER ShowOfflineComputers
Returns a list of the computers that did not respond.
.EXAMPLE
Get-UpTime -ComputerName Value -ShowOfflineComputers
Returns the last boot time and uptime in hours of the list of computers in "value" and lists the computers that did not respond
.OUTPUTS
ComputerName LastBoot TotalHours
------------ -------- ----------
localhost 10/9/2019 00:09:28 407.57
tester Unable to Connect Error Shown Below
Errors for Computers not able to connect.
tester Error: The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
#>

[cmdletbinding(DefaultParameterSetName = 'DisplayOnly')]
Param (
[Parameter(ValueFromPipeline,ValueFromPipelineByPropertyName,Position = 0)]
[Alias('hostname')]
[string[]]$ComputerName = $env:COMPUTERNAME,
[Parameter (ParameterSetName = 'DisplayOnly')]
[Switch]$ShowOfflineComputers,
<# [Parameter (ParameterSetName = 'DisplayOnly')]
[Switch]$DisplayOnly,#>
[Parameter (ParameterSetName = 'DisplayOnly')]
[Switch]$BootOnly,
[Parameter (ParameterSetName = 'FileOnly')]
[Switch]$FileOnly,
[Parameter (ParameterSetName = 'FileOnly')]
[String]$OutCsv = "$env:HOMEDRIVE\Temp\UpTime.csv"
)

BEGIN {
$ErroredComputers = @()
if($BootOnly)
{
$SelectObjects = 'ComputerName', 'LastBoot'
}
else
{
$SelectObjects = 'ComputerName', 'LastBoot', 'TotalHours'
}
if($DisplayOnly)
{
$OutCsv = $null
}
if($FileOnly)
{
if (Test-Path -Path $OutCsv)
{
$i = 1
$NewFileName = $OutCsv.Trim('.csv')
Do
{
$OutCsv = ('{0}({1}).csv' -f $NewFileName, $i)
$i++
}while (Test-Path -Path $OutCsv)
}
}
}

PROCESS {
Foreach ($Computer in $ComputerName)
{
Try
{
$OS = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $Computer -ErrorAction Stop
$UpTime = (Get-Date) - $OS.ConvertToDateTime($OS.LastBootUpTime)
$Properties = @{
ComputerName = $Computer
LastBoot = $OS.ConvertToDateTime($OS.LastBootUpTime)
TotalHours = ( '{0:n2}' -f $UpTime.TotalHours)
}

$Object = New-Object -TypeName PSObject -Property $Properties | Select-Object -Property $SelectObjects
}
catch
{
if ($ShowOfflineComputers)
{
$ErrorMessage = ('{0} Error: {1}' -f $Computer, $_.Exception.Message)
$ErroredComputers += $ErrorMessage

$Properties = @{
ComputerName = $Computer
LastBoot = 'Unable to Connect'
TotalHours = 'Error Shown Below'
}

$Object = New-Object -TypeName PSObject -Property $Properties | Select-Object -Property $SelectObjects
}
}
finally
{
if($FileOnly)
{
$Object | Export-Csv -Path $OutCsv -Append -NoTypeInformation
Write-Verbose -Message ('Output located {0}' -f $OutCsv)
}

Write-Output -InputObject $Object

$Object = $null
$OS = $null
$UpTime = $null
$ErrorMessage = $null
$Properties = $null
}
}
}

END {
if ($ShowOfflineComputers)
{
Write-Output -InputObject ''
Write-Output -InputObject 'Errors for Computers not able to connect.'
Write-Output -InputObject $ErroredComputers
}
}
}
42 changes: 26 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,41 @@
#### (No connection to the MIT OMCS project)


This is the second go around of some tools. The first was a bunch of scripts, this one although different in not just the exact scripts, but also these have been written as a module.
This is the ~~second~~ third go around of some tools. The original idea was to create a series of tools that could be used by the desk side support tech. I found that some of the tasks that were being completed didn't need to have elevated rights, so I recreated this toolset to be run as the logged on users. Now, months later and a better understanding of modules, Github and life overall, I have done some updates to the overall module and some changes to the code.I found that having to make sure the script was signed and had to "Run-As" an administrator. Both of those were problems that I wanted to get around. So, moving forward, although scripts will be signed, they will be designed so that you can run them as a normal user.

### Original Toolset:
* **Add-NetworkPrinter** - _Unchanged_ You need to know the Print Server Name. It will provide a list of printers that you are allowed to print to.
* **Compare-Folders** - _Minor Changes_ This version allows you to identify a parent folder before select the two to compare.
* **Get-InstalledSoftware** - _Unchanged_ This returns the version of the software named.
* **New-TimedStampFileName** - _Removed_ One of my original funtions that I used in early scripting. It just spits out a file name with a time stamp. It really didn't grow, so it has been removed from this module, and rewritten as _New-TimeStampFile_ which actually creates the file. And moved to the _ITPS.OMCS.CodingFunction_ module.
* **Repair-FolderRedirection** - _Major Changes_ This has been changed from a single script which did both report and fix to two. See below: Get-FolderRedirection and Set-FolderRedirection.
* **Test-AdWorkstationConnections** - _Unchanged_ Collects a list of computers from AD base the the Searchbase you provide and returns two files, first is the full list of computers the next is a list of computer that not responded to the "ping". Because it uses the Net bios name to ping, this also tests the DNS servers. It also gives a list of all of the computers that are in the searchbase.
* **Test-FiberSatellite** - _Unchanged_ "Pings" servers based on your input and gives an does the math and gives an average. This was setup, where it was important to know if we were working over the fiber (~60ms average) or over the satellite (+600ms average). By default it pings the big search engine websites.
**Output example:**
8/2/2021 14:09:13 - _username_ tested 5 remote sites and 5 responded. The average response time: 33ms
The Ping-O-Matic Fiber Tester!
Round Trip Time is GOOD!

* **Test-PrinterStatus** - Similar to _Test-AdWorkstationConnections_, but for printers. You have to provide the printserver name.
* **Test-Replication** - This is a manual "brut force" test of DFSR. It writes to a file on one node and reads it on its replication partner, then does the same thing in reverse. You must know at least two of the replication partners.

### New Tools:
* **Get-SystemUpTime** - This was build after users lieing or not understanding what a Reboot is.
It will give you the following: _ComputerName, LastBoot, TotalHours_
* **Get-FolderRedirection** - _NEW_ Returns the location of the user's files. This is a way to make sure there is nothing wrong with the folder redirection and they are saving to the HD.
* **Set-FolderRedirection** - _NEW_ Changes the location of the user's files and copies them if needed. This will make the changes in the HKCU registry to fix folder redirection.

The original idea was to create a series of tools that could be used by the desk side support tech, but during testing I found that having to make sure the script was signed and had to "Run-As" an administrator. Both of those were problems that I wanted to get around. So, moving forward, although scripts will be signed, they will be designed so that you can run them as a normal user.

### Tools:
* **Add-NetworkPrinter** - This will help you add a printer to your workstation or server. You need to know the Print Server Name.
* **Compare-Folders** - This allows you the ability to compare the files in two folders.
* **Get-InstalledSoftware** - This returns the version of the software named.
* **New-TimedStampFileName** - One of my original funtions. It just spits out a file name with a time stamp.
* **Repair-FolderRedirection** - This will make the changes in the registry to fix folder redirection for the folders that were used at the place I worked when I wrote it.
* **Test-AdWorkstationConnections** - Collects a list of computers from AD base the the Searchbase you provide and returns two files, first is the full list of computers the next is a list of computer that not responded to the "ping". Because it uses the Net bios name to ping, this also tests the DNS servers. It also gives a list of all of the computers that are in the searchbase.
* **Test-FiberSatellite** - "Pings" servers based on your input. It pings the big search engine websites.
* **Test-PrinterStatus** - Similar to the AD workstation connection is does the same for printers. You have to provide the printserver name.
* **Test-Replication** - Perform a test to ensure Replication is working. You must know at least two of the replication partners

```PowerShell
Test-FiberSatellite -Sites Value -Simple
Import-Module -Name ITPS.OMCS.Tools -Scope Local # When using this as a normal user.
```

### Module Downloads:

Latest Version at [PowerShell Gallery](https://www.powershellgallery.com/packages/ITPS.OMCS.Tools/1.8.1)
Version 1.8.1 has been uploaded to the [PowerShell Gallery](https://www.powershellgallery.com/packages/ITPS.OMCS.Tools/1.8.1)

At [Github](https://github.com/KnarrStudio/ITPS.OMCS.Tools)
This current version 1.12.2.8 is only available at [Github](https://github.com/KnarrStudio/ITPS.OMCS.Tools) under the **Module Testing** branch.


Loading

0 comments on commit 4568e81

Please sign in to comment.