diff --git a/ITPS.OMCS.Tools.psd1 b/ITPS.OMCS.Tools.psd1 index 5f53f95..8b258fb 100644 Binary files a/ITPS.OMCS.Tools.psd1 and b/ITPS.OMCS.Tools.psd1 differ diff --git a/Modules/ConnectionsModule.psm1 b/Modules/ConnectionsModule.psm1 new file mode 100644 index 0000000..658aae0 --- /dev/null +++ b/Modules/ConnectionsModule.psm1 @@ -0,0 +1,690 @@ +#!/usr/bin/env powershell +#requires -Version 3.0 + +function Test-AdWorkstationConnections +{ + <# + .SYNOPSIS + Pulls a list of computers from AD and then 'pings' them. + + .DESCRIPTION + Pulls a list of computers from AD based on the searchbase you pass and stores them in a csv file. Then it reads the file and 'pings' each name in the file. If the computer does not respond, it will log it into another csv file report. + + .PARAMETER ADSearchBase + Defines where you want to search such as - 'OU=Clients-Desktop,OU=Computers,DC=Knarrstudio,DC=net' + + .PARAMETER WorkstationReportFolder + This is the folder where you want the output to be stored such as - '\\server\share\Reports\WorkstationReport' or 'c:\temp' + + .PARAMETER OutputFileName + The name of the file. Actually base name of the file. Passing 'AdDesktop' will result in the following file names - '20191112-1851-AdDesktop_List.csv' and '20191112-1851-AdDesktop_Report.csv' + + .PARAMETER Bombastic + Is a synonym for verose. It doesn't quite do verbose, but gives you an output to the screen. Without it you only the the report. Does you verbose when running as a job. + + .EXAMPLE + Test-AdWorkstationConnections -ADSearchBase Value -WorkstationReportFolder Value -OutputFileName Value -Bombastic + + This will give you two files a list and a report. Plus it will give you a count of the computers found and reported with a link the report file. + + + .NOTES + Place additional notes here. + + .LINK + URLs to related sites + https://knarrstudio.github.io/ITPS.OMCS.Tools/ + + https://github.com/KnarrStudio/ITPS.OMCS.Tools + + .INPUTS + None other than the parameters + + .OUTPUTS + The default information in the help file will produce the following: + \\server\share\Reports\WorkstationReport\20191112-1851-AdDesktop_Report.csv + \\server\share\Reports\WorkstationReport\20191112-1851-AdDesktop_List.csv + + ------------------ Bombasistic Output ---------- + Total workstations found in AD: 32 + Total workstations not responding: 5 + This test was run by myusername from Workstation-1 + You can find the full report at: \\server\share\Reports\WorkstationReport\20191112-1851-AdDesktop_Report.csv + + #> + + [CmdletBinding(SupportsShouldProcess = $true,ConfirmImpact = 'Low')] + param( + + [Parameter(Mandatory = $false, Position = 1)] + [String] + $ADSearchBase = 'OU=Clients-Desktop,OU=Computers,DC=Knarrstudio,DC=net', + + [Parameter(Mandatory = $false, Position = 0)] + [String] + $WorkstationReportFolder = "$env:temp/Reports/WorkstationReport", + + [Parameter(Mandatory = $false, Position = 2)] + [string] + $OutputFileName = 'AdDesktop', + + [Switch]$Bombastic + ) + + $i = 1 + $BadCount = 0 + $DateNow = Get-Date -UFormat %Y%m%d-%H%M + $OutputFileNameReport = ('{0}\{1}-{2}_Report.csv' -f $WorkstationReportFolder, $DateNow, $OutputFileName) + $WorkstationSiteList = ('{0}\{1}-{2}_List.csv' -f $WorkstationReportFolder, $DateNow, $OutputFileName) + + + if(!(Test-Path -Path $WorkstationReportFolder)) + { + New-Item -Path $WorkstationReportFolder -ItemType Directory + } + + if((Get-Module -Name ActiveDirectory)) + { + Get-ADComputer -filter * -SearchBase $ADSearchBase -Properties * | + Select-Object -Property Name, LastLogonDate, Description | + Sort-Object -Property LastLogonDate -Descending | + Export-Csv -Path $WorkstationSiteList -NoTypeInformation + } + Else + { + $OutputFileName = (Get-ChildItem -Path $OutputFileName | + Sort-Object -Property LastWriteTime | + Select-Object -Last 1).Name + $WorkstationSiteList = ('{0}\{1}' -f $WorkstationReportFolder, $OutputFileName) + Write-Warning -Message ('This is being run using the AD report from {0}' -f $OutputFileName) + } + + $WorkstationList = Import-Csv -Path $WorkstationSiteList -Header Name + $TotalWorkstations = $WorkstationList.count -1 + + if($TotalWorkstations -gt 0) + { + foreach($OneWorkstation in $WorkstationList) + { + $WorkstationName = $OneWorkstation.Name + if ($WorkstationName -ne 'Name') + { + Write-Progress -Activity ('Testing {0}' -f $WorkstationName) -PercentComplete ($i / $TotalWorkstations*100) + $i++ + $Ping = Test-Connection -ComputerName $WorkstationName -Count 1 -Quiet + if($Ping -ne 'True') + { + $BadCount ++ + $WorkstationProperties = Get-ADComputer -Identity $WorkstationName -Properties * | Select-Object -Property Name, LastLogonDate, Description + if($BadCount -eq 1) + { + $WorkstationProperties | Export-Csv -Path $OutputFileNameReport -NoClobber -NoTypeInformation + } + else + { + $WorkstationProperties | Export-Csv -Path $OutputFileNameReport -NoTypeInformation -Append + } + } + } + } + } + + if ($Bombastic) + { + Write-Host -Object ('Total workstations found in AD: {0}' -f $TotalWorkstations) -ForegroundColor Green + Write-Host -Object ('Total workstations not responding: {0}' -f $BadCount) -ForegroundColor Red + Write-Host -Object "This test was run by $env:USERNAME from $env:COMPUTERNAME" + Write-Host -Object ('You can find the full report at: {0}' -f $OutputFileNameReport) + } +} + +function Test-FiberSatellite +{ + <# + .SYNOPSIS + "Pings" a group of sites or servers and gives a response in laymans terms. + + .DESCRIPTION + "Pings" a group of sites or servers and gives a response in laymans terms. + This started due to our need to find out if transport was over fiber or bird. + There are some default remote sites that it will test, but you can pass your own if you only want to check one or two sites. + + .PARAMETER Sites + A single or list of sites or servers that you want to test against. + + .PARAMETER Simple + Provides a single output line for those who just need answers. + + .PARAMETER Log + Sends the output to a log file. + + .PARAMETER ReportFolder + The folder where the output log will be sent. + + .EXAMPLE + Test-FiberSatellite -Sites Value + The default values are: ('localhost', 'www.google.com', 'www.bing.com', 'www.wolframalpha.com', 'www.yahoo.com') + + .EXAMPLE + Test-FiberSatellite -Simple + Creates a simple output using the default site list + + .EXAMPLE + Test-FiberSatellite -Log -ReportFile Value + Creates a log file with the year and month to create a monthly log. + + .EXAMPLE + Test-FiberSatellite -Log -ReportCsv Value + If the file exist is will add the results to that file for trending. If it doesn't exist, it will create it. + + .LINK + https://github.com/KnarrStudio/ITPS.OMCS.Tools/wiki/Test-FiberSatellite + + .INPUTS + List of input types that are accepted by this function. + + .OUTPUTS + To console or screen at this time. + #> + <#PSScriptInfo + + .VERSION 4.0 + + .GUID 676612d8-4397-451f-b6e3-bc3ae055a8ff + + .AUTHOR Erik + + .COMPANYNAME Knarr Studio + + .COPYRIGHT + + .TAGS Test, Console, NonAdmin User + + .LICENSEURI + + .PROJECTURI https://github.com/KnarrStudio/ITPS.OMCS.Tools + + .ICONURI + + .EXTERNALMODULEDEPENDENCIES NetTCPIP + + .REQUIREDSCRIPTS + + .EXTERNALSCRIPTDEPENDENCIES + + .RELEASENOTES + + .PRIVATEDATA + + #> + + [cmdletbinding(DefaultParameterSetName = 'Default')] + param + ( + [Parameter(Position = 0)] + [String[]] $Sites = ('localhost', 'www.google.com', 'www.bing.com', 'www.wolframalpha.com', 'www.yahoo.com'), + [Parameter (ParameterSetName = 'Default')] + [Switch]$Simple, + [Parameter (ParameterSetName = 'Log')] + [Switch]$Log, + [Parameter (ParameterSetName = 'Log')] + [String]$ReportFile = "$env:SystemDrive/temp/Reports/FiberSatellite/FiberSatellite.log", + [Parameter(Mandatory,HelpMessage = 'CSV file that is used for trending',Position = 1,ParameterSetName = 'Log')] + [ValidateScript({ + If($_ -match '.csv') + { + $true + } + Else + { + Throw 'Input file needs to be CSV' + } + })][String]$ReportCsv + ) + + #region Initial Setup + function script:f_CurrentLineNumber + { + <# + .SYNOPSIS + Get the line number at the command + #> + + + $MyInvocation.ScriptLineNumber + } + + #region Variables + $TimeStamp = Get-Date -Format G + $ReportList = [Collections.ArrayList]@() + $null = @() + $TotalResponses = $RttTotal = $NotRight = 0 + $TotalSites = $Sites.Count + $YearMonth = Get-Date -Format yyyy-MMMM + + + $OutputTable = @{ + Title = "`nThe Ping-O-Matic Fiber Tester!" + Green = ' Round Trip Time is GOOD!' + Yellow = ' The average is a little high. An email will be generated to send to the Netowrk team to investigate.' + Red = ' Although not always the case this could indicate that you are on the Satellite.' + Report = '' + } + + $VerboseMsg = @{ + 1 = 'Place Holder Message' + 2 = 'Log Switch set' + 3 = 'ReportCsv Test' + 4 = 'Column Test' + 5 = 'Region Setup Files' + 6 = 'Create New File' + } + + $PingStat = [Ordered]@{ + 'DateStamp' = $TimeStamp + } + + #endregion Variables + + #region Setup Log file + Write-Verbose -Message ('Line {0}: Message: {1}' -f $(f_CurrentLineNumber), $VerboseMsg.5) + $ReportFile = [String]$($ReportFile.Replace('.',('_{0}.' -f $YearMonth))) + + If(-not (Test-Path -Path $ReportFile)) + { + Write-Verbose -Message ('Line {0}: Message: {1}' -f $(f_CurrentLineNumber), $VerboseMsg.6) + $null = New-Item -Path $ReportFile -ItemType File -Force + } + + # Log file - with monthly rename + $OutputTable.Title | Add-Content -Path $ReportFile + ('-'*31) | Add-Content -Path $ReportFile + + #endregion Setup Log file + + + #region Setup Output CSV file + Write-Verbose -Message ('Line {0}: Message: {1}' -f $(f_CurrentLineNumber), $VerboseMsg.5) + if($ReportCsv) + { + if(Test-Path -Path $ReportCsv) + { + # Trending CSV file setup and site addition + Write-Verbose -Message ('Line {0}: {1}' -f $(f_CurrentLineNumber), $VerboseMsg.3) + $PingReportInput = Import-Csv -Path $ReportCsv + $ColumnNames = ($PingReportInput[0].psobject.Properties).name + # Add any new sites to the report file + foreach($site in $Sites) + { + Write-Verbose -Message ('Line {0}: Message: {1}' -f $(f_CurrentLineNumber), $site) + if(! $ColumnNames.contains($site)) + { + Write-Verbose -Message ('Line {0}: {1}' -f $(f_CurrentLineNumber), $VerboseMsg.4) + $PingReportInput | Add-Member -MemberType NoteProperty -Name $site -Value $null -Force + $PingReportInput | Export-Csv -Path $ReportCsv -NoTypeInformation + } + } + } + else + { + $null = New-Item -Path $ReportCsv -ItemType File -Force + } + } + #endregion Setup Output CSV file + + #endregion Initial Setup + + ForEach ($site in $Sites) + { + Write-Verbose -Message ('Line {0}: site: {1}' -f $(f_CurrentLineNumber), $site) + $PingReply = Test-NetConnection -ComputerName $site + + $RoundTripTime = $PingReply.PingReplyDetails.RoundtripTime + $RemoteAddress = $PingReply.RemoteAddress + $PingSucceded = $PingReply.PingSucceeded + $RemoteComputerName = $PingReply.Computername + + if($PingSucceded -eq $true) + { + $TotalResponses = $TotalResponses + 1 + $RttTotal += $RoundTripTime + $OutputMessage = ('{0} - RoundTripTime is {1} ms.' -f $site, $RoundTripTime) + + Write-Verbose -Message ('Line {0}: RttTotal {1}' -f $(f_CurrentLineNumber), $RttTotal) + } + if($PingSucceded -eq $false) + { + #$TotalResponses = $TotalResponses - 1 + $NotRight ++ + $OutputMessage = ('{0} - Did not reply' -f $site) + } + + #$OutputMessage = ('{0} - RoundTripTime is {1} ms.' -f $site, $RoundTripTime) + + $OutputMessage | Add-Content -Path $ReportFile + + Write-Verbose -Message ('Line {0}: Message: {1}' -f $(f_CurrentLineNumber), $OutputMessage) + $ReportList += $OutputMessage + + $PingStat[$site] = $RoundTripTime + } + + $RoundTripTime = $RttTotal/$TotalResponses + $TimeStamp = Get-Date -Format G + + $OutputTable.Report = ('{1} - {3} tested {0} remote sites and {2} responded. The average response time: {4}ms' -f $TotalSites, $TimeStamp, $TotalResponses, $env:USERNAME, [int]$RoundTripTime) + + Write-Verbose -Message ('Line {0}: Message: {1}' -f $(f_CurrentLineNumber), $OutputTable.Report) + + #region Console Output + If(-Not $Log) + { + Write-Output -InputObject $OutputTable.Report + } + if((-not $Simple) -and (-not $Log)) + { + Write-Output -InputObject $OutputTable.Title + if($RoundTripTime -gt 380) + { + Write-Host -Object (' ') -BackgroundColor Red -ForegroundColor White -NoNewline + Write-Output -InputObject ($OutputTable.Red) + } + ElseIf($RoundTripTime -gt 90) + { + Write-Host -Object (' ') -BackgroundColor Yellow -ForegroundColor White -NoNewline + Write-Output -InputObject ($OutputTable.Yellow) + } + ElseIf($RoundTripTime -gt 1) + { + Write-Host -Object (' ') -BackgroundColor Green -ForegroundColor White -NoNewline + Write-Output -InputObject ($OutputTable.Green) + } + if($NotRight -gt 0) + { + Write-Output -InputObject ('{0} Responded with 0 ms. If you tested the "Localhost" one would be expected.' -f $NotRight) + } + } + #endregion Console Output + + + $LogOutput = ( + @' + +{0} +{2} +{3} +'@ -f $($OutputTable.Report), ('-' * 31), ('You can find the full report at: {0}' -f $ReportFile), ('=' * 31)) + + $LogOutput | Add-Content -Path $ReportFile + + Start-Process -FilePath notepad -ArgumentList $ReportFile + + + #region File Output + If($Log) + { + # Export the hashtable to the file + $PingStat | + ForEach-Object -Process { + [pscustomobject]$_ + } | + Export-Csv -Path $ReportCsv -NoTypeInformation -Force -Append + } + #endregion File Output +} + +function Test-Replication +{ + <# + .SYNOPSIS + Perform a user based test to ensure Replication is working. You must know at least two of the replication partners + + .DESCRIPTION + Perform a user based test to ensure Replication is working. You must know at least two of the replication partners + + .PARAMETER FilePath + Name of the file to test. Format as a txt file with starting with the '\' + + .PARAMETER DfsrServers + Two or more of the replication partner's Net Bios Name + + .PARAMETER test + Test is a switch that is used for testing the script locally. Will be removed in the future. + + .EXAMPLE + Test-Replication -DfsrServers Server1, Server2, Server3 -FilePath \folder-1\test-date.txt + + DFSR Replication Test + + Server1 + Status: Good + Message Replicated: 2/17/2020 08:16:06 - MyUserName Tested replication of this file from Workstation-11 + File Path: \\Server1\Folder-1\test-date.txt + + Server2 + Status: Failed + Message Replicated: 2/17/2020 08:16:06 - MyUserName Tested replication of this file from Workstation-11 + File Path: \\Server2\Folder-1\test-date.txt + + Server3 + Status: File Missing + Message Replicated: 2/17/2020 08:16:06 - MyUserName Tested replication of this file from Workstation-11 + File Path: \\Server3\Folder-1\test-date.txt + + + Good: The file has been replicated + Failed: The file has not replicated + File Missing: is just that + + The file contents will look like: + 12/15/2019 10:01:00 - MyUserName Tested replication of this file from Workstation-11 + 12/15/2019 10:03:48 - MyUserName Tested replication of this file from Workstation-11 + 2/17/2020 08:16:06 - MyUserName Tested replication of this file from Workstation-11 + + .NOTES + Place additional notes here. + + .LINK + URLs to related sites + The first link is opened by Get-Help -Online Test-Replication + + .INPUTS + List of Server names and file path + + .OUTPUTS + Screen and file + #> + + param + ( + [Parameter(Mandatory ,HelpMessage = 'Enter a file and path name. Example "\Sharename\Filename.log"')] + #Reserve for PS ver 6 - [ValidatePattern('(\\[a-zA-Z0-9\-_]{1,}){1,}[\$]{0,1}',ErrorMessage = 'The pattern needs to be \Sharename\Filename')] + [ValidatePattern('(\\[a-zA-Z0-9\-_]{1,}){1,}[\$]{0,1}')] + [String]$FilePath, + [Parameter(Mandatory,HelpMessage = 'DFSR path to test files separated by comma', Position = 0)] + [ValidateCount(2,5)] + [String[]]$DfsrServers, + [Switch]$test + ) + + BEGIN { + <# Testing + $DfsrServers = 'Localhost', 'LENOVA-11' + $FilePath = '\Folder-1\test-date.txt' + $Server = 'Localhost' + Testing #> + + # Time Delay used for the amount of time to wait for replication to occur + [int]$TimeDelay = 30 + + # Getting the first server in the list + $FirstDfsrServer = $DfsrServers[0] + + # Creating the Path + $TestFilePath = ('\\{0}{1}' -f $FirstDfsrServer, $FilePath) + + # Results storage hash table + $Results = [ordered]@{} + + # Messages hash table + $UserMessages = @{ + Msg1 = 'Good: The file has been replicated' + Msg2 = 'Failed: The file has not replicated' + Msg3 = 'File Missing: is just that' + OutputTitle = 'DFSR Replication Test' + } + + function Test-ModeNow + { + <# + .SYNOPSIS + Test-ModeNow is trigger by the "Test" switch. It is used for testing the script locally. Will be removed in the future. + #> + + $tempfilepath = '.\Folder-2\test-date.txt' + if($TestFilePath.Length -gt 0) + { + #$fileProperty = Get-ItemProperty $TestFilePath | Select-Object -Property * + $null = Copy-Item -Path $TestFilePath -Destination $tempfilepath + $null = New-Item -Path $TestFilePath -ItemType File -Force + } + + $copiedFile = Get-ItemProperty -Path $tempfilepath | Select-Object -Property * + if($copiedFile.Length -gt 0) + { + $null = Copy-Item -Path $tempfilepath -Destination $TestFilePath -Force + } + } + function script:f_Timestamp + { + <# + .SYNOPSIS + Time stamp in format - 2/17/2020 10:56:12 + #> + Write-Debug -Message 'function TimeStamp' + $(f_Get-Date -Format G) + } + + function Save-Results + { + <# + .SYNOPSIS + Consolidated Results + #> + + + param + ( + [Parameter(Position = 0)] + [string] $TimeStamp = (f_Timestamp), + [Parameter(Mandatory)] + [string] $Server, + [Parameter(Mandatory)] + [string] $Status, + [Parameter(Mandatory)] + [string] $ReplicaStatement, + [Parameter(Mandatory)] + [string] $ServerShareFile + + ) + + Write-Debug -Message ('function Save-Results - Server: {0}' -f $Server) + Write-Debug -Message ('function Save-Results - Status: {0}' -f $Status) + Write-Debug -Message ('function Save-Results - Statement: {0}' -f $ReplicaStatement) + Write-Debug -Message ('function Save-Results - File Share Path: {0}' -f $ServerShareFile) + + $script:Results = @{} + $Results.$Server = [ordered]@{} + + $Results.Item($Server).Add('Status',$Status) + $Results.Item($Server).Add('Time',$ReplicaStatement) + $Results.Item($Server).Add('Path',$ServerShareFile) + } + } + + PROCESS { + + Write-Debug -Message ('Time: {0}' -f $TimeDelay) + + $TimeStamp = f_Timestamp + Write-Debug -Message ('Date Time: {0}' -f $TimeStamp) + + $ReplicaStatement = ('{0} - {1} initiated the replication test of this file from {2}' -f $TimeStamp, $env:username, $env:COMPUTERNAME) + Write-Debug -Message ('Date Time User Stamp: {0}' -f $ReplicaStatement) + + #$ReplicaStatement = ('{0} - {1}' -f $DateTime, $env:username) + $ReplicaStatement | Out-File -FilePath $TestFilePath -Append + + #Single host testing + if ($test) + { + Test-ModeNow + } + + + foreach($Server in $DfsrServers) + { + $i = 0 + Write-Debug -Message ('foreach Server Loop - Server: {0}' -f $Server) + Write-Debug -Message ('foreach Server Loop - File path: {0}' -f $FilePath) + Write-Debug -Message ('foreach Server Loop - Reset $i to: {0}' -f $i) + + $ServerShareFile = ('\\{0}{1}' -f $Server, $FilePath) + Write-Debug -Message ('foreach Server Loop - Server Share File: {0}' -f $ServerShareFile) + + + If(Test-Path -Path $ServerShareFile) + { + $StopTime = (Get-Date).AddSeconds($TimeDelay) + while($((Get-Date) -le $StopTime)) + { + Write-Progress -Activity ('Testing {0}' -f $FilePath) -PercentComplete ($i / $TimeDelay*100) + Start-Sleep -Seconds 1 + $i++ + + #Single host testing + if ($test) + { + Test-ModeNow + } + + $FileTest = $(f_Get-Content -Path $ServerShareFile | Select-String -Pattern $ReplicaStatement) + Write-Debug -Message ('File test returns: {0}' -f $FileTest) + + If($FileTest) + { + break + } + } + + if($FileTest) + { + $TimeStamp = f_Timestamp + Save-Results -TimeStamp $TimeStamp -Server $Server -Status Good -ReplicaStatement $ReplicaStatement -ServerShareFile $ServerShareFile + } + else + { + $TimeStamp = f_Timestamp + Save-Results -TimeStamp $TimeStamp -Server $Server -Status Failed -ReplicaStatement $ReplicaStatement -ServerShareFile $ServerShareFile + } + } + Else + { + $TimeStamp = f_Timestamp + Save-Results -TimeStamp $TimeStamp -Server $Server -Status 'File Missing' -ReplicaStatement $ReplicaStatement -ServerShareFile $ServerShareFile + } + } + } + END { + + Write-Output -InputObject ("{1} - {0}`n" -f $UserMessages.OutputTitle, $TimeStamp) + foreach($DfsrPartner in $Results.Keys) + { + $Server = $Results[$DfsrPartner] + " {0}`n - Status: {1} `n - Replicated Statement: {2}`n - File Path: {3}`n`n" -f $DfsrPartner, $Server.Status, $Server.Time, $Server.Path + } + Write-Output -InputObject ("{0}`n{1}`n{2}" -f $UserMessages.Msg1, $UserMessages.Msg2, $UserMessages.Msg3) + + } +} + diff --git a/Modules/FoldersModule.psm1 b/Modules/FoldersModule.psm1 new file mode 100644 index 0000000..e720082 --- /dev/null +++ b/Modules/FoldersModule.psm1 @@ -0,0 +1,432 @@ +# Folders Module +#requires -Version 3.0 + +<#PSScriptInfo + + .VERSION 1.3 + + .GUID ffd1c052-9783-4fe0-afff-76d070421959 + + .AUTHOR Erik + + .COMPANYNAME Knarr Studio + + .COPYRIGHT + + .TAGS Folder Redirecton Self Help + + .LICENSEURI + + .PROJECTURI https://github.com/KnarrStudio/ITPS.OMCS.Tools + + .ICONURI + + .EXTERNALMODULEDEPENDENCIES + + .REQUIREDSCRIPTS + + .EXTERNALSCRIPTDEPENDENCIES + + .RELEASENOTES + + + .PRIVATEDATA + +#> + +function Get-FolderRedirection +{ + <# + .SYNOPSIS + Verify the user's folder redirection. + + .DESCRIPTION + From a normal Powershell console. + The script will verify that the path exists and displays it to the console. + This should be run prior to imaging a user's workstaion. + + .PARAMETER Quiet + Suppresses output to console + + .EXAMPLE + Get-FolderRedirection + Sends the current settings to the screen + + .EXAMPLE + Get-FolderRedirection -Quiet + This will do the same as default, but will not show on the console, so the file will have to be opened. + If using this switch, it would be best to use the -errorlog and -resultlog parameters to ensure you know where the files will be stored. + + .EXAMPLE + Get-FolderRedirection -errorlog + Allows you to set the location and name of the error log. + Default = "$env:TEMP\ErrorLog-FolderRedirection-$(Get-Date -UFormat %d%S).txt" + + .EXAMPLE + Get-FolderRedirection -resultlog + Allows you to set the location and name of the result log. + Default = "$env:TEMP\FolderRedirection-$($env:COMPUTERNAME)-$($env:USERNAME).log" + + .NOTES + Really written to standardize the troubleshooting and repair of systems before they are imaged to prevent data loss. + + .LINK + https://github.com/KnarrStudio/ITPS.OMCS.Tools + + .INPUTS + Remote path as a string + + .OUTPUTS + Display to console. + #> + + [CmdletBinding(SupportsShouldProcess,ConfirmImpact = 'Low')] + [OutputType([int])] + Param + ( + [Parameter(ValueFromPipelineByPropertyName,Position = 0)] + [Switch]$Quiet, + [string]$errorlog = "$env:TEMP\ErrorLog-FolderRedirection-$(Get-Date -UFormat %d%S).txt", + [string]$resultlog = "$env:TEMP\FolderRedirection-$($env:COMPUTERNAME)-$($env:USERNAME).log" + + ) + + Begin + { + #$ConfirmPreference = 'High' + + $CompareList = @() + + $FolderList = @{ + 'Desktop' = 'Desktop' + 'Favorites' = 'Favorites' + 'My Music' = 'Music' + 'My Pictures' = 'Pictures' + 'My Video' = 'Videos' + 'Personal' = 'Documents' + } + + $Keys = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders', 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders' + $LocalPath = $Env:USERPROFILE + + } + + PROCESS + { + + + $KeyIndex = $null + foreach($RegKey in $Keys) + { + $CurrentIndex = [array]::indexof($Keys,$RegKey) + Write-Verbose -Message ('CurrentIndex = {0}' -f $CurrentIndex) + if($KeyIndex -ne $CurrentIndex) + { + $KeyIndex = $CurrentIndex + $CompareList += $RegKey.ToString() + } + + foreach($FolderKey in $FolderList.keys) + { + $FolderName = $FolderList.Item($FolderKey) + $OldPath = ('{0}\{1}' -f $LocalPath, $FolderName) + $LeafKey = Split-Path -Path $RegKey -Leaf + $CurrentSettings = Get-ItemProperty -Path $RegKey -Name $FolderKey + $newlist = ('{2}: {0} = {1}' -f $FolderKey, $CurrentSettings.$FolderKey, $LeafKey) + Write-Verbose -Message $newlist + $CompareList += $newlist + + Write-Verbose -Message ('FolderName = {0}' -f $FolderName) + Write-Verbose -Message ('OldPath = {0}' -f $OldPath) + Write-Verbose -Message ('FolderKey = {0}' -f $FolderKey) + Write-Verbose -Message ('RegKey = {0}' -f $RegKey) + + <# F8 Testing -- + $Key = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders' + Get-ItemProperty -Path $key + #> + } + } + } + + END { + if(-not $Quiet) + { + $CompareList + Write-Output -InputObject ('Log File: {0}' -f $resultlog) + } + $CompareList | Out-File -FilePath $resultlog + } +} + +function Set-FolderRedirection +{ + <# + .SYNOPSIS + Change the user's folder redirection. + + .DESCRIPTION + From a normal Powershell console. + The script will set the folder redirection to what is specified in the -RemotePath Parameter. Then it will copy any file that is in the "old path" to the new path if the -NoCopy parameter is not set (default). + + .PARAMETER RemotePath + Makes changes to the home folders based on what you put here. Such as - "H:\_MyComputer". + + .PARAMETER NoCopy + Bypassess the process of copying the items in the old path, most of the time 'local' to the new path. + + .PARAMETER Quiet + Suppresses output to console + + .PARAMETER errorlog + Change the default locaion of the log - Default = "$env:TEMP\ErrorLog-FolderRedirection-$(Get-Date -UFormat %d%S).txt" + + .PARAMETER resultlog + Change the default locaion of the log - Default = "$env:TEMP\FolderRedirection-$($env:USERNAME).log" + + .EXAMPLE + Set-FolderRedirection -RemotePath 'H:\_MyComputer' + This will redirect the folders to the path on the "H:" drive. You must use the 'Repair' parameter if you want to make changes. + + .NOTES + Really written to standardize the troubleshooting and repair of systems before they are imaged to prevent data loss. + + .LINK + https://github.com/KnarrStudio/ITPS.OMCS.Tools + + .INPUTS + Remote path as a string + + .OUTPUTS + Display to console. + #> + + [CmdletBinding(SupportsShouldProcess,ConfirmImpact = 'High')] + [OutputType([int])] + Param + ( + # $RemotePath Path to the Users's home drive if "remotepath" is not set. Often the 'H:' drive. + [Parameter(Mandatory = $True,HelpMessage = 'Add the new location for the folder redirection. RemotePath Path to the Users''s home drive. Often the "H:" drive. Such as - "H:\_MyComputer"',ValueFromPipelineByPropertyName,Position = 0)] + [string]$RemotePath, + [Switch]$NoCopy, + [Switch]$Quiet, + [string]$errorlog = "$env:TEMP\ErrorLog-FolderRedirection-$(Get-Date -UFormat %d%S).txt", + [string]$resultlog = "$env:TEMP\FolderRedirection-$($env:USERNAME).log", + [Object]$param + + ) + Begin + { + #$ConfirmPreference = 'High' + + $CompareList = @() + + $FolderList = @{ + 'Desktop' = 'Desktop' + 'Favorites' = 'Favorites' + 'My Music' = 'Music' + 'My Pictures' = 'Pictures' + 'My Video' = 'Videos' + 'Personal' = 'Documents' + } + + $Keys = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders', 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders' + $LocalPath = $Env:USERPROFILE + #$errorlog = "ErrorLog-FolderRedirection-$(Get-Date -UFormat %d%S).txt" + #$resultlog = "$env:TEMP\FolderRedirection-$($env:USERNAME).log" + } + Process + { + if ($PSCmdlet.ShouldProcess($param)) + { + # The reason for looping through the FolderList first instead of the Registry Keys is to find out which of the folders have been redirected first. + foreach($FolderKey in $FolderList.keys) + { + $FolderName = $FolderList.Item($FolderKey) + $OldPath = ('{0}\{1}' -f $LocalPath, $FolderName) + $NewPath = ('{0}\{1}' -f $RemotePath, $FolderName) + Write-Verbose -Message ('FolderName = {0}' -f $FolderName) + Write-Verbose -Message ('OldPath = {0}' -f $OldPath) + Write-Verbose -Message ('NewPath = {0}' -f $NewPath) + + If(-Not(Test-Path -Path $NewPath )) + { + Write-Verbose -Message ('NewPath = {0}' -f $NewPath) + try + { + New-Item -Path $NewPath -ItemType Directory -ErrorAction Stop + } + catch + { + Write-Output -InputObject ('Error File: {0}' -f $errorlog) + $null = $NewPath + $_.Exception.Message | Out-File -FilePath $errorlog -Append + } + } + + if(-not $NoCopy) + { + Write-Verbose -Message ('OldPath = {0}' -f $OldPath) + try + { + Copy-Item -Path $OldPath -Destination $RemotePath -Force -Recurse -ErrorAction Stop + } + catch + { + Write-Output -InputObject ('Error File: {0}' -f $errorlog) + $null = $OldPath + $_.Exception.Message | Out-File -FilePath $errorlog -Append + } + } + + foreach($RegKey in $Keys) + { + Write-Verbose -Message ('FolderKey = {0}' -f $FolderKey) + Write-Verbose -Message ('FolderName = {0}' -f $FolderName) + Write-Verbose -Message ('RegKey = {0}' -f $RegKey) + + $LeafKey = Split-Path -Path $RegKey -Leaf + #$LeafKey = Split-Path -Path $Keys[0] -Leaf + $CurrentSettings = Get-ItemProperty -Path $RegKey -Name $FolderKey + $newlist = ('{2}: {0} = {1}' -f $FolderKey, $CurrentSettings.$FolderKey, $LeafKey) + Write-Verbose -Message $newlist + $CompareList += $newlist + + <# F8 Testing -- + $Key = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders' + Get-ItemProperty -Path $key + #> + + + # This is the command that actually makes changes to the Registry + Set-ItemProperty -Path $RegKey -Name $FolderKey -Value $NewPath -WhatIf + } + } + } + } + End + { + if(-not $Quiet) + { + $CompareList | Sort-Object + Write-Output -InputObject ('Log File: {0}' -f $resultlog) + } + $CompareList | + Sort-Object | + Out-File -FilePath $resultlog + } +} + +function Compare-Folders +{ + <# + .SYNOPSIS + Compare two folders for clean up + + .EXAMPLE + Compare-Folders -FolderSource "C:\Temp" -FolderDest"\\Network\Fileshare" -Verbose + + .PARAMETER FirstFolder + The source folder -FirstFolder. + + .PARAMETER SecondFolder + The Destination -SecondFolder. + + #> + + + [Cmdletbinding()] + + Param + ( + [Parameter(Mandatory, Position = 0,ValueFromPipeline, ValueFromPipelineByPropertyName)] [Alias('Source','OldFolder')] + [string]$FirstFolder, + [Parameter(Mandatory=$False)][Alias('Destination','Staging')] + [string]$SecondFolder = $null ) + + function Get-FolderStats + { + [CmdletBinding()] + Param + ( + [Parameter(Mandatory = $true, Position = 0)] + [Object]$InputItem + ) + $folderSize = (Get-ChildItem -Path $InputItem -Recurse -Force -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum -ErrorAction SilentlyContinue) + '{0:N2} MB' -f ($folderSize.Sum / 1MB) + Write-Debug -Message ('{0} = {1}' -f $InputItem, $('{0:N2} MB' -f ($folderSize.Sum / 1MB))) + Write-Verbose -Message ('Folder Size = {0}' -f $('{0:N2} MB' -f ($folderSize.Sum / 1MB))) + } + + function Get-Recursed + { + Param + ( + [Parameter(Mandatory, ValueFromPipelineByPropertyName, Position = 0)] + [String]$InputItem + ) + Process + { + $SelectedFolderItems = Get-ChildItem -Path $InputItem -Recurse -Force + + Write-Debug -Message ('Get-Recursed = {0}' -f $InputItem) + Write-Verbose -Message ('Get-Recursed = {0}' -f $InputItem) + if($SelectedFolderItems -eq $null){ + $SelectedFolderItems = Get-ChildItem -Path $InputItem -Recurse -Force + } + Return $SelectedFolderItems = Get-ChildItem -Path $InputItem -Recurse -Force + }} + + function Select-FolderToCompare + { + [CmdletBinding()] + Param + ( + [Parameter(Mandatory = $true, Position = 0)][String]$InputItem, + [Parameter(Mandatory = $true, Position = 1)][String]$Title + ) + $FolderSelected = (Get-ChildItem -Path $InputItem | + Select-Object -Property Name, FullName | + Out-GridView -Title $Title -OutputMode Single ).fullname + + Write-Verbose -Message ('FolderSourceSelected = {0}' -f $FolderSelected) + Write-Debug -Message ('FolderSourceSelected = {0}' -f $FolderSelected) + + Return $FolderSelected + } + + if(-not $SecondFolder){ + $SecondFolder = [String]$FirstFolder + } + + $FirstFolderSelected = Select-FolderToCompare -InputItem $FirstFolder -Title 'Select Folder to Compare' + if($FirstFolderSelected -eq $null) + { + $FirstFolderSelected = 'Nothing Selected' + Break + } + Write-Debug -Message ('FirstFolderSelected = {0}' -f $FirstFolderSelected) + + $SecondFolderSelected = Select-FolderToCompare -InputItem $SecondFolder -Title "Compare to $FirstFolderSelected" + if($SecondFolderSelected -eq $null) + { + $SecondFolderSelected = 'Nothing Selected' + Break + } + Write-Debug -Message ('SecondFolderSelected = {0}' -f $SecondFolderSelected) + + + #$FirstCompare = Get-ChildItem -Path $FirstFolderSelected -Recurse -Force # + $FirstCompare = Get-Recursed -InputItem $FirstFolderSelected + Write-Debug -Message ('FirstCompare = {0}' -f $FirstCompare) + + #$SecondCompare = Get-ChildItem -Path $SecondFolderSelected -Recurse -Force # + $SecondCompare = Get-Recursed -InputItem $SecondFolderSelected + Write-Debug -Message ('SecondCompare = {0}' -f $SecondCompare) + + Compare-Object -ReferenceObject $FirstCompare -DifferenceObject $SecondCompare + + + Write-Verbose -Message ('FolderSourceSize = {0}' -f $(Get-FolderStats -InputItem $FirstFolderSelected)) + Write-Verbose -Message ('FolderDestSize = {0}' -f $(Get-FolderStats -InputItem $SecondFolderSelected)) + Write-Verbose -Message ("'<=' only in {0} " -f $FirstFolderSelected) + Write-Verbose -Message ("'=>' only in {0} " -f $SecondFolderSelected) +} \ No newline at end of file diff --git a/Scripts/Test-PrinterStatus.ps1 b/Modules/PrintersModule.psm1 similarity index 63% rename from Scripts/Test-PrinterStatus.ps1 rename to Modules/PrintersModule.psm1 index 2b8626a..a38fb19 100644 --- a/Scripts/Test-PrinterStatus.ps1 +++ b/Modules/PrintersModule.psm1 @@ -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 @@ -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 - +} \ No newline at end of file diff --git a/Scripts/Get-InstalledSoftware.ps1 b/Modules/SystemInfoModule.psm1 similarity index 50% rename from Scripts/Get-InstalledSoftware.ps1 rename to Modules/SystemInfoModule.psm1 index ea607ee..b3675c9 100644 --- a/Scripts/Get-InstalledSoftware.ps1 +++ b/Modules/SystemInfoModule.psm1 @@ -1,5 +1,4 @@ -#requires -Version 3.0 -Function Get-InstalledSoftware +Function Get-InstalledSoftware { <# .SYNOPSIS @@ -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 + } + } +} diff --git a/README.md b/README.md index ca91ee7..28e077d 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/Scripts/Add-NetworkPrinter.ps1 b/Scripts/Add-NetworkPrinter.ps1 deleted file mode 100644 index 2ce3202..0000000 --- a/Scripts/Add-NetworkPrinter.ps1 +++ /dev/null @@ -1,127 +0,0 @@ -#requires -Version 3.0 -Modules PrintManagement -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 - - ) - - 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 - } -} - - - - - -# SIG # Begin signature block -# MIID/AYJKoZIhvcNAQcCoIID7TCCA+kCAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB -# gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR -# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUHcu9/06llA53921oDRvi91SA -# BUSgggIRMIICDTCCAXagAwIBAgIQapk6cNSgeKlJl3aFtKq3jDANBgkqhkiG9w0B -# 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 -# BgEEAYI3AgELMQ4wDAYKKwYBBAGCNwIBFTAjBgkqhkiG9w0BCQQxFgQUtBRgGUrh -# 1C+P8PhaKi8o0fVzpw8wDQYJKoZIhvcNAQEBBQAEgYB4vqt25KXDALU+Ol3/IoxU -# WPKdthtE61w4ANGPIYAD+ZGSV/YFYgW1IrWMGVPxANqzHmmozjxV544GwL6w4ly7 -# MMsa81HJeyXWTndKlUt4Y5G3106b7NU6UhpEhHoIAjeoYTtxu3SiR2afXFnWIuFC -# QIwKg4esxvAWoDs0zaIAvA== -# SIG # End signature block diff --git a/Scripts/Compare-Folders.ps1 b/Scripts/Compare-Folders.ps1 deleted file mode 100644 index 1a48712..0000000 --- a/Scripts/Compare-Folders.ps1 +++ /dev/null @@ -1,142 +0,0 @@ -function Compare-Folders -{ - <# - .SYNOPSIS - Compare two folders for clean up - - .EXAMPLE - Compare-Folders -FolderSource "C:\Temp" -FolderDest"\\Network\Fileshare" -Verbose - - .PARAMETER FirstFolder - The source folder -FirstFolder. - - .PARAMETER SecondFolder - The Destination -SecondFolder. - - #> - - - [Cmdletbinding()] - - Param - ( - [Parameter(Mandatory, Position = 0,ValueFromPipeline, ValueFromPipelineByPropertyName)] [Alias('Source','OldFolder')] - [string]$FirstFolder, - [Parameter(Mandatory=$False)][Alias('Destination','Staging')] - [string]$SecondFolder = $null ) - - function Get-FolderStats - { - [CmdletBinding()] - Param - ( - [Parameter(Mandatory = $true, Position = 0)] - [Object]$InputItem - ) - $folderSize = (Get-ChildItem -Path $InputItem -Recurse -Force -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum -ErrorAction SilentlyContinue) - '{0:N2} MB' -f ($folderSize.Sum / 1MB) - Write-Debug -Message ('{0} = {1}' -f $InputItem, $('{0:N2} MB' -f ($folderSize.Sum / 1MB))) - Write-Verbose -Message ('Folder Size = {0}' -f $('{0:N2} MB' -f ($folderSize.Sum / 1MB))) - } - - function Get-Recursed - { - Param - ( - [Parameter(Mandatory, ValueFromPipelineByPropertyName, Position = 0)] - [String]$InputItem - ) - Process - { - $SelectedFolderItems = Get-ChildItem -Path $InputItem -Recurse -Force - - Write-Debug -Message ('Get-Recursed = {0}' -f $InputItem) - Write-Verbose -Message ('Get-Recursed = {0}' -f $InputItem) - if($SelectedFolderItems -eq $null){ - $SelectedFolderItems = Get-ChildItem -Path $InputItem -Recurse -Force - } - Return $SelectedFolderItems = Get-ChildItem -Path $InputItem -Recurse -Force - }} - - function Select-FolderToCompare - { - [CmdletBinding()] - Param - ( - [Parameter(Mandatory = $true, Position = 0)][String]$InputItem, - [Parameter(Mandatory = $true, Position = 1)][String]$Title - ) - $FolderSelected = (Get-ChildItem -Path $InputItem | - Select-Object -Property Name, FullName | - Out-GridView -Title $Title -OutputMode Single ).fullname - - Write-Verbose -Message ('FolderSourceSelected = {0}' -f $FolderSelected) - Write-Debug -Message ('FolderSourceSelected = {0}' -f $FolderSelected) - - Return $FolderSelected - } - - if(-not $SecondFolder){ - $SecondFolder = [String]$FirstFolder - } - - $FirstFolderSelected = Select-FolderToCompare -InputItem $FirstFolder -Title 'Select Folder to Compare' - if($FirstFolderSelected -eq $null) - { - $FirstFolderSelected = 'Nothing Selected' - Break - } - Write-Debug -Message ('FirstFolderSelected = {0}' -f $FirstFolderSelected) - - $SecondFolderSelected = Select-FolderToCompare -InputItem $SecondFolder -Title "Compare to $FirstFolderSelected" - if($SecondFolderSelected -eq $null) - { - $SecondFolderSelected = 'Nothing Selected' - Break - } - Write-Debug -Message ('SecondFolderSelected = {0}' -f $SecondFolderSelected) - - - #$FirstCompare = Get-ChildItem -Path $FirstFolderSelected -Recurse -Force # - $FirstCompare = Get-Recursed -InputItem $FirstFolderSelected - Write-Debug -Message ('FirstCompare = {0}' -f $FirstCompare) - - #$SecondCompare = Get-ChildItem -Path $SecondFolderSelected -Recurse -Force # - $SecondCompare = Get-Recursed -InputItem $SecondFolderSelected - Write-Debug -Message ('SecondCompare = {0}' -f $SecondCompare) - - Compare-Object -ReferenceObject $FirstCompare -DifferenceObject $SecondCompare - - - Write-Verbose -Message ('FolderSourceSize = {0}' -f $(Get-FolderStats -InputItem $FirstFolderSelected)) - Write-Verbose -Message ('FolderDestSize = {0}' -f $(Get-FolderStats -InputItem $SecondFolderSelected)) - Write-Verbose -Message ("'<=' only in {0} " -f $FirstFolderSelected) - Write-Verbose -Message ("'=>' only in {0} " -f $SecondFolderSelected) -} - - - -# SIG # Begin signature block -# MIID/AYJKoZIhvcNAQcCoIID7TCCA+kCAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB -# gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR -# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUw+5Q5rbHWy1OhWgTnWnoK07S -# nv6gggIRMIICDTCCAXagAwIBAgIQapk6cNSgeKlJl3aFtKq3jDANBgkqhkiG9w0B -# 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 -# BgEEAYI3AgELMQ4wDAYKKwYBBAGCNwIBFTAjBgkqhkiG9w0BCQQxFgQUEn6HOQ6J -# BNjhOuZ0Y0kO75i1J+swDQYJKoZIhvcNAQEBBQAEgYBc8iPcekHnCgexxvkId3if -# lNkJ3WseAyyYYLOmo5oi2Wu/eO17eOdeInaRRJ8ulK1lDC0sNuLebjJMtcElPHeN -# ub2f2pcEl+xwwfV7Rt1YKRaw9w+pjZCP6kqrAAJ+2F6N43a+P+Y+1fezM5Jcig+Y -# iL7POcfn7UuauwOuohP0qg== -# SIG # End signature block diff --git a/Scripts/Get-SystemUpTime.ps1 b/Scripts/Get-SystemUpTime.ps1 deleted file mode 100644 index 2e297bb..0000000 --- a/Scripts/Get-SystemUpTime.ps1 +++ /dev/null @@ -1,210 +0,0 @@ -#requires -Version 3.0 - -<#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 - -#> - -<# - -.DESCRIPTION - Returns system uptime - -#> - -[CmdletBinding()] -Param() - -function Get-SystemUpTime -{ - - - <# - .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 - } - } -} - - - - - -# SIG # Begin signature block -# MIID/AYJKoZIhvcNAQcCoIID7TCCA+kCAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB -# gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR -# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUQBa53k7aBXvsqSfEi9lP2S/h -# nAOgggIRMIICDTCCAXagAwIBAgIQapk6cNSgeKlJl3aFtKq3jDANBgkqhkiG9w0B -# 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 -# BgEEAYI3AgELMQ4wDAYKKwYBBAGCNwIBFTAjBgkqhkiG9w0BCQQxFgQUwzKQfHuJ -# pvnNm6gpeKEzildgc3UwDQYJKoZIhvcNAQEBBQAEgYBPvG3Il1ohuO3zHbRBskRp -# zCQeB+StRxo2FdvfIiZQFO1Th7oytfJxdh/oAWqQTGlh0VVfjaV59Dxcjp+ou0pS -# BqyJMQ69Amy7LypysHAWQT70VHnAhMUF2sCCoiTv9WgrQ1764wIoHzlOpgd/jMqT -# DES820Hspcjw5B2WsGAzYA== -# SIG # End signature block diff --git a/Scripts/New-TimeStampFileName.ps1 b/Scripts/New-TimeStampFileName.ps1 deleted file mode 100644 index 9e31a53..0000000 --- a/Scripts/New-TimeStampFileName.ps1 +++ /dev/null @@ -1,119 +0,0 @@ -function New-TimeStampFile -{ - <# - .SYNOPSIS - Creates a file or filename with a time stamp in the name - - .DESCRIPTION - Allows you to create a file or filename with a time stamp. You provide the base name, extension, date format and it should do the rest. It should be setup to be a plug-n-play function that can be used in or out of another script. - - .PARAMETER baseNAME - This is the primary name of the file. It will be followed by the date/time stamp. - - .PARAMETER FileType - The extension. ig. csv, txt, log - - .PARAMETER ReportFolder - To acutally create the file add -ReportFolder. - - .EXAMPLE - New-TimeStampFile -baseNAME Value -FileType Value -StampFormat Value -ReportFolder Value - Actually creates the file in the folder specified in the -ReportFolder parameter - - .PARAMETER StampFormat - StampFormat is an integer from 1-4 which selects the date foramat. For more information "Get-Help New-TimeStampFile -full" . - - .EXAMPLE - New-TimeStampFileName -baseNAME TestFile -FileType log -StampFormat 1 - This creates a file TestFile-1910260715.log - - .EXAMPLE - New-TimedStampFileName -baseNAME TestFile -FileType log -StampFormat 2 - This creates a file TestFile-20191026.log - - .EXAMPLE - New-TimedStampFileName -baseNAME TestFile -FileType log -StampFormat 3 - This creates a file TestFile-299071531.log - - .EXAMPLE - New-TimedStampFileName -baseNAME TestFile -FileType log -StampFormat 4 - This creates a file TestFile-2019-10-26T07.16.33.3394199-04.00.log - - .NOTES - StampFormats: - (1) YYMMDDHHmm (Two digit year followed by two digit month day hours minutes. This is good for the report that runs more than once a day) -example 1703162145 - - (2) YYYYMMDD (Four digit year two digit month day. This is for the once a day report) -example 20170316 - - (3) jjjHHmmss (Julian day then hours minutes seconds. Use this when you are testing, troubleshooting or creating. You won't have to worry about overwrite or append errors) -example 160214855 - - (4) YYYY-MM-DDTHH.mm.ss.ms-UTC (Four digit year two digit month and day "T" starts the time section two digit hour minute seconds then milliseconds finish with an hours from UTC -example 2019-04-24T07:23:51.3195398-04:00 - - Old #4: YY/MM/DD_HH.mm (Two digit year/month/day _ Hours:Minutes. This can only be used inside a log file) -example 17/03/16_21:52 - - .INPUTS - Any authorized file name for the base and an extension that has some value to you. - - .OUTPUTS - example output - Filename-20181005.bat - #> - - param - ( - [Parameter(Mandatory,HelpMessage = 'Prefix of file or log name')] - [String]$baseNAME, - [Parameter(Mandatory=$false,HelpMessage = 'Extention of file. txt, csv, log')] - [alias('Extension')] - [String]$FileType= 'log', - [Parameter(Mandatory,HelpMessage = 'Formatting Choice 1 to 4')] - [ValidateRange(1,4)] - [int]$StampFormat, - [Parameter(ValueFromPipeline,HelpMessage = 'Folder Path')] - [AllowNull()] - [String]$ReportFolder - ) - - switch ($StampFormat){ - 1 - { - $DateStamp = Get-Date -UFormat '%y%m%d%H%M' - } # 1703162145 YYMMDDHHmm - 2 - { - $DateStamp = Get-Date -UFormat '%Y%m%d' - } # 20170316 YYYYMMDD - 3 - { - $DateStamp = Get-Date -UFormat '%j%H%M%S' - } # 160214855 jjjHHmmss - 4 - { - $DateStamp = Get-Date -Format o | ForEach-Object -Process {$_ -replace ':', '.'} - # 2019-09-02T14:09:02.1593508-04:00 - - } - default - { - Write-Verbose -Message 'No time format selected' - } - } - - $FileName = ('{0}-{1}.{2}' -f $baseNAME,$DateStamp,$FileType) - - - If ($ReportFolder){ - If(-not (Test-Path -Path $ReportFolder)) - { - $null = New-Item -Path $ReportFolder -ItemType Directory -Force - } - $null = New-Item -Path ('{0}\{1}' -f $ReportFolder, $FileName) -ItemType File -Force - Return ('{0}\{1}' -f $ReportFolder, $FileName) - } - else - { - Return $FileName - } -} - - - diff --git a/Scripts/Publish-Install.ps1 b/Scripts/Publish-Install.ps1 new file mode 100644 index 0000000..a5cf415 --- /dev/null +++ b/Scripts/Publish-Install.ps1 @@ -0,0 +1,33 @@ +#!/usr/bin/env powershell +#requires -Version 2.0 -Modules PowerShellGet + +$PSGallery = 'NasPSGallery' +$ModuleName = 'ITPS.OMCS.Tools' + +if(Test-Path -Path $env:USERPROFILE\Documents\GitHub) +{ + $ModuleLocation = "$env:USERPROFILE\Documents\GitHub\" +} +elseif(Test-Path -Path D:\GitHub\KnarrStudio) +{ + $ModuleLocation = 'D:\GitHub\KnarrStudio\' +} +Set-Location -Path $ModuleLocation + +$PublishSplat = @{ + Name = ('{0}\{1}' -f $ModuleLocation, $ModuleName) + Repository = $PSGallery +} + +$InstallSplat = @{ + Name = $ModuleName + Repository = $PSGallery + Scope = 'CurrentUser' + AllowClobber = $true + Force = $true +} + + +Publish-Module @PublishSplat +Install-Module @InstallSplat + diff --git a/Scripts/Repair-FolderRedirection.ps1 b/Scripts/Repair-FolderRedirection.ps1 deleted file mode 100644 index 90dadce..0000000 --- a/Scripts/Repair-FolderRedirection.ps1 +++ /dev/null @@ -1,213 +0,0 @@ -#requires -Version 3.0 -function Repair-FolderRedirection -{ - <#PSScriptInfo - - .VERSION 1.3 - - .GUID cc7ee278-5103-4711-909c-315e3915ba92 - - .AUTHOR Erik - - .COMPANYNAME Knarr Studio - - .COPYRIGHT - - .TAGS Folder Redirecton Self Help - - .LICENSEURI - - .PROJECTURI https://github.com/KnarrStudio/ITPS.OMCS.Tools - - .ICONURI - - .EXTERNALMODULEDEPENDENCIES - - .REQUIREDSCRIPTS - - .EXTERNALSCRIPTDEPENDENCIES - - .RELEASENOTES - - - .PRIVATEDATA - - #> - <# - .SYNOPSIS - Verify and repair (redirect) the user's folder redirection. - - .DESCRIPTION - From a normal Powershell console. - The script will verify that the path exists, and copies all of the local files to the "Remote" location, then changes the registry to mach that remote location. - Changes the folder redirection settings in the registry. - This should be run prior to imaging a user's workstaion. - - .PARAMETER RemotePath - Makes changes to the home folders based on what you put here. Such as - "$env:HOMEDRIVE\_MyComputer". - - .PARAMETER Repair - Initiats the changes - - .PARAMETER Silent - Suppresses output to console - - .EXAMPLE - Repair-FolderRedirection -RemotePath 'H:\_MyComputer' -Repair - This will redirect the folders to the path on the "H:" drive. You must use the 'Repair' parameter if you want to make changes. - - .EXAMPLE - Repair-FolderRedirection - Sends the current settings to the screen - - .NOTES - Really written to standardize the troubleshooting and repair of systems before they are imaged to prevent data loss. - - .LINK - https://github.com/KnarrStudio/ITPS.OMCS.Tools - - .INPUTS - Remote path as a string - - .OUTPUTS - Display to console. - #> - - [CmdletBinding(SupportsShouldProcess,ConfirmImpact = 'High')] - [OutputType([int])] - Param - ( - # $RemotePath Path to the Users's 'H:' drive - [Parameter(ParameterSetName = 'Repair',ValueFromPipelineByPropertyName,Position = 0)] - [string]$RemotePath = "$env:HOMEDRIVE\_MyComputer", - # Use the Repair switch make changes to settings - [Parameter(ParameterSetName = 'Repair')] - [Switch]$Repair, - [Switch]$Silent - ) - - Begin - { - $ConfirmPreference = 'High' - - $CompareList = @() - - $FolderList = @{ - 'Desktop' = 'Desktop' - 'Favorites' = 'Favorites' - 'My Music' = 'Music' - 'My Pictures' = 'Pictures' - 'My Video' = 'Videos' - 'Personal' = 'Documents' - } - - $Keys = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders', 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders' - $LocalPath = $Env:USERPROFILE - $errorlog = "ErrorLog-FolderRedirection-$(Get-Date -UFormat %d%S).txt" - } - Process - { - foreach($FolderKey in $FolderList.keys) - { - $FolderName = $FolderList.Item($FolderKey) - $OldPath = ('{0}\{1}' -f $LocalPath, $FolderName) - $NewPath = ('{0}\{1}' -f $RemotePath, $FolderName) - Write-Verbose -Message ('FolderName = {0}' -f $FolderName) - Write-Verbose -Message ('OldPath = {0}' -f $OldPath) - Write-Verbose -Message ('NewPath = {0}' -f $NewPath) - - If(-Not(Test-Path -Path $NewPath )) - { - Write-Verbose -Message ('NewPath = {0}' -f $NewPath) - if($Repair) - { - New-Item -Path $NewPath -ItemType Directory - } - } - - Write-Verbose -Message ('OldPath = {0}' -f $OldPath) - try - { - if($Repair) - { - Copy-Item -Path $OldPath -Destination $RemotePath -Force -Recurse -ErrorAction Stop - } - } - catch - { - $OldPath + $_.Exception.Message | Out-File -FilePath ('{0}\{1}' -f $RemotePath, $errorlog) -Append - } - - foreach($RegKey in $Keys) - { - Write-Verbose -Message ('FolderKey = {0}' -f $FolderKey) - Write-Verbose -Message ('FolderName = {0}' -f $FolderName) - Write-Verbose -Message ('RegKey = {0}' -f $RegKey) - - - $LeafKey = Split-Path -Path $RegKey -Leaf - $CurrentSettings = Get-ItemProperty -Path $RegKey -Name $FolderKey - $newlist = ('{2}: {0} = {1}' -f $FolderKey, $CurrentSettings.$FolderKey, $LeafKey) - Write-Verbose -Message $newlist - $CompareList += $newlist - - <# F8 Testing -- - $Key = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders' - Get-ItemProperty -Path $ke - #> - - if($Repair) - { - Set-ItemProperty -Path $RegKey -Name $FolderKey -Value $NewPath - } - } - } - - } - - END { - if(-not $Silent) - { - $CompareList | Sort-Object - Write-Output -InputObject 'Log File: ', $env:TEMP\FolderRedirection.log"" - } - $CompareList | - Sort-Object | - Out-File -FilePath "$env:TEMP\FolderRedirection.log" - } -} - - -# Testing: -# Repair-FolderRedirection -Silent -# Repair-FolderRedirection -Repair -RemotePath h:\_MyComputer -Confirm - - - - - - -# SIG # Begin signature block -# MIID/AYJKoZIhvcNAQcCoIID7TCCA+kCAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB -# gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR -# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQU/T9SUBgOtbwsBe7QeRi+r3xO -# F++gggIRMIICDTCCAXagAwIBAgIQapk6cNSgeKlJl3aFtKq3jDANBgkqhkiG9w0B -# 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 -# BgEEAYI3AgELMQ4wDAYKKwYBBAGCNwIBFTAjBgkqhkiG9w0BCQQxFgQUdNPde3bh -# 4lLZoCGQXvW71q81I2cwDQYJKoZIhvcNAQEBBQAEgYAbk/9AWqDvQZzsRxNi6NFg -# /8otKzQJrSZP7/g0uqPSuLzefaR0AIrsw/Y71Oocv42t7dyPLClyMPIkzpiiLr7+ -# Qx9ebNzMNu4/Ib76TXsTbKuEF+DHtLuj2iPwVyk91AJCe+lHJ+o6I79dvbbQQiPf -# jEORfdKWOYOBIewG8tLqeg== -# SIG # End signature block diff --git a/Scripts/Repair-WindowsUpdate.ps1 b/Scripts/Repair-WindowsUpdate.ps1 new file mode 100644 index 0000000..844bb57 --- /dev/null +++ b/Scripts/Repair-WindowsUpdate.ps1 @@ -0,0 +1,122 @@ +function Repair-WindowsUpdate +{ + #requires -Version 3.0 + <#PSScriptInfo + + .VERSION 2.0 + + .GUID ebdf766e-f61c-49a4-a764-1102ed0ac4dc + + .AUTHOR Erik@home + + .COMPANYNAME KnarrStudio + + .COPYRIGHT 2021 KnarrStudio + + .RELEASENOTES + Quick script to automate a manual process + + #> + <# + .SYNOPSIS + Automates the steps used to repair Windows Updates. + + .DESCRIPTION + Automates the steps used to repair Windows Updates. + The steps can be found in the Advanced section of the "Troubleshoot problems updating Windows 10" page. See link + + PowerShells the following steps: + net.exe stop wuauserv + net.exe stop cryptSvc + net.exe stop bits + net.exe stop msiserver + ren C:\Windows\SoftwareDistribution -NewName SoftwareDistribution.old + ren C:\Windows\System32\catroot2 -NewName Catroot2.old + net.exe start wuauserv + net.exe start cryptSvc + net.exe start bits + net.exe start msiserver + + + .EXAMPLE + As an admin, run: Repair-WindowsUpdate + + .NOTES + + + .LINK + https://support.microsoft.com/help/4089834?ocid=20SMC10164Windows10 + + #> + BEGIN{ + $asAdmin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) + $UpdateServices = 'wuauserv', 'cryptSvc', 'bits', 'msiserver' + $RenameFiles = "$env:windir\SoftwareDistribution", "$env:windir\System32\catroot2" + + function Set-ServiceState + { + <# + .SYNOPSIS + Start or stop Services based on "Stop / Start" switch + #> + param( + [Parameter(Mandatory,HelpMessage = 'list of services that to stop or start')][string[]]$services, + [Switch]$Stop, + [Switch]$Start + ) + if ($Stop) + { + ForEach ($service in $services) + { + try + { + Stop-Service -InputObject $service -PassThru + } + catch + { + Stop-Service -InputObject $service -Force + } + } + } + if ($Start) + { + ForEach ($service in $services) + { + Start-Service -InputObject $service + } + } + } + + function Rename-Files + { + <# + .SYNOPSIS + Renames files to ".old" + #> + param( + [Parameter(Mandatory,HelpMessage = 'list of files to be renamed with ".old"')][string[]]$Files + ) + ForEach($File in $Files) + { + Rename-Item -Path $File -NewName ('{0}.old' -f $File) -Force + } + } + } + + PROCESS{ + if ($asAdmin -eq $true) + { + Set-ServiceState -services $UpdateServices -Stop + Rename-Files -Files $RenameFiles + Set-ServiceState -services $UpdateServices -Start + } + else + { + Write-Host -Object '*** Re-run as an administrator ******' -ForegroundColor Black -BackgroundColor Yellow + } + } + + END{ + } +} + diff --git a/Start-DailyChecks.ps1 b/Scripts/Start-DailyChecks.ps1 similarity index 100% rename from Start-DailyChecks.ps1 rename to Scripts/Start-DailyChecks.ps1 diff --git a/Scripts/Test-AdWorkstationConnections.ps1 b/Scripts/Test-AdWorkstationConnections.ps1 deleted file mode 100644 index e7f930e..0000000 --- a/Scripts/Test-AdWorkstationConnections.ps1 +++ /dev/null @@ -1,166 +0,0 @@ -#requires -Version 3.0 -function Test-AdWorkstationConnections -{ - <# - .SYNOPSIS - Pulls a list of computers from AD and then 'pings' them. - - .DESCRIPTION - Pulls a list of computers from AD based on the searchbase you pass and stores them in a csv file. Then it reads the file and 'pings' each name in the file. If the computer does not respond, it will log it into another csv file report. - - .PARAMETER ADSearchBase - Defines where you want to search such as - 'OU=Clients-Desktop,OU=Computers,DC=Knarrstudio,DC=net' - - .PARAMETER WorkstationReportFolder - This is the folder where you want the output to be stored such as - '\\server\share\Reports\WorkstationReport' or 'c:\temp' - - .PARAMETER OutputFileName - The name of the file. Actually base name of the file. Passing 'AdDesktop' will result in the following file names - '20191112-1851-AdDesktop_List.csv' and '20191112-1851-AdDesktop_Report.csv' - - .PARAMETER Bombastic - Is a synonym for verose. It doesn't quite do verbose, but gives you an output to the screen. Without it you only the the report. Does you verbose when running as a job. - - .EXAMPLE - Test-AdWorkstationConnections -ADSearchBase Value -WorkstationReportFolder Value -OutputFileName Value -Bombastic - - This will give you two files a list and a report. Plus it will give you a count of the computers found and reported with a link the report file. - - - .NOTES - Place additional notes here. - - .LINK - URLs to related sites - https://knarrstudio.github.io/ITPS.OMCS.Tools/ - - https://github.com/KnarrStudio/ITPS.OMCS.Tools - - .INPUTS - None other than the parameters - - .OUTPUTS - The default information in the help file will produce the following: - \\server\share\Reports\WorkstationReport\20191112-1851-AdDesktop_Report.csv - \\server\share\Reports\WorkstationReport\20191112-1851-AdDesktop_List.csv - - ------------------ Bombasistic Output ---------- - Total workstations found in AD: 32 - Total workstations not responding: 5 - This test was run by myusername from Workstation-1 - You can find the full report at: \\server\share\Reports\WorkstationReport\20191112-1851-AdDesktop_Report.csv - - #> - - [CmdletBinding(SupportsShouldProcess = $true,ConfirmImpact = 'Low')] - param( - - [Parameter(Mandatory = $false, Position = 1)] - [String] - $ADSearchBase = 'OU=Clients-Desktop,OU=Computers,DC=Knarrstudio,DC=net', - - [Parameter(Mandatory = $false, Position = 0)] - [String] - $WorkstationReportFolder = "$env:temp\Reports\WorkstationReport", - - [Parameter(Mandatory = $false, Position = 2)] - [string] - $OutputFileName = 'AdDesktop', - - [Switch]$Bombastic - ) - - $i = 1 - $BadCount = 0 - $DateNow = Get-Date -UFormat %Y%m%d-%H%M - $OutputFileNameReport = ('{0}\{1}-{2}_Report.csv' -f $WorkstationReportFolder, $DateNow, $OutputFileName) - $WorkstationSiteList = ('{0}\{1}-{2}_List.csv' -f $WorkstationReportFolder, $DateNow, $OutputFileName) - - - if(!(Test-Path -Path $WorkstationReportFolder)) - { - New-Item -Path $WorkstationReportFolder -ItemType Directory - } - - if((Get-Module -Name ActiveDirectory)) - { - Get-ADComputer -filter * -SearchBase $ADSearchBase -Properties * | - Select-Object -Property Name, LastLogonDate, Description | - Sort-Object -Property LastLogonDate -Descending | - Export-Csv -Path $WorkstationSiteList -NoTypeInformation - } - Else - { - $OutputFileName = (Get-ChildItem -Path $OutputFileName | - Sort-Object -Property LastWriteTime | - Select-Object -Last 1).Name - $WorkstationSiteList = ('{0}\{1}' -f $WorkstationReportFolder, $OutputFileName) - Write-Warning -Message ('This is being run using the AD report from {0}' -f $OutputFileName) - } - - $WorkstationList = Import-Csv -Path $WorkstationSiteList -Header Name - $TotalWorkstations = $WorkstationList.count -1 - - if($TotalWorkstations -gt 0) - { - foreach($OneWorkstation in $WorkstationList) - { - $WorkstationName = $OneWorkstation.Name - if ($WorkstationName -ne 'Name') - { - Write-Progress -Activity ('Testing {0}' -f $WorkstationName) -PercentComplete ($i / $TotalWorkstations*100) - $i++ - $Ping = Test-Connection -ComputerName $WorkstationName -Count 1 -Quiet - if($Ping -ne 'True') - { - $BadCount ++ - $WorkstationProperties = Get-ADComputer -Identity $WorkstationName -Properties * | Select-Object -Property Name, LastLogonDate, Description - if($BadCount -eq 1) - { - $WorkstationProperties | Export-Csv -Path $OutputFileNameReport -NoClobber -NoTypeInformation - } - else - { - $WorkstationProperties | Export-Csv -Path $OutputFileNameReport -NoTypeInformation -Append - } - } - } - } - } - - if ($Bombastic) - { - Write-Host -Object ('Total workstations found in AD: {0}' -f $TotalWorkstations) -ForegroundColor Green - Write-Host -Object ('Total workstations not responding: {0}' -f $BadCount) -ForegroundColor Red - Write-Host -Object "This test was run by $env:USERNAME from $env:COMPUTERNAME" - Write-Host -Object ('You can find the full report at: {0}' -f $OutputFileNameReport) - } -} - - - - - -# SIG # Begin signature block -# MIID/AYJKoZIhvcNAQcCoIID7TCCA+kCAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB -# gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR -# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUwMOE/gR3RwOHX8LhwiIfczjf -# 4ISgggIRMIICDTCCAXagAwIBAgIQapk6cNSgeKlJl3aFtKq3jDANBgkqhkiG9w0B -# 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 -# BgEEAYI3AgELMQ4wDAYKKwYBBAGCNwIBFTAjBgkqhkiG9w0BCQQxFgQU1FOfclhW -# 3My6FG0zA1qTJDrxiBUwDQYJKoZIhvcNAQEBBQAEgYBOemou9STncvyCwKRy7jUi -# MzhUqDm/Fa045s5XdpF0Dr6++CQ259J+ca7r9HC8UgtDrW1ZrVr/3JQ3J3WSlPYh -# Kd1x2rkL8oIzCMUPFzkSsHox7e6gV+XVM1kvzhsi533ydhDTsYZ44NcZXQmMJMU1 -# eCXYHTmE3cee02pext9T7w== -# SIG # End signature block diff --git a/Scripts/Test-FiberSatellite.ps1 b/Scripts/Test-FiberSatellite.ps1 deleted file mode 100644 index 1fb2664..0000000 --- a/Scripts/Test-FiberSatellite.ps1 +++ /dev/null @@ -1,317 +0,0 @@ -#requires -Version 3.0 -Modules NetTCPIP - -$TestSplat = @{ - 'Log' = $true - 'ReportCsv' = 'C:\Temp\Reports\FiberSatellite\Ping.csv' - 'Reportfile' = 'C:\temp\Reports\FiberSatellite\Ping.log' - 'Sites' = ('localhost', 'www.google.com', 'www.bing.com', 'www.yahoo.com', 'fooman.shoe', 'asssd') - 'Verbose' = $true -} - -function Test-FiberSatellite -{ - <# - .SYNOPSIS - "Pings" a group of sites or servers and gives a response in laymans terms. - - .DESCRIPTION - "Pings" a group of sites or servers and gives a response in laymans terms. - This started due to our need to find out if transport was over fiber or bird. - There are some default remote sites that it will test, but you can pass your own if you only want to check one or two sites. - - .PARAMETER Sites - A single or list of sites or servers that you want to test against. - - .PARAMETER Simple - Provides a single output line for those who just need answers. - - .PARAMETER Log - Sends the output to a log file. - - .PARAMETER ReportFolder - The folder where the output log will be sent. - - .EXAMPLE - Test-FiberSatellite -Sites Value - The default values are: ('localhost', 'www.google.com', 'www.bing.com', 'www.wolframalpha.com', 'www.yahoo.com') - - .EXAMPLE - Test-FiberSatellite -Simple - Creates a simple output using the default site list - - .EXAMPLE - Test-FiberSatellite -Log -ReportFile Value - Creates a log file with the year and month to create a monthly log. - - .EXAMPLE - Test-FiberSatellite -Log -ReportCsv Value - If the file exist is will add the results to that file for trending. If it doesn't exist, it will create it. - - .LINK - https://github.com/KnarrStudio/ITPS.OMCS.Tools/wiki/Test-FiberSatellite - - .INPUTS - List of input types that are accepted by this function. - - .OUTPUTS - To console or screen at this time. - #> - <#PSScriptInfo - - .VERSION 4.0 - - .GUID 676612d8-4397-451f-b6e3-bc3ae055a8ff - - .AUTHOR Erik - - .COMPANYNAME Knarr Studio - - .COPYRIGHT - - .TAGS Test, Console, NonAdmin User - - .LICENSEURI - - .PROJECTURI https://github.com/KnarrStudio/ITPS.OMCS.Tools - - .ICONURI - - .EXTERNALMODULEDEPENDENCIES NetTCPIP - - .REQUIREDSCRIPTS - - .EXTERNALSCRIPTDEPENDENCIES - - .RELEASENOTES - - .PRIVATEDATA - - #> - - [cmdletbinding(DefaultParameterSetName = 'Default')] - param - ( - [Parameter(Position = 0)] - [String[]] $Sites = ('localhost', 'www.google.com', 'www.bing.com', 'www.wolframalpha.com', 'www.yahoo.com'), - [Parameter (ParameterSetName = 'Default')] - [Switch]$Simple, - [Parameter (ParameterSetName = 'Log')] - [Switch]$Log, - [Parameter (ParameterSetName = 'Log')] - [String]$ReportFile = "$env:SystemDrive\temp\Reports\FiberSatellite\FiberSatellite.log", - [Parameter(Mandatory,HelpMessage = 'CSV file that is used for trending',Position = 1,ParameterSetName = 'Log')] - [ValidateScript({ - If($_ -match '.csv') - { - $true - } - Else - { - Throw 'Input file needs to be CSV' - } - })][String]$ReportCsv - ) - - #region Initial Setup - function Get-CurrentLineNumber - { - <# - .SYNOPSIS - Get the line number at the command - #> - - - $MyInvocation.ScriptLineNumber - } - - #region Variables - $TimeStamp = Get-Date -Format G - $ReportList = [Collections.ArrayList]@() - $null = @() - $TotalResponses = $RttTotal = $NotRight = 0 - $TotalSites = $Sites.Count - $YearMonth = Get-Date -Format yyyy-MMMM - - - $OutputTable = @{ - Title = "`nThe Ping-O-Matic Fiber Tester!" - Green = ' Round Trip Time is GOOD!' - Yellow = ' The average is a little high. An email will be generated to send to the Netowrk team to investigate.' - Red = ' Although not always the case this could indicate that you are on the Satellite.' - Report = '' - } - - $VerboseMsg = @{ - 1 = 'Place Holder Message' - 2 = 'Log Switch set' - 3 = 'ReportCsv Test' - 4 = 'Column Test' - 5 = 'Region Setup Files' - 6 = 'Create New File' - } - - $PingStat = [Ordered]@{ - 'DateStamp' = $TimeStamp - } - - #endregion Variables - - #region Setup Log file - Write-Verbose -Message ('Line {0}: Message: {1}' -f $(Get-CurrentLineNumber), $VerboseMsg.5) - $ReportFile = [String]$($ReportFile.Replace('.',('_{0}.' -f $YearMonth))) - - If(-not (Test-Path -Path $ReportFile)) - { - Write-Verbose -Message ('Line {0}: Message: {1}' -f $(Get-CurrentLineNumber), $VerboseMsg.6) - $null = New-Item -Path $ReportFile -ItemType File -Force - } - - # Log file - with monthly rename - $OutputTable.Title | Add-Content -Path $ReportFile - ('-'*31) | Add-Content -Path $ReportFile - - #endregion Setup Log file - - - #region Setup Output CSV file - Write-Verbose -Message ('Line {0}: Message: {1}' -f $(Get-CurrentLineNumber), $VerboseMsg.5) - if($ReportCsv) - { - if(Test-Path -Path $ReportCsv) - { - # Trending CSV file setup and site addition - Write-Verbose -Message ('Line {0}: {1}' -f $(Get-CurrentLineNumber), $VerboseMsg.3) - $PingReportInput = Import-Csv -Path $ReportCsv - $ColumnNames = ($PingReportInput[0].psobject.Properties).name - # Add any new sites to the report file - foreach($site in $Sites) - { - Write-Verbose -Message ('Line {0}: Message: {1}' -f $(Get-CurrentLineNumber), $site) - if(! $ColumnNames.contains($site)) - { - Write-Verbose -Message ('Line {0}: {1}' -f $(Get-CurrentLineNumber), $VerboseMsg.4) - $PingReportInput | Add-Member -MemberType NoteProperty -Name $site -Value $null -Force - $PingReportInput | Export-Csv -Path $ReportCsv -NoTypeInformation - } - } - } - else - { - $null = New-Item -Path $ReportCsv -ItemType File -Force - } - } - #endregion Setup Output CSV file - - #endregion Initial Setup - - ForEach ($site in $Sites) - { - Write-Verbose -Message ('Line {0}: site: {1}' -f $(Get-CurrentLineNumber), $site) - $PingReply = Test-NetConnection -ComputerName $site - - $RoundTripTime = $PingReply.PingReplyDetails.RoundtripTime - $RemoteAddress = $PingReply.RemoteAddress - $PingSucceded = $PingReply.PingSucceeded - $RemoteComputerName = $PingReply.Computername - - if($PingSucceded -eq $true) - { - $TotalResponses = $TotalResponses + 1 - $RttTotal += $RoundTripTime - $OutputMessage = ('{0} - RoundTripTime is {1} ms.' -f $site, $RoundTripTime) - - Write-Verbose -Message ('Line {0}: RttTotal {1}' -f $(Get-CurrentLineNumber), $RttTotal) - } - if($PingSucceded -eq $false) - { - #$TotalResponses = $TotalResponses - 1 - $NotRight ++ - $OutputMessage = ('{0} - Did not reply' -f $site) - } - - #$OutputMessage = ('{0} - RoundTripTime is {1} ms.' -f $site, $RoundTripTime) - - $OutputMessage | Add-Content -Path $ReportFile - - Write-Verbose -Message ('Line {0}: Message: {1}' -f $(Get-CurrentLineNumber), $OutputMessage) - $ReportList += $OutputMessage - - $PingStat[$site] = $RoundTripTime - } - - $RoundTripTime = $RttTotal/$TotalResponses - $TimeStamp = Get-Date -Format G - - $OutputTable.Report = ('{1} - {3} tested {0} remote sites and {2} responded. The average response time: {4}ms' -f $TotalSites, $TimeStamp, $TotalResponses, $env:USERNAME, [int]$RoundTripTime) - - Write-Verbose -Message ('Line {0}: Message: {1}' -f $(Get-CurrentLineNumber), $OutputTable.Report) - - #region Console Output - If(-Not $Log) - { - Write-Output -InputObject $OutputTable.Report - } - if((-not $Simple) -and (-not $Log)) - { - Write-Output -InputObject $OutputTable.Title - if($RoundTripTime -gt 380) - { - Write-Host -Object (' ') -BackgroundColor Red -ForegroundColor White -NoNewline - Write-Output -InputObject ($OutputTable.Red) - } - ElseIf($RoundTripTime -gt 90) - { - Write-Host -Object (' ') -BackgroundColor Yellow -ForegroundColor White -NoNewline - Write-Output -InputObject ($OutputTable.Yellow) - } - ElseIf($RoundTripTime -gt 1) - { - Write-Host -Object (' ') -BackgroundColor Green -ForegroundColor White -NoNewline - Write-Output -InputObject ($OutputTable.Green) - } - if($NotRight -gt 0) - { - Write-Output -InputObject ('{0} Responded with 0 ms. If you tested the "Localhost" one would be expected.' -f $NotRight) - } - } - #endregion Console Output - - - $LogOutput = ( - @' - -{0} -{2} -{3} -'@ -f $($OutputTable.Report), ('-' * 31), ('You can find the full report at: {0}' -f $ReportFile), ('=' * 31)) - - $LogOutput | Add-Content -Path $ReportFile - - Start-Process -FilePath notepad -ArgumentList $ReportFile - - - #region File Output - If($Log) - { - # Export the hashtable to the file - $PingStat | - ForEach-Object -Process { - [pscustomobject]$_ - } | - Export-Csv -Path $ReportCsv -NoTypeInformation -Force -Append - } - #endregion File Output -} - - -Test-FiberSatellite @TestSplat - - -# For Testing: -#Test-FiberSatellite -#Test-FiberSatellite -Simple -#Test-FiberSatellite -Sites localhost,'yahoo.com' -#Test-FiberSatellite -Sites localhost,'yahoo.com' -Simple -#Test-FiberSatellite -Sites localhost,'yahoo.com' -Simple -Verbose -#Test-FiberSatellite -Log -ReportFolder C:\Temp -#Test-FiberSatellite -Log -Verbose diff --git a/Scripts/Test-Replication.ps1 b/Scripts/Test-Replication.ps1 deleted file mode 100644 index 705da8f..0000000 --- a/Scripts/Test-Replication.ps1 +++ /dev/null @@ -1,285 +0,0 @@ -function Test-Replication -{ - <# - .SYNOPSIS - Perform a user based test to ensure Replication is working. You must know at least two of the replication partners - - .DESCRIPTION - Perform a user based test to ensure Replication is working. You must know at least two of the replication partners - - .PARAMETER FilePath - Name of the file to test. Format as a txt file with starting with the '\' - - .PARAMETER DfsrServers - Two or more of the replication partner's Net Bios Name - - .PARAMETER test - Test is a switch that is used for testing the script locally. Will be removed in the future. - - .EXAMPLE - Test-Replication -DfsrServers Server1, Server2, Server3 -FilePath \folder-1\test-date.txt - - DFSR Replication Test - - Server1 - Status: Good - Message Replicated: 2/17/2020 08:16:06 - MyUserName Tested replication of this file from Workstation-11 - File Path: \\Server1\Folder-1\test-date.txt - - Server2 - Status: Failed - Message Replicated: 2/17/2020 08:16:06 - MyUserName Tested replication of this file from Workstation-11 - File Path: \\Server2\Folder-1\test-date.txt - - Server3 - Status: File Missing - Message Replicated: 2/17/2020 08:16:06 - MyUserName Tested replication of this file from Workstation-11 - File Path: \\Server3\Folder-1\test-date.txt - - - Good: The file has been replicated - Failed: The file has not replicated - File Missing: is just that - - The file contents will look like: - 12/15/2019 10:01:00 - MyUserName Tested replication of this file from Workstation-11 - 12/15/2019 10:03:48 - MyUserName Tested replication of this file from Workstation-11 - 2/17/2020 08:16:06 - MyUserName Tested replication of this file from Workstation-11 - - .NOTES - Place additional notes here. - - .LINK - URLs to related sites - The first link is opened by Get-Help -Online Test-Replication - - .INPUTS - List of Server names and file path - - .OUTPUTS - Screen and file - #> - - param - ( - [Parameter(Mandatory ,HelpMessage = 'Enter a file and path name. Example "\Sharename\Filename.log"')] - #Reserve for PS ver 6 - [ValidatePattern('(\\[a-zA-Z0-9\-_]{1,}){1,}[\$]{0,1}',ErrorMessage = 'The pattern needs to be \Sharename\Filename')] - [ValidatePattern('(\\[a-zA-Z0-9\-_]{1,}){1,}[\$]{0,1}')] - [String]$FilePath, - [Parameter(Mandatory,HelpMessage = 'DFSR path to test files separated by comma', Position = 0)] - [ValidateCount(2,5)] - [String[]]$DfsrServers, - [Switch]$test - ) - - BEGIN { - <# Testing - $DfsrServers = 'Localhost', 'LENOVA-11' - $FilePath = '\Folder-1\test-date.txt' - $Server = 'Localhost' - Testing #> - - # Time Delay used for the amount of time to wait for replication to occur - [int]$TimeDelay = 30 - - # Getting the first server in the list - $FirstDfsrServer = $DfsrServers[0] - - # Creating the Path - $TestFilePath = ('\\{0}{1}' -f $FirstDfsrServer, $FilePath) - - # Results storage hash table - $Results = [ordered]@{} - - # Messages hash table - $UserMessages = @{ - Msg1 = 'Good: The file has been replicated' - Msg2 = 'Failed: The file has not replicated' - Msg3 = 'File Missing: is just that' - OutputTitle = 'DFSR Replication Test' - } - - function Test-ModeNow - { - <# - .SYNOPSIS - Test-ModeNow is trigger by the "Test" switch. It is used for testing the script locally. Will be removed in the future. - #> - - $tempfilepath = '.\Folder-2\test-date.txt' - if($TestFilePath.Length -gt 0) - { - #$fileProperty = Get-ItemProperty $TestFilePath | Select-Object -Property * - $null = Copy-Item -Path $TestFilePath -Destination $tempfilepath - $null = New-Item -Path $TestFilePath -ItemType File -Force - } - - $copiedFile = Get-ItemProperty -Path $tempfilepath | Select-Object -Property * - if($copiedFile.Length -gt 0) - { - $null = Copy-Item -Path $tempfilepath -Destination $TestFilePath -Force - } - } - function Get-TimeStamp - { - <# - .SYNOPSIS - Time stamp in format - 2/17/2020 10:56:12 - #> - Write-Debug -Message 'function Get-TimeStamp' - $(Get-Date -Format G) - } - - function Save-Results - { - <# - .SYNOPSIS - Consolidated Results - #> - - - param - ( - [Parameter(Position = 0)] - [string] $TimeStamp = (Get-TimeStamp), - [Parameter(Mandatory)] - [string] $Server, - [Parameter(Mandatory)] - [string] $Status, - [Parameter(Mandatory)] - [string] $ReplicaStatement, - [Parameter(Mandatory)] - [string] $ServerShareFile - - ) - - Write-Debug -Message ('function Save-Results - Server: {0}' -f $Server) - Write-Debug -Message ('function Save-Results - Status: {0}' -f $Status) - Write-Debug -Message ('function Save-Results - Statement: {0}' -f $ReplicaStatement) - Write-Debug -Message ('function Save-Results - File Share Path: {0}' -f $ServerShareFile) - - $script:Results = @{} - $Results.$Server = [ordered]@{} - - $Results.Item($Server).Add('Status',$Status) - $Results.Item($Server).Add('Time',$ReplicaStatement) - $Results.Item($Server).Add('Path',$ServerShareFile) - } - } - - PROCESS { - - Write-Debug -Message ('Time: {0}' -f $TimeDelay) - - $TimeStamp = Get-TimeStamp - Write-Debug -Message ('Date Time: {0}' -f $TimeStamp) - - $ReplicaStatement = ('{0} - {1} initiated the replication test of this file from {2}' -f $TimeStamp, $env:username, $env:COMPUTERNAME) - Write-Debug -Message ('Date Time User Stamp: {0}' -f $ReplicaStatement) - - #$ReplicaStatement = ('{0} - {1}' -f $DateTime, $env:username) - $ReplicaStatement | Out-File -FilePath $TestFilePath -Append - - #Single host testing - if ($test) - { - Test-ModeNow - } - - - foreach($Server in $DfsrServers) - { - $i = 0 - Write-Debug -Message ('foreach Server Loop - Server: {0}' -f $Server) - Write-Debug -Message ('foreach Server Loop - File path: {0}' -f $FilePath) - Write-Debug -Message ('foreach Server Loop - Reset $i to: {0}' -f $i) - - $ServerShareFile = ('\\{0}{1}' -f $Server, $FilePath) - Write-Debug -Message ('foreach Server Loop - Server Share File: {0}' -f $ServerShareFile) - - - If(Test-Path -Path $ServerShareFile) - { - $StopTime = (Get-Date).AddSeconds($TimeDelay) - while($((Get-Date) -le $StopTime)) - { - Write-Progress -Activity ('Testing {0}' -f $FilePath) -PercentComplete ($i / $TimeDelay*100) - Start-Sleep -Seconds 1 - $i++ - - #Single host testing - if ($test) - { - Test-ModeNow - } - - $FileTest = $(Get-Content -Path $ServerShareFile | Select-String -Pattern $ReplicaStatement) - Write-Debug -Message ('File test returns: {0}' -f $FileTest) - - If($FileTest) - { - break - } - } - - if($FileTest) - { - $TimeStamp = Get-TimeStamp - Save-Results -TimeStamp $TimeStamp -Server $Server -Status Good -ReplicaStatement $ReplicaStatement -ServerShareFile $ServerShareFile - } - else - { - $TimeStamp = Get-TimeStamp - Save-Results -TimeStamp $TimeStamp -Server $Server -Status Failed -ReplicaStatement $ReplicaStatement -ServerShareFile $ServerShareFile - } - } - Else - { - $TimeStamp = Get-TimeStamp - Save-Results -TimeStamp $TimeStamp -Server $Server -Status 'File Missing' -ReplicaStatement $ReplicaStatement -ServerShareFile $ServerShareFile - } - } - } - END { - - Write-Output -InputObject ("{1} - {0}`n" -f $UserMessages.OutputTitle, $TimeStamp) - foreach($DfsrPartner in $Results.Keys) - { - $Server = $Results[$DfsrPartner] - " {0}`n - Status: {1} `n - Replicated Statement: {2}`n - File Path: {3}`n`n" -f $DfsrPartner, $Server.Status, $Server.Time, $Server.Path - } - Write-Output -InputObject ("{0}`n{1}`n{2}" -f $UserMessages.Msg1, $UserMessages.Msg2, $UserMessages.Msg3) - - } -} - - - -# Test-Replication -DfsrServers 'Localhost', $env:COMPUTERNAME -FilePath \Folder-1\test-date.txt -test -Debug - - - -# SIG # Begin signature block -# MIID/AYJKoZIhvcNAQcCoIID7TCCA+kCAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB -# gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR -# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUgyXWqei1X4FQIGO0LTXj7WVR -# mj2gggIRMIICDTCCAXagAwIBAgIQapk6cNSgeKlJl3aFtKq3jDANBgkqhkiG9w0B -# 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 -# BgEEAYI3AgELMQ4wDAYKKwYBBAGCNwIBFTAjBgkqhkiG9w0BCQQxFgQUwz1xrGDt -# IotC6bQYnHzW0+xPTpowDQYJKoZIhvcNAQEBBQAEgYAN9d9ktKntCjo/3Kh0naXG -# DhPLv+R49TMe/3vrbj6r7ZGo3/A72/LB0imjbdDK+XrUQnjhwPiob6AuwEMPlZDg -# 3KYzJ3UI9En6olWY8UrWD20oFh8zRmr0ysJ4AqNfRNQ57wT2pCZeg+ZPoKQ+hBgg -# QkmznBAShUcfxlBEu9RDVA== -# SIG # End signature block diff --git a/Scripts/Update-ManifestModule.ps1 b/Scripts/Update-ManifestModule.ps1 new file mode 100644 index 0000000..961f571 --- /dev/null +++ b/Scripts/Update-ManifestModule.ps1 @@ -0,0 +1,19 @@ +#!/usr/bin/env powershell +#requires -Version 2.0 -Modules Microsoft.PowerShell.Utility +$SplatSettings = @{ +Path = "C:\Users\erika\Documents\GitHub\ITPS.OMCS.Tools\ITPS.OMCS.Tools.psd1" +RootModule = '.\loader.psm1' +Guid = "$(New-Guid)" +Author = 'Erik' +CompanyName = 'Knarr Studio' +ModuleVersion = '1.12.2.8' +Description = 'IT PowerShell tools for the Open Minded Common Sense tech' +PowerShellVersion = '3.0' +NestedModules = @('Modules\ConnectionsModule.psm1', 'Modules\FoldersModule.psm1', 'Modules\PrintersModule.psm1', 'Modules\SystemInfoModule.psm1') +FunctionsToExport = 'Repair-WindowsUpdate','Get-SystemUpTime', 'Get-InstalledSoftware', 'Test-PrinterStatus', 'Add-NetworkPrinter', 'Test-SQLConnection', 'Write-Report', 'Test-AdWorkstationConnections', 'Test-FiberSatellite', 'Test-Replication', 'Compare-Folders', 'Set-FolderRedirection', 'Get-FolderRedirection'#CmdletsToExport = '*' +#ModuleList = '.\ITPS.OMCS.CodingFunctions.psm1' +ReleaseNotes = 'Fixing the Functions to export command in the psd1' +} + +New-ModuleManifest @SplatSettings + diff --git a/init.ps1 b/init.ps1 index 669e492..cb9640b 100644 --- a/init.ps1 +++ b/init.ps1 @@ -1,31 +1,9 @@ - +#requires -Version 1.0 + # use this file to define global variables on module scope # or perform other initialization procedures. # this file will not be touched when new functions are exported to # this module. -# SIG # Begin signature block -# MIID7QYJKoZIhvcNAQcCoIID3jCCA9oCAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB -# gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR -# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUjK23pzYT1CbEkoetX/A/Y98J -# Pc2gggINMIICCTCCAXagAwIBAgIQyWSKL3Rtw7JMh5kRI2JlijAJBgUrDgMCHQUA -# MBYxFDASBgNVBAMTC0VyaWtBcm5lc2VuMB4XDTE3MTIyOTA1MDU1NVoXDTM5MTIz -# MTIzNTk1OVowFjEUMBIGA1UEAxMLRXJpa0FybmVzZW4wgZ8wDQYJKoZIhvcNAQEB -# BQADgY0AMIGJAoGBAKYEBA0nxXibNWtrLb8GZ/mDFF6I7tG4am2hs2Z7NHYcJPwY -# CxCw5v9xTbCiiVcPvpBl7Vr4I2eR/ZF5GN88XzJNAeELbJHJdfcCvhgNLK/F4DFp -# kvf2qUb6l/ayLvpBBg6lcFskhKG1vbEz+uNrg4se8pxecJ24Ln3IrxfR2o+BAgMB -# AAGjYDBeMBMGA1UdJQQMMAoGCCsGAQUFBwMDMEcGA1UdAQRAMD6AEMry1NzZravR -# UsYVhyFVVoyhGDAWMRQwEgYDVQQDEwtFcmlrQXJuZXNlboIQyWSKL3Rtw7JMh5kR -# I2JlijAJBgUrDgMCHQUAA4GBAF9beeNarhSMJBRL5idYsFZCvMNeLpr3n9fjauAC -# CDB6C+V3PQOvHXXxUqYmzZpkOPpu38TCZvBuBUchvqKRmhKARANLQt0gKBo8nf4b -# OXpOjdXnLeI2t8SSFRltmhw8TiZEpZR1lCq9123A3LDFN94g7I7DYxY1Kp5FCBds -# fJ/uMYIBSjCCAUYCAQEwKjAWMRQwEgYDVQQDEwtFcmlrQXJuZXNlbgIQyWSKL3Rt -# w7JMh5kRI2JlijAJBgUrDgMCGgUAoHgwGAYKKwYBBAGCNwIBDDEKMAigAoAAoQKA -# ADAZBgkqhkiG9w0BCQMxDAYKKwYBBAGCNwIBBDAcBgorBgEEAYI3AgELMQ4wDAYK -# KwYBBAGCNwIBFTAjBgkqhkiG9w0BCQQxFgQUhtK0nBRRIPXOFTtgQVOvPt6Oktww -# DQYJKoZIhvcNAQEBBQAEgYAUMpHq55u2FUhlFY8HqhrolXHaauOXTSF6a7pg54NQ -# fcQmCOMB/2okIT4j6PKA1quQlgVqxXfKxR5wCx4fBoEbi9yHynN86AOraTWA6tGi -# TfydFxKABLiH8Wa9JnTCQm7rLUFARy0zGx7zZ0plMZ03vU64audzmlWl3TIx9F3F -# Eg== -# SIG # End signature block + diff --git a/loader.psm1 b/loader.psm1 index 383dd09..7b9d5c9 100644 --- a/loader.psm1 +++ b/loader.psm1 @@ -8,38 +8,9 @@ # LOADING ALL FUNCTION DEFINITIONS: -. $PSScriptRoot\Scripts\Add-NetworkPrinter.ps1 -. $PSScriptRoot\Scripts\Compare-Folders.ps1 -. $PSScriptRoot\Scripts\Get-InstalledSoftware.ps1 -. $PSScriptRoot\Scripts\Get-SystemUpTime.ps1 -. $PSScriptRoot\Scripts\New-TimeStampFileName.ps1 -. $PSScriptRoot\Scripts\Repair-FolderRedirection.ps1 -. $PSScriptRoot\Scripts\Test-AdWorkstationConnections.ps1 -. $PSScriptRoot\Scripts\Test-FiberSatellite.ps1 -. $PSScriptRoot\Scripts\Test-PrinterStatus.ps1 -. $PSScriptRoot\Scripts\Test-Replication.ps1 - -# SIG # Begin signature block -# MIID/AYJKoZIhvcNAQcCoIID7TCCA+kCAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB -# gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR -# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUs3lUG76x38Vstpz0RAOQSZrz -# SkCgggIRMIICDTCCAXagAwIBAgIQapk6cNSgeKlJl3aFtKq3jDANBgkqhkiG9w0B -# 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 -# BgEEAYI3AgELMQ4wDAYKKwYBBAGCNwIBFTAjBgkqhkiG9w0BCQQxFgQUyhLmSLi4 -# mrhBY7clsum+/3/jxswwDQYJKoZIhvcNAQEBBQAEgYBMoKME3CRq/IKzMQZzyEM5 -# Jt8d0u6JM2xuIw4xdWiDqcg2UcAgRIH/I5ECFNg32kLAwoAPjkH0Iv4MAvNlmBLI -# 1D3cQr8UE8o41uxqmCx+Qw2xpBIhki6cKyLWTY/1nfmnzGM99xKsI71HSA09P3mk -# 7CxcPuQj/qOLwEP7/q2sVg== -# SIG # End signature block +#. $PSScriptRoot\Modules\ConnectionsModule.psm1 +#. $PSScriptRoot\Modules\FoldersModule.psm1 +#. $PSScriptRoot\Modules\PrintersModule.psm1 +#. $PSScriptRoot\Modules\SystemInfoModule.psm1 +. $PSScriptRoot\Scripts\Test-SQLConnection.ps1 +. $PSScriptRoot\Scripts\Repair-WindowsUpdate.ps1