From 1e70b50f32df87c3745d0974a924915a21772483 Mon Sep 17 00:00:00 2001 From: Erik JA Date: Tue, 30 Mar 2021 19:09:55 -0400 Subject: [PATCH 01/33] Updating the Folder Redirction Separating the test from the fix --- Scripts/FolderRedirection.ps1 | 315 +++++++++++++++++++++++++++ Scripts/Get-FolderRedirection.ps1 | 185 ++++++++++++++++ Scripts/Repair-FolderRedirection.ps1 | 43 ++-- 3 files changed, 521 insertions(+), 22 deletions(-) create mode 100644 Scripts/FolderRedirection.ps1 create mode 100644 Scripts/Get-FolderRedirection.ps1 diff --git a/Scripts/FolderRedirection.ps1 b/Scripts/FolderRedirection.ps1 new file mode 100644 index 0000000..47488d8 --- /dev/null +++ b/Scripts/FolderRedirection.ps1 @@ -0,0 +1,315 @@ +#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 = 'High')] + [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) + { + 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) + + $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 + + <# 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 + Stops 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,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" + + ) + + 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 + { + # 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 + } +} \ No newline at end of file diff --git a/Scripts/Get-FolderRedirection.ps1 b/Scripts/Get-FolderRedirection.ps1 new file mode 100644 index 0000000..4d30749 --- /dev/null +++ b/Scripts/Get-FolderRedirection.ps1 @@ -0,0 +1,185 @@ +#requires -Version 3.0 +function Get-FolderRedirection +{ + <#PSScriptInfo + + .VERSION 1.3 + + .GUID c8170885-61c4-4018-97d3-6546c71f9b81 + + .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 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 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 + Get-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 + Get-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 + { + $Keys | ForEach-Object {Write-Output('Registry Key: {0}' -f $_)} + 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 $key + #> + + 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: +# Get-FolderRedirection -Silent +# Get-FolderRedirection -Repair -RemotePath h:\_MyComputer -Confirm + + diff --git a/Scripts/Repair-FolderRedirection.ps1 b/Scripts/Repair-FolderRedirection.ps1 index 90dadce..9956248 100644 --- a/Scripts/Repair-FolderRedirection.ps1 +++ b/Scripts/Repair-FolderRedirection.ps1 @@ -186,28 +186,27 @@ function Repair-FolderRedirection - # SIG # Begin signature block -# MIID/AYJKoZIhvcNAQcCoIID7TCCA+kCAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB +# MIID7QYJKoZIhvcNAQcCoIID3jCCA9oCAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB # 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== +# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUjmAd7kYOiD3flXoNRiLrKxTD +# Zs2gggINMIICCTCCAXagAwIBAgIQyWSKL3Rtw7JMh5kRI2JlijAJBgUrDgMCHQUA +# MBYxFDASBgNVBAMTC0VyaWtBcm5lc2VuMB4XDTE3MTIyOTA1MDU1NVoXDTM5MTIz +# MTIzNTk1OVowFjEUMBIGA1UEAxMLRXJpa0FybmVzZW4wgZ8wDQYJKoZIhvcNAQEB +# BQADgY0AMIGJAoGBAKYEBA0nxXibNWtrLb8GZ/mDFF6I7tG4am2hs2Z7NHYcJPwY +# CxCw5v9xTbCiiVcPvpBl7Vr4I2eR/ZF5GN88XzJNAeELbJHJdfcCvhgNLK/F4DFp +# kvf2qUb6l/ayLvpBBg6lcFskhKG1vbEz+uNrg4se8pxecJ24Ln3IrxfR2o+BAgMB +# AAGjYDBeMBMGA1UdJQQMMAoGCCsGAQUFBwMDMEcGA1UdAQRAMD6AEMry1NzZravR +# UsYVhyFVVoyhGDAWMRQwEgYDVQQDEwtFcmlrQXJuZXNlboIQyWSKL3Rtw7JMh5kR +# I2JlijAJBgUrDgMCHQUAA4GBAF9beeNarhSMJBRL5idYsFZCvMNeLpr3n9fjauAC +# CDB6C+V3PQOvHXXxUqYmzZpkOPpu38TCZvBuBUchvqKRmhKARANLQt0gKBo8nf4b +# OXpOjdXnLeI2t8SSFRltmhw8TiZEpZR1lCq9123A3LDFN94g7I7DYxY1Kp5FCBds +# fJ/uMYIBSjCCAUYCAQEwKjAWMRQwEgYDVQQDEwtFcmlrQXJuZXNlbgIQyWSKL3Rt +# w7JMh5kRI2JlijAJBgUrDgMCGgUAoHgwGAYKKwYBBAGCNwIBDDEKMAigAoAAoQKA +# ADAZBgkqhkiG9w0BCQMxDAYKKwYBBAGCNwIBBDAcBgorBgEEAYI3AgELMQ4wDAYK +# KwYBBAGCNwIBFTAjBgkqhkiG9w0BCQQxFgQUctcJjKxjdAhy4CGJaV9LBJ0FOC4w +# DQYJKoZIhvcNAQEBBQAEgYCZhwOAn0fhGce6aS0MRuiKRGNtUWlW6yJerLacIQGx +# X/O3EJtWgSQBBXhu2DDPFLOWig0ghcIkBB4srhfUGiNMPZ9ER3Kyi8KpOSM/Lku9 +# yUf5aaPSRxLJR0OTObBMzCgaxshSnOBy2V+JnU8uJf1FeEcivu4c5yjFfnyl/HIO +# 6A== # SIG # End signature block From 50b3a1e8fddc542450ab47f26bf6a04a1a51906e Mon Sep 17 00:00:00 2001 From: Erik JA Date: Tue, 30 Mar 2021 19:18:57 -0400 Subject: [PATCH 02/33] Update FolderRedirection.ps1 --- Scripts/FolderRedirection.ps1 | 111 +++++++++++++++++----------------- 1 file changed, 54 insertions(+), 57 deletions(-) diff --git a/Scripts/FolderRedirection.ps1 b/Scripts/FolderRedirection.ps1 index 47488d8..184466f 100644 --- a/Scripts/FolderRedirection.ps1 +++ b/Scripts/FolderRedirection.ps1 @@ -1,40 +1,39 @@ #requires -Version 3.0 - <#PSScriptInfo +<#PSScriptInfo - .VERSION 1.3 + .VERSION 1.3 - .GUID ffd1c052-9783-4fe0-afff-76d070421959 + .GUID ffd1c052-9783-4fe0-afff-76d070421959 - .AUTHOR Erik + .AUTHOR Erik - .COMPANYNAME Knarr Studio + .COMPANYNAME Knarr Studio - .COPYRIGHT + .COPYRIGHT - .TAGS Folder Redirecton Self Help + .TAGS Folder Redirecton Self Help - .LICENSEURI + .LICENSEURI - .PROJECTURI https://github.com/KnarrStudio/ITPS.OMCS.Tools + .PROJECTURI https://github.com/KnarrStudio/ITPS.OMCS.Tools - .ICONURI + .ICONURI - .EXTERNALMODULEDEPENDENCIES + .EXTERNALMODULEDEPENDENCIES - .REQUIREDSCRIPTS + .REQUIREDSCRIPTS - .EXTERNALSCRIPTDEPENDENCIES + .EXTERNALSCRIPTDEPENDENCIES - .RELEASENOTES + .RELEASENOTES - .PRIVATEDATA + .PRIVATEDATA - #> +#> - function Get-FolderRedirection +function Get-FolderRedirection { - <# .SYNOPSIS Verify the user's folder redirection. @@ -114,38 +113,36 @@ { -$KeyIndex = $null -foreach($RegKey in $Keys) - { + $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() - } - - + if($KeyIndex -ne $CurrentIndex) + { + $KeyIndex = $CurrentIndex + $CompareList += $RegKey.ToString() + } - foreach($FolderKey in $FolderList.keys) - { - 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) - + foreach($FolderKey in $FolderList.keys) + { $FolderName = $FolderList.Item($FolderKey) - $OldPath = ('{0}\{1}' -f $LocalPath, $FolderName) - $LeafKey = Split-Path -Path $RegKey -Leaf + $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 #> - } } } @@ -155,14 +152,13 @@ foreach($RegKey in $Keys) { $CompareList Write-Output -InputObject ('Log File: {0}' -f $resultlog) - } + } $CompareList | Out-File -FilePath $resultlog } } function Set-FolderRedirection { - <# .SYNOPSIS Change the user's folder redirection. @@ -208,7 +204,7 @@ function Set-FolderRedirection Param ( # $RemotePath Path to the Users's home drive if "remotepath" is not set. Often the 'H:' drive. - [Parameter(Mandatory=$True,ValueFromPipelineByPropertyName,Position = 0)] + [Parameter(Mandatory = $True,HelpMessage='Add the new location for the folder redirection',ValueFromPipelineByPropertyName,Position = 0)] [string]$RemotePath, [Switch]$NoCopy, [Switch]$Quiet, @@ -254,26 +250,27 @@ function Set-FolderRedirection Write-Verbose -Message ('NewPath = {0}' -f $NewPath) try { - New-Item -Path $NewPath -ItemType Directory -ErrorAction Stop + 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 + 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 - } + 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) @@ -307,9 +304,9 @@ function Set-FolderRedirection { $CompareList | Sort-Object Write-Output -InputObject ('Log File: {0}' -f $resultlog) - } + } $CompareList | Sort-Object | Out-File -FilePath $resultlog } -} \ No newline at end of file +} From 6981c08c5b5d89a884aea8d597c097649bad66f5 Mon Sep 17 00:00:00 2001 From: Erik JA Date: Wed, 7 Apr 2021 11:49:20 -0400 Subject: [PATCH 03/33] Update cleanup --- ITPS.OMCS.Tools.psd1 | 141 ++++++++--------------- Scripts/Get-FolderRedirection.ps1 | 127 ++++++++------------ Scripts/Set-FolderRedirection.ps1 | 185 ++++++++++++++++++++++++++++++ loader.psm1 | 40 +++---- 4 files changed, 296 insertions(+), 197 deletions(-) create mode 100644 Scripts/Set-FolderRedirection.ps1 diff --git a/ITPS.OMCS.Tools.psd1 b/ITPS.OMCS.Tools.psd1 index 5f53f95..3e38d97 100644 --- a/ITPS.OMCS.Tools.psd1 +++ b/ITPS.OMCS.Tools.psd1 @@ -1,136 +1,91 @@ + # -# Module manifest for module 'itps.omcs.tools' +# Module Manifest for Module 'ITPS.OMCS.Tools.psd1 # -# Generated by: Erik +# This manifest file is a PowerShell hashtable with all technical requirements for this module +# This module was autogenerated by ISESteroids (http://www.isesteroids.com) # -# Generated on: 3/3/2020 +# Generated: 2021-03-30 # @{ -# Script module or binary module file associated with this manifest. +# Module Loader File RootModule = 'loader.psm1' -# Version number of this module. -ModuleVersion = '1.8.7.1' +# Version Number +ModuleVersion = '1.10.0.0' -# Supported PSEditions -# CompatiblePSEditions = @() - -# ID used to uniquely identify this module +# Unique Module ID GUID = 'a7717d2d-5c0c-4ccd-b47f-6e2e9149ba73' -# Author of this module +# Module Author Author = 'Erik' -# Company or vendor of this module +# Company CompanyName = 'Knarr Studio' -# Copyright statement for this module +# Copyright Copyright = '(c) 2019 Knarr Studio. All rights reserved.' -# Description of the functionality provided by this module +# Module Description Description = 'IT PowerShell tools for the Open Minded Common Sense tech' -# Minimum version of the Windows PowerShell engine required by this module -PowerShellVersion = '3.0' +# Minimum PowerShell Version Required +PowerShellVersion = '' -# Name of the Windows PowerShell host required by this module -# PowerShellHostName = '' +# Name of Required PowerShell Host +PowerShellHostName = '' -# Minimum version of the Windows PowerShell host required by this module -# PowerShellHostVersion = '' +# Minimum Host Version Required +PowerShellHostVersion = '' -# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only. -# DotNetFrameworkVersion = '' +# Minimum .NET Framework-Version +DotNetFrameworkVersion = '' -# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only. -# CLRVersion = '' +# Minimum CLR (Common Language Runtime) Version +CLRVersion = '' -# Processor architecture (None, X86, Amd64) required by this module -# ProcessorArchitecture = '' +# Processor Architecture Required (X86, Amd64, IA64) +ProcessorArchitecture = '' -# Modules that must be imported into the global environment prior to importing this module -RequiredModules = @('NetTCPIP', - 'PrintManagement') +# Required Modules (will load before this module loads) +RequiredModules = @() -# Assemblies that must be loaded prior to importing this module -# RequiredAssemblies = @() +# Required Assemblies +RequiredAssemblies = @() -# Script files (.ps1) that are run in the caller's environment prior to importing this module. -# ScriptsToProcess = @() +# PowerShell Scripts (.ps1) that need to be executed before this module loads +ScriptsToProcess = @() -# Type files (.ps1xml) to be loaded when importing this module -# TypesToProcess = @() +# Type files (.ps1xml) that need to be loaded when this module loads +TypesToProcess = @() -# Format files (.ps1xml) to be loaded when importing this module -# FormatsToProcess = @() +# Format files (.ps1xml) that need to be loaded when this module loads +FormatsToProcess = @() -# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess +# NestedModules = @() -# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. -FunctionsToExport = 'Add-NetworkPrinter', 'Compare-Folders', 'Get-InstalledSoftware', - 'Get-SystemUpTime', 'New-TimeStampFileName', - 'Repair-FolderRedirection', 'Test-AdWorkstationConnections', - 'Test-FiberSatellite', 'Test-PrinterStatus', 'Test-Replication' +# List of exportable functions +FunctionsToExport = '*' -# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. +# List of exportable cmdlets CmdletsToExport = '*' -# Variables to export from this module +# List of exportable variables VariablesToExport = '*' -# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. +# List of exportable aliases AliasesToExport = '*' -# DSC resources to export from this module -# DscResourcesToExport = @() - -# List of all modules packaged with this module -# ModuleList = @() - -# List of all files packaged with this module -# FileList = @() - -# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. -PrivateData = @{ - - PSData = @{ - - # Tags applied to this module. These help with module discovery in online galleries. - # Tags = @() - - # A URL to the license for this module. - # LicenseUri = '' - - # A URL to the main website for this project. - # ProjectUri = '' - - # A URL to an icon representing this module. - # IconUri = '' - - # ReleaseNotes of this module - # ReleaseNotes = '' - - # Prerelease string of this module - # Prerelease = '' - - # Flag to indicate whether the module requires explicit user acceptance for install/update/save - # RequireLicenseAcceptance = $false - - # External dependent modules of this module - ExternalModuleDependencies = @('NetTCPIP','PrintManagement') - - } # End of PSData hashtable - - } # End of PrivateData hashtable - -# HelpInfo URI of this module -# HelpInfoURI = '' +# List of all modules contained in this module +ModuleList = @() -# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. -# DefaultCommandPrefix = '' +# List of all files contained in this module +FileList = @() -} +# Private data that needs to be passed to this module +PrivateData = '' +} \ No newline at end of file diff --git a/Scripts/Get-FolderRedirection.ps1 b/Scripts/Get-FolderRedirection.ps1 index 4d30749..4c017e7 100644 --- a/Scripts/Get-FolderRedirection.ps1 +++ b/Scripts/Get-FolderRedirection.ps1 @@ -1,11 +1,10 @@ -#requires -Version 3.0 -function Get-FolderRedirection +function Get-FolderRedirection { <#PSScriptInfo .VERSION 1.3 - .GUID c8170885-61c4-4018-97d3-6546c71f9b81 + .GUID 0786a98d-55c0-46a3-9fcf-ed33512b2ff7 .AUTHOR Erik @@ -42,23 +41,28 @@ function Get-FolderRedirection 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 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 + .PARAMETER Quiet Suppresses output to console - .EXAMPLE - Get-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 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. @@ -76,13 +80,11 @@ function Get-FolderRedirection [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 + [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 @@ -102,84 +104,53 @@ function Get-FolderRedirection $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 + + PROCESS { - $Keys | ForEach-Object {Write-Output('Registry Key: {0}' -f $_)} - foreach($FolderKey in $FolderList.keys) + + + $KeyIndex = $null + foreach($RegKey in $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 )) + $CurrentIndex = [array]::indexof($Keys,$RegKey) + Write-Verbose -Message ('CurrentIndex = {0}' -f $CurrentIndex) + if($KeyIndex -ne $CurrentIndex) { - Write-Verbose -Message ('NewPath = {0}' -f $NewPath) - if($Repair) - { - New-Item -Path $NewPath -ItemType Directory - } + $KeyIndex = $CurrentIndex + $CompareList += $RegKey.ToString() } - Write-Verbose -Message ('OldPath = {0}' -f $OldPath) - try + foreach($FolderKey in $FolderList.keys) { - 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) - - + $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 #> - - if($Repair) - { - Set-ItemProperty -Path $RegKey -Name $FolderKey -Value $NewPath - } } } - } END { - if(-not $Silent) + if(-not $Quiet) { - $CompareList | Sort-Object - Write-Output -InputObject 'Log File: ', $env:TEMP\FolderRedirection.log"" + $CompareList + Write-Output -InputObject ('Log File: {0}' -f $resultlog) } - $CompareList | - Sort-Object | - Out-File -FilePath "$env:TEMP\FolderRedirection.log" + $CompareList | Out-File -FilePath $resultlog } -} - - -# Testing: -# Get-FolderRedirection -Silent -# Get-FolderRedirection -Repair -RemotePath h:\_MyComputer -Confirm - - +} \ No newline at end of file diff --git a/Scripts/Set-FolderRedirection.ps1 b/Scripts/Set-FolderRedirection.ps1 new file mode 100644 index 0000000..0ef9de1 --- /dev/null +++ b/Scripts/Set-FolderRedirection.ps1 @@ -0,0 +1,185 @@ +function Set-FolderRedirection +{ + <#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 + + #> + <# + .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 + Stops 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',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" + + ) + + 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 + { + # 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 + } +} \ No newline at end of file diff --git a/loader.psm1 b/loader.psm1 index 383dd09..cc5c1b8 100644 --- a/loader.psm1 +++ b/loader.psm1 @@ -8,38 +8,26 @@ # LOADING ALL FUNCTION DEFINITIONS: +. $PSScriptRoot\Scripts\Get-FolderRedirection.ps1 +. $PSScriptRoot\Scripts\Set-FolderRedirection.ps1 . $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\Scripts\Add-NetworkPrinter.ps1 +. $PSScriptRoot\Scripts\Compare-Folders.ps1 +. $PSScriptRoot\Scripts\Get-FolderRedirection.ps1 +. $PSScriptRoot\Scripts\Get-InstalledSoftware.ps1 +. $PSScriptRoot\Scripts\Get-SystemUpTime.ps1 +. $PSScriptRoot\Scripts\New-TimeStampFileName.ps1 +. $PSScriptRoot\Scripts\Set-FolderRedirection.ps1 +. $PSScriptRoot\Scripts\Test-AdWorkstationConnections.ps1 +. $PSScriptRoot\Scripts\Test-FiberSatellite.ps1 +. $PSScriptRoot\Scripts\Test-PrinterStatus.ps1 +. $PSScriptRoot\Scripts\Test-Replication.ps1 +. $PSScriptRoot\Scripts\Test-SQLConnection.ps1 From d656e3d92107a5160b740126460c9ef101582c69 Mon Sep 17 00:00:00 2001 From: Erik JA Date: Tue, 22 Jun 2021 21:23:17 -0500 Subject: [PATCH 04/33] Updates Folder Redirection Time Stamp File --- Scripts/FolderRedirection.ps1 | 115 ++++++++++---------- Scripts/New-TimeStampFile.ps1 | 193 ++++++++++++++++++++++++++++++++++ 2 files changed, 252 insertions(+), 56 deletions(-) create mode 100644 Scripts/New-TimeStampFile.ps1 diff --git a/Scripts/FolderRedirection.ps1 b/Scripts/FolderRedirection.ps1 index 184466f..c9db6b2 100644 --- a/Scripts/FolderRedirection.ps1 +++ b/Scripts/FolderRedirection.ps1 @@ -78,7 +78,7 @@ function Get-FolderRedirection Display to console. #> - [CmdletBinding(SupportsShouldProcess,ConfirmImpact = 'High')] + [CmdletBinding(SupportsShouldProcess,ConfirmImpact = 'Low')] [OutputType([int])] Param ( @@ -91,7 +91,7 @@ function Get-FolderRedirection Begin { - $ConfirmPreference = 'High' + #$ConfirmPreference = 'High' $CompareList = @() @@ -171,7 +171,7 @@ function Set-FolderRedirection Makes changes to the home folders based on what you put here. Such as - "H:\_MyComputer". .PARAMETER NoCopy - Stops the items in the old path, most of the time 'local' to the new path. + 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 @@ -204,18 +204,18 @@ function Set-FolderRedirection 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',ValueFromPipelineByPropertyName,Position = 0)] + [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" + [string]$resultlog = "$env:TEMP\FolderRedirection-$($env:USERNAME).log", + [Object]$param ) - Begin { - $ConfirmPreference = 'High' + #$ConfirmPreference = 'High' $CompareList = @() @@ -235,71 +235,73 @@ function Set-FolderRedirection } Process { - # 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) + if ($PSCmdlet.ShouldProcess($param)) { - $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 )) + # 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) - 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 + If(-Not(Test-Path -Path $NewPath )) { - Copy-Item -Path $OldPath -Destination $RemotePath -Force -Recurse -ErrorAction Stop + 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 + } } - catch + + if(-not $NoCopy) { - Write-Output -InputObject ('Error File: {0}' -f $errorlog) - $null = $OldPath + $_.Exception.Message | Out-File -FilePath $errorlog -Append + 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) + 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 + $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 - #> + <# 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 + # This is the command that actually makes changes to the Registry + Set-ItemProperty -Path $RegKey -Name $FolderKey -Value $NewPath -WhatIf + } } } - } - - END { + End + { if(-not $Quiet) { $CompareList | Sort-Object @@ -310,3 +312,4 @@ function Set-FolderRedirection Out-File -FilePath $resultlog } } + diff --git a/Scripts/New-TimeStampFile.ps1 b/Scripts/New-TimeStampFile.ps1 new file mode 100644 index 0000000..9ebda54 --- /dev/null +++ b/Scripts/New-TimeStampFile.ps1 @@ -0,0 +1,193 @@ +#requires -Version 1.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 FilePath + where to put the file, if "create" is added. + To create the file add -FilePath. -Use the create parameter for this. + + .PARAMETER Create + This will create the file, otherwise the filename only will be returned. + + .PARAMETER NoClober + If this is sent, then the file name will not overwrite an existing file, but add a (X) to the end of the file name, where X is a number + + .EXAMPLE + New-TimeStampFile -baseNAME Value -FileType Value -StampFormat Value -FilePath Value + Actually creates the file in the folder specified in the -FilePath 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 -Create -NoClober + This creates a file TestFile-20191026.log if it does not exist + This creates a file TestFile-20191026(1).log if the original does exist + + + .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 -Create + 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 + If the "create" switch is selected, then the file will be created. + #> + + param + ( + [Parameter(Mandatory = $true,HelpMessage = 'Prefix of file or log name')] + [String]$baseNAME, + [Parameter(Mandatory = $true,HelpMessage = 'Extention of file. txt, csv, log')] + [alias('Extension')] + [String]$FileType, + [Parameter(HelpMessage = 'Formatting Choice 1 to 4')] + [ValidateRange(1,4)] + [AllowNull()] + [int]$StampFormat, + [Switch]$Create, + [Parameter(ValueFromPipeline = $true,HelpMessage = 'File Path')] + [AllowNull()] + [String]$FilePath, + [Switch]$NoClobber + + ) + + + if (-not $FilePath) + { + $FilePath = Get-Location + } + + 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' + } + } + + if ($StampFormat) + { + $FullFileName = ('{0}-{1}.{2}' -f $baseNAME, $DateStamp, $FileType) + } + else + { + $FullFileName = ('{0}.{1}' -f $baseNAME, $FileType) + } + + If ($Create) + { + if(Test-Path -Path $FullFileName) + { + if ($NoClobber) + { + $i = 0 + + if (-not (Test-Path -Path $FullFileName)) + { + New-Item -Path $FullFileName -ItemType File + } + else + { + $baseNAME = $($FullFileName.Split('.'))[0] + $FileType = $($FullFileName.Split('.'))[1] + + while (Test-Path -Path ('{0}.{1}' -f $baseNAME, $FileType)) + { + $i++ + $baseNAME = $($baseNAME.Split('(')[0]+"($i)") + } + $FullFileName = ('{0}.{1}' -f $baseNAME, $FileType) + $null = New-Item -Path $FullFileName -ItemType File + } + } + else + { + $null = New-Item -Path $FullFileName -ItemType File -Force + } + } + else + { + #Test path + If(-not (Test-Path -Path $FilePath)) + { + $null = New-Item -Path $FilePath -ItemType Directory -Force + } + $null = New-Item -Path ('{0}\{1}' -f $FilePath, $FullFileName) -ItemType File -Force + } + } + else + { + Return $FullFileName + } +} + + +<# +BaseName : mytest-20210603 +Target : {} +LinkType : +Name : mytest-20210603.txt +Length : 0 +DirectoryName : C:\Users\erika\testfile +Directory : C:\Users\erika\testfile +IsReadOnly : False +Exists : True +FullName : C:\Users\erika\testfile\mytest-20210603.txt +Extension : .txt +#> From 04ebfe89e7aae78b7c3643b33ebacd9ed4b1b5c4 Mon Sep 17 00:00:00 2001 From: Erik JA Date: Sat, 24 Jul 2021 23:36:04 -0500 Subject: [PATCH 05/33] Testing module Testing out the different way functions work in a psd1 file. --- ...-FolderRedirection.ps1 => Repair-FolderRedirection.txt} | 0 Scripts/Test-FiberSatellite.ps1 | 2 +- loader.psm1 | 7 ++----- 3 files changed, 3 insertions(+), 6 deletions(-) rename Scripts/{Repair-FolderRedirection.ps1 => Repair-FolderRedirection.txt} (100%) diff --git a/Scripts/Repair-FolderRedirection.ps1 b/Scripts/Repair-FolderRedirection.txt similarity index 100% rename from Scripts/Repair-FolderRedirection.ps1 rename to Scripts/Repair-FolderRedirection.txt diff --git a/Scripts/Test-FiberSatellite.ps1 b/Scripts/Test-FiberSatellite.ps1 index 1fb2664..8dffbcc 100644 --- a/Scripts/Test-FiberSatellite.ps1 +++ b/Scripts/Test-FiberSatellite.ps1 @@ -304,7 +304,7 @@ function Test-FiberSatellite } -Test-FiberSatellite @TestSplat +# Test-FiberSatellite @TestSplat # For Testing: diff --git a/loader.psm1 b/loader.psm1 index cc5c1b8..278269c 100644 --- a/loader.psm1 +++ b/loader.psm1 @@ -8,8 +8,6 @@ # LOADING ALL FUNCTION DEFINITIONS: -. $PSScriptRoot\Scripts\Get-FolderRedirection.ps1 -. $PSScriptRoot\Scripts\Set-FolderRedirection.ps1 . $PSScriptRoot\Scripts\Add-NetworkPrinter.ps1 . $PSScriptRoot\Scripts\Compare-Folders.ps1 . $PSScriptRoot\Scripts\Get-InstalledSoftware.ps1 @@ -20,12 +18,11 @@ . $PSScriptRoot\Scripts\Test-PrinterStatus.ps1 . $PSScriptRoot\Scripts\Test-Replication.ps1 . $PSScriptRoot\Scripts\Add-NetworkPrinter.ps1 -. $PSScriptRoot\Scripts\Compare-Folders.ps1 -. $PSScriptRoot\Scripts\Get-FolderRedirection.ps1 +. $PSScriptRoot\Scripts\Compare-Folders.ps1 . $PSScriptRoot\Scripts\Get-InstalledSoftware.ps1 . $PSScriptRoot\Scripts\Get-SystemUpTime.ps1 . $PSScriptRoot\Scripts\New-TimeStampFileName.ps1 -. $PSScriptRoot\Scripts\Set-FolderRedirection.ps1 +. $PSScriptRoot\Scripts\FolderRedirection.ps1 . $PSScriptRoot\Scripts\Test-AdWorkstationConnections.ps1 . $PSScriptRoot\Scripts\Test-FiberSatellite.ps1 . $PSScriptRoot\Scripts\Test-PrinterStatus.ps1 From 385591378c32b2a053ca4d2e1c492bc154e4f58d Mon Sep 17 00:00:00 2001 From: Erik JA Date: Fri, 30 Jul 2021 09:23:14 -0500 Subject: [PATCH 06/33] Update init.ps1 --- init.ps1 | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) 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 + From 8990b9075fd26916346c26456d44f51710ff68df Mon Sep 17 00:00:00 2001 From: Erik JA Date: Fri, 30 Jul 2021 09:23:21 -0500 Subject: [PATCH 07/33] Create ITPS.OMCS.Tools - Copy.psd1 --- ITPS.OMCS.Tools - Copy.psd1 | 91 +++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 ITPS.OMCS.Tools - Copy.psd1 diff --git a/ITPS.OMCS.Tools - Copy.psd1 b/ITPS.OMCS.Tools - Copy.psd1 new file mode 100644 index 0000000..4bbc89e --- /dev/null +++ b/ITPS.OMCS.Tools - Copy.psd1 @@ -0,0 +1,91 @@ + +# +# Module Manifest for Module 'ITPS.OMCS.Tools.psd1 +# +# This manifest file is a PowerShell hashtable with all technical requirements for this module +# This module was autogenerated by ISESteroids (http://www.isesteroids.com) +# +# Generated: 2021-03-30 +# + +@{ + +# Module Loader File +RootModule = 'loader.psm1' + +# Version Number +ModuleVersion = '1.11.1.4' + +# Unique Module ID +GUID = '35352390-cd15-4e29-b27b-ac200adabbda' + +# Module Author +Author = 'Erik' + +# Company +CompanyName = 'Knarr Studio' + +# Copyright +Copyright = '(c) 2019 Knarr Studio. All rights reserved.' + +# Module Description +Description = 'IT PowerShell tools for the Open Minded Common Sense tech' + +# Minimum PowerShell Version Required +PowerShellVersion = '3.0' + +# Name of Required PowerShell Host +#PowerShellHostName = '' + +# Minimum Host Version Required +#PowerShellHostVersion = '' + +# Minimum .NET Framework-Version +#DotNetFrameworkVersion = '' + +# Minimum CLR (Common Language Runtime) Version +#CLRVersion = '' + +# Processor Architecture Required (X86, Amd64, IA64) +#ProcessorArchitecture = '' + +# Required Modules (will load before this module loads) +RequiredModules = @() + +# Required Assemblies +RequiredAssemblies = @() + +# PowerShell Scripts (.ps1) that need to be executed before this module loads +ScriptsToProcess = @() + +# Type files (.ps1xml) that need to be loaded when this module loads +TypesToProcess = @() + +# Format files (.ps1xml) that need to be loaded when this module loads +FormatsToProcess = @() + +# +NestedModules = @('Modules\ConnectionsModule.psm1', 'Modules\FoldersModule.psm1', 'Modules\PrintersModule.psm1', 'Modules\SystemInfoModule.psm1') + +# List of exportable functions +FunctionsToExport = 'Get-SystemUpTime, Get-InstalledSoftware, Test-PrinterStatus, Add-NetworkPrinter, Test-SQLConnection, Write-Report, Test-AdWorkstationConnections, Test-FiberSatellite, Test-Replication, Compare-Folders, Set-FolderRedirection, Get-FolderRedirection' +#FunctionsToExport = '*' + +# List of exportable cmdlets +CmdletsToExport = '*' + +# List of exportable variables +VariablesToExport = '*' + +# List of exportable aliases +AliasesToExport = '*' + +# List of all modules contained in this module +ModuleList = @('ConnectionsModule.psm1','FoldersModule.psm1','PrintersModule.psm1','SystemInfoModule.psm1','Test-SQLConnection.ps1') +# List of all files contained in this module +FileList = @() + +# Private data that needs to be passed to this module +PrivateData = '' + +} \ No newline at end of file From 55452a4ceedf8b2e8bd0b60450ac778502aa93c8 Mon Sep 17 00:00:00 2001 From: Erik JA Date: Fri, 30 Jul 2021 09:23:24 -0500 Subject: [PATCH 08/33] Update ITPS.OMCS.Tools.psd1 --- ITPS.OMCS.Tools.psd1 | Bin 1907 -> 8984 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/ITPS.OMCS.Tools.psd1 b/ITPS.OMCS.Tools.psd1 index 3e38d97c804c35b55f4fb53c47b9fb68f9945ed7..6f60b6ca4722a7327808a101b2b45f1882bdb406 100644 GIT binary patch literal 8984 zcmeI1+fN%u6vpSdQvU}_JeX94gj}0Sm11#8P}3yEko2K1;0tjJwriV^sLH?I_WRB8 z$?SM{!O)=gA+liY-I+7r`Oam|nf?2(mGE`=Dy)P?_$iD+H=Ko&(9^Hea2SSR5c>Kx z4Kv;8>-i);DUNG~-LM~Cg?3mEFC}9$e%sgBkt9t+b1vUkc`A8B{Y@l)rfXLckHUxW zy{_B3I|#ooF=Hed%y<-Thr8i%{C`K^HVSiD@k#hI-tpDjp%d2_M~zN1jZM2FAs7nV zM3`WqsB2%(jGaSiHr2C^?j$|V^=lU1Y99Xw8d2tPJ>uEZ+>u7*od2NlP4W1vRvAfd zH}bR|#*%a@-Hc1u<#l{I)jF`z(BGLx9mTs1-Rm#lNSYXi;@XR{49SMDZ0N)Pb#a}q z-`09#ec;V4i63kWH#``w>D(d>dB#Zi#*wdqaKdEO_(ov$Ct)?*%51kAwsikYT$tC) zB#+;C=^wiGBoUhpB5%WppdarPt&v!O$EV>y{)=4G_(6CWzSCzzG9HP+HA&qF_rpDX zyB{8eJMrFQJ=@TeHH~_xPfvf{`JBhP_7|9H2^|>B!!EK6nDWtv%OfMVKw@+l^)&hK zgl8x`%dM8ncp>YYYQFRFqa+av#C=;joJlTrE#nvq0nvLbJ;@g242ulpVU3hQ>g@rV zMM=iMs$%VyWZabvi1U;!*7dz5+n?x~5DqrB8eyEl3Z+vYm*&|6epYvRn$A9i|b!(cI z+9KD{3C)Q~n8#*hj`i?D`wFqKqbHW5&h>PnYT>FrMZVaV=iB~F1d}1$EAe$=gM9>_ zey7!lcRbZAAo3R@sywry-Gr?3dyLnyMiGf=KV)YfO5z9USI~qL>dyIXSyCoy(Tf^k?(9TSXCZ*9`<7XO-%9aviSY~ac!C`!|5w|1r;9F z#1q*A*$c^<<|FJ0XVG^Ws#ab^K6~L?jr&D4#KZWlB@U?)?q7pF_m47?RxOU|T$1)6 zd>TJsZ>Bn>p5hyIBR)@shOS=Gv71<><=%5F?;UA8ae;Ran)@9{7zn48v=9*LYo4@9^JCAwUI7oiHoUi%%SHZj!{hLmi2>Neu7cpD~ z`(iAWW0Y)%4d~X%5ti+Xamv%YswzIE2f(8A$Z%ux%{%urZ?XTqopr-y&mk+YM>>{8 z4LqKjnVhM*X{z91)FV~#(`;0+$0mQXR^!4?c@->iq8vt~eSYag5!_*in~>jD{28;S z>WGK2)+sVvWGL^;cVe|rWY#l&FT9rr*lt36kO$~0$W4AalCnO$dxb@G+rEScP3HIQ zOo|^(~>kcYAOT*vR)HM`ykB_3?$BMH05xO@mBao7qMd=kh8cf_gl*Ko8p|PrcJQd)lC)0DzPZ$DT;*QvxiS&? z*6T>yoAUQA_zG_gI?By2ymM~zg^9DbF?{X3j= zDV*L|ELpAwhxrE41^W6^vwD=fbD3AcN1aHvvK@)DO|lVLCw2Vg9}E znLA~fdO09?7MUJ@>bfnqc0XaNjvY``%_c6HyBI5s<;_Gt9BTJJku~kClRNOAq9A7! zix(NUoOW3+PhNXD&roneuZ{iey$QeSagf#B(|2WAKS5Z_PHY09R N^%-T3K1SQZ>^~xJuHgUx literal 1907 zcmbtV+invv5PkPojKo6|M3!tD8j6HO)U*)MhN=mOS7$xxTCDBG_I6t#zKjPxiCk{Q*H&c5%E zZ(x78pALoxgM%U6uy;S$HUVdb3$$=bv9L>He4CfIuvf$z3SOmq0q_N_lSae5QY*Bq zG3*Y>K26eLLceJIS|*aajop@KzgN7Zs@uTdns{!GzjR+gSJ!FKk6akktQf)CPZi;VE8L=ERs z3o0ZztSFBQ)DELK8h)vzs?;t;m)y%nHiB(+)?LxF5gns9Yv@dOX+9X|cc9^Km#jN4 zhl@>>JED8Q`|nan(d%S>vV>DhHK>jKHfYV*)c862&G}R4(u0TU$-M=xMDIUM!b266|{<#B^- zdK8 zj2xg2O#AdI_n?vF;|+NNc!OCL$HEg{v6f(I+K9KWEN@GMHFbQ;exr(q55)EtQ0FAv z2O+aS;U1wrHCBpx+xxs_q&JNBj9{S%HClGEsBlV*Jy6Fws<&Qb@N(Vk09N|1Ld z(@x|V(ne5SfPtVX%9HT$3AhWsu=1KdJs`N}TLHROfh8wRM>+1ugW4-%rUBA4)z822 C$9Jg! From 7cfcc46443e97dabc4edce49dbec35209fea9959 Mon Sep 17 00:00:00 2001 From: Erik JA Date: Fri, 30 Jul 2021 09:23:27 -0500 Subject: [PATCH 09/33] Update loader.psm1 --- loader.psm1 | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/loader.psm1 b/loader.psm1 index 278269c..a1986bd 100644 --- a/loader.psm1 +++ b/loader.psm1 @@ -8,23 +8,8 @@ # 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\Test-AdWorkstationConnections.ps1 -. $PSScriptRoot\Scripts\Test-FiberSatellite.ps1 -. $PSScriptRoot\Scripts\Test-PrinterStatus.ps1 -. $PSScriptRoot\Scripts\Test-Replication.ps1 -. $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\FolderRedirection.ps1 -. $PSScriptRoot\Scripts\Test-AdWorkstationConnections.ps1 -. $PSScriptRoot\Scripts\Test-FiberSatellite.ps1 -. $PSScriptRoot\Scripts\Test-PrinterStatus.ps1 -. $PSScriptRoot\Scripts\Test-Replication.ps1 -. $PSScriptRoot\Scripts\Test-SQLConnection.ps1 +#. $PSScriptRoot\Modules\ConnectionsModule.psm1 +#. $PSScriptRoot\Modules\FoldersModule.psm1 +#. $PSScriptRoot\Modules\PrintersModule.psm1 +#. $PSScriptRoot\Modules\SystemInfoModule.psm1 +. $PSScriptRoot\Scripts\Test-SQLConnection.ps1 From 5324f7eb12886e6e2c785155360c1f558842df07 Mon Sep 17 00:00:00 2001 From: Erik JA Date: Fri, 30 Jul 2021 09:23:29 -0500 Subject: [PATCH 10/33] Create ConnectionsModule.psm1 --- Modules/ConnectionsModule.psm1 | 690 +++++++++++++++++++++++++++++++++ 1 file changed, 690 insertions(+) create mode 100644 Modules/ConnectionsModule.psm1 diff --git a/Modules/ConnectionsModule.psm1 b/Modules/ConnectionsModule.psm1 new file mode 100644 index 0000000..70bcfa8 --- /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 $(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) + + } +} + From 8d6540b37e8779fb88fbb125b7cb9b6b5a8de6b5 Mon Sep 17 00:00:00 2001 From: Erik JA Date: Fri, 30 Jul 2021 09:23:32 -0500 Subject: [PATCH 11/33] Create FoldersModule.psm1 --- Modules/FoldersModule.psm1 | 432 +++++++++++++++++++++++++++++++++++++ 1 file changed, 432 insertions(+) create mode 100644 Modules/FoldersModule.psm1 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 From 08c417e209c7b6f4e1e26dc153fe0fc178922fb9 Mon Sep 17 00:00:00 2001 From: Erik JA Date: Fri, 30 Jul 2021 09:23:35 -0500 Subject: [PATCH 12/33] Create PrintersModule.psm1 --- Modules/PrintersModule.psm1 | 254 ++++++++++++++++++++++++++++++++++++ 1 file changed, 254 insertions(+) create mode 100644 Modules/PrintersModule.psm1 diff --git a/Modules/PrintersModule.psm1 b/Modules/PrintersModule.psm1 new file mode 100644 index 0000000..a38fb19 --- /dev/null +++ b/Modules/PrintersModule.psm1 @@ -0,0 +1,254 @@ +# 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 + + ) + + 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 +{ + <# + .SYNOPSIS + Tests the status of the printers on the network. + + .DESCRIPTION + What started as a oneline script to find out which printers are erroring out has turned into this module. It creates two files, one that has a list of all of the printers and one that has a list of the printers that are not in a "Normal" status. It also finds the port IP Address and attempts to "ping" it. It returns those results to the screen. + + .PARAMETER PrintServer + Assigns the print server name to the variable. + + .PARAMETER PingReportFolder + Assigns a location to where the files will be stored. + + .EXAMPLE + Test-PrinterStatus -PrintServer Value -PingReportFolder Value + The simple form of this returns the staus of the printers. + + .LINK + https://knarrstudio.github.io/ITPS.OMCS.Tools/ + The first link is opened by Get-Help -Online Test-PrinterStatus + + .INPUTS + Print server Name + Report location + + .OUTPUTS + Screen and Files + #> + + param + ( + [Parameter(Mandatory ,HelpMessage = 'Add PrintServer name', Position = 0)] + [string]$PrintServer, + + [Parameter(HelpMessage = '\\NetworkShare\Reports\PrinterStatus\report.csv or c:\temp\report.csv',Position = 1)] + [string]$PingReportFolder = '\\NetworkShare\Reports\PrinterStatus'<#, + + [Parameter(Mandatory,HelpMessage = '\\NetworkShare\Reports\PrinterStatus\report.csv or c:\temp\report.csv',Position = 2)] + [string]$PrinterStatusReport + + , + + [Parameter(Mandatory,HelpMessage = '\\NetworkShare\Reports\PrinterStatus\report.csv or c:\temp\report.csv',Position = 2)] + [string]$PrinterListFull + #> + ) + + #$PingReportFolder = $env:HOMEDRIVE\temp + $BadCount = $i = 0 + $DateStampFile = Get-Date -UFormat %Y%m%d-%H%M%S + $DateStampData = Get-Date -Format G + + $PrinterStatusReport = (('{0}\{1}-PrinterReport.csv' -f $PingReportFolder, $DateStampFile)) + $PrinterSiteList = (('{0}\{1}-FullPrinterList.csv' -f $PingReportFolder, $DateStampFile)) + + # For testing that an IP address is in correct format. + $Octet = '(?:0?0?[0-9]|0?[1-9][0-9]|1[0-9]{2}|2[0-5][0-5]|2[0-4][0-9])' + [regex] $IPv4Regex = "^(?:$Octet\.){3}$Octet$" + + $PrinterStatus = [Ordered]@{ + 'DateStamp' = $DateStampData + } + + <# + $PrinterStatus['PrinterName'] = '' + $PrinterStatus['PrinterPort'] = '' + $PrinterStatus['PingResponse'] = '' + $PrinterStatus['DuplexingMode'] = '' + $PrinterStatus['PaperSize'] = '' + $PrinterStatus['Collate'] = '' + $PrinterStatus['Color'] = '' + #> + + if(!(Test-Path -Path $PingReportFolder)) + { +New-Item -Path $PingReportFolder -ItemType Directory +} + + $AllPrinters = Get-Printer -ComputerName $PrintServer | Select-Object -Property * + #$AllPrinters = Get-Printer -Name 'EPSON XP-440 Series' | Select-Object -Property * + #$AllPrinters = Get-Printer | Select-Object -Property * + + # Export AllPrinters to a CSV + $AllPrinters | Export-Csv $PrinterSiteList -NoTypeInformation + + $CountTotalPrinters = $AllPrinters.count + if($CountTotalPrinters -gt 0) + { + foreach($OnePrinter in $AllPrinters) + { + $PrinterStatus['PrinterPort'] = $PortName = $OnePrinter.PortName + $PrinterStatus['PrinterName'] = $PrinterName = $OnePrinter.Name + Write-Verbose -Message ('Printer/Port Name: {0} / {1}' -f $PrinterName, $PortName) + Write-Progress -Activity ('Testing {0}' -f $PrinterName) -PercentComplete ($i / $CountTotalPrinters*100) + $i++ + + # Get Print Configuration + $PrintConfig = Get-PrintConfiguration -ComputerName $PrintServer -PrinterName $PrinterName + $PrinterStatus['DuplexingMode'] = $PrintConfig.DuplexingMode + $PrinterStatus['PaperSize'] = $PrintConfig.PaperSize + $PrinterStatus['Collate'] = $PrintConfig.Collate + $PrinterStatus['Color'] = $PrintConfig.Color + # Write-Verbose ('Printer Config Status: {0}' -f $PrinterStatus) + # Get-PrinterProperty -PrinterName 'EPSON XP-440 Series' + # $PrintConfig = Get-PrintConfiguration -PrinterName 'EPSON XP-440 Series' + + $PrinterStatus['PortIpAddress'] = $PortIpAddress = (Get-PrinterPort -ComputerName $PrintServer -Name $PortName).PrinterHostAddress + Write-Verbose -Message ('Port Name / Port IP Address {0} / {1}' -f $PortName, $PortIpAddress) + if ($PortIpAddress -match $IPv4Regex) + { + $PingPortResult = Test-NetConnection -ComputerName $PortIpAddress -InformationLevel Quiet + Write-Verbose -Message ('Port Address Ping Response: {0}' -f $PingPortResult) + } + else +{ +$PingPortResult = 'IncorrectFormat' +} + + Switch ($PingPortResult) { + $False + { + Write-Host -Object ('The printer {0} failed to respond to a ping! ' -f $PrinterName) -ForegroundColor Red + $BadCount ++ + $PrinterProperties = $OnePrinter + } + $true + { +Write-Host -Object ('The printer {0} responded to a ping! ' -f $PrinterName) -ForegroundColor Green +} + Default + { +$PingPortResult = 'N/A' +} + } + $PrinterStatus['PingPortResult'] = $PingPortResult + + If($PrinterStatusReport -ne $null) + { + # Export the hashtable to the file + $PrinterStatus | + ForEach-Object -Process { +[pscustomobject]$_ +} | + Export-Csv -Path $PrinterStatusReport -NoTypeInformation -Force -Append + } + } +} + + Write-Verbose -Message ('Total Printers found: {0}' -f $CountTotalPrinters) + 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) +} \ No newline at end of file From 25a1b0ae36a0aece63d6d5acf729f93e7a0dbec6 Mon Sep 17 00:00:00 2001 From: Erik JA Date: Fri, 30 Jul 2021 09:23:40 -0500 Subject: [PATCH 13/33] Create SystemInfoModule.psm1 --- Modules/SystemInfoModule.psm1 | 323 ++++++++++++++++++++++++++++++++++ 1 file changed, 323 insertions(+) create mode 100644 Modules/SystemInfoModule.psm1 diff --git a/Modules/SystemInfoModule.psm1 b/Modules/SystemInfoModule.psm1 new file mode 100644 index 0000000..b3675c9 --- /dev/null +++ b/Modules/SystemInfoModule.psm1 @@ -0,0 +1,323 @@ +Function Get-InstalledSoftware +{ + <# + .SYNOPSIS + "Get-InstalledSoftware" collects all the software listed in the Uninstall registry. + + .DESCRIPTION + Add a more complete description of what the function does. + + .PARAMETER SortList + Allows you to sort by Name, Installed Date or Version Number. 'InstallDate' or 'DisplayName' or 'DisplayVersion' + + .PARAMETER SoftwareName + This wil provide the installed date, version, and name of the software in the "value". You can use part of a name or two words, but they must be in quotes. Mozil or "Mozilla Firefox" + + .PARAMETER File + Future Use: Will be used to send to a file instead of the screen. + + .EXAMPLE + Get-InstalledSoftware -SortList DisplayName + + InstallDate DisplayVersion DisplayName + ----------- -------------- ----------- + 20150128 6.1.1600.0 Windows MultiPoint Server Log Collector + 02/06/2007 3.1 Windows Driver Package - Silicon Labs Software (DSI_SiUSBXp_3_1) USB (02/06/2007 3.1) + 07/25/2013 10.30.0.288 Windows Driver Package - Lenovo (WUDFRd) LenovoVhid (07/25/2013 10.30.0.288) + + + .EXAMPLE + Get-InstalledSoftware -SoftwareName 'Mozilla Firefox',Green,vlc + + Installdate DisplayVersion DisplayName + ----------- -------------- ----------- + 69.0 Mozilla Firefox 69.0 (x64 en-US) + 20170112 1.2.9.112 Greenshot 1.2.9.112 + 2.1.5 VLC media player + + .NOTES + Place additional notes here. + + .LINK + https://github.com/KnarrStudio/ITPS.OMCS.Tools + + + .OUTPUTS + To the screen until the File parameter is working + + #> + + [cmdletbinding(DefaultParameterSetName = 'SortList',SupportsPaging = $true)] + Param( + + [Parameter(Mandatory = $true,HelpMessage = 'At least part of the software name to test', Position = 0,ParameterSetName = 'SoftwareName')] + [String[]]$SoftwareName, + [Parameter(ParameterSetName = 'SortList')] + [Parameter(ParameterSetName = 'SoftwareName')] + [ValidateSet('DateInstalled', 'DisplayName','DisplayVersion')] + [String]$SortList = 'DateInstalled' + + ) + + Begin { + $SoftwareOutput = @() + $InstalledSoftware = (Get-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*) + } + + Process { + Try + { + if($SoftwareName -eq $null) + { + $SoftwareOutput = $InstalledSoftware | + #Sort-Object -Descending -Property $SortList | + Select-Object -Property @{ + Name = 'DateInstalled' + Exp = { + $_.InstallDate + } + }, @{ + Name = 'Version' + Exp = { + $_.DisplayVersion + } + }, DisplayName #, UninstallString + } + Else + { + foreach($Item in $SoftwareName) + { + $SoftwareOutput += $InstalledSoftware | + Where-Object -Property DisplayName -Match -Value $SoftwareName| + Select-Object -Property @{ + Name = 'DateInstalled' + Exp = { + $_.InstallDate + } + }, @{ + Name = 'Version' + Exp = { + $_.DisplayVersion + } + }, DisplayName #, UninstallString + } + } + } + Catch + { + # get error record + [Management.Automation.ErrorRecord]$e = $_ + + # retrieve information about runtime error + $info = New-Object -TypeName PSObject -Property @{ + 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 + } + } + + End{ + Switch ($SortList){ + 'DisplayName' + { + $SoftwareOutput | + Sort-Object -Property 'displayname' + } + 'DisplayVersion' + { + $SoftwareOutput | + Sort-Object -Property 'Version' + } + 'UninstallString' + { + + } + 'DateInstalled' + { + $SoftwareOutput | + Sort-Object -Property 'DateInstalled' + } + default + { + $SoftwareOutput | + Sort-Object -Property 'DateInstalled' + } #'InstallDate' + + } + } +} + +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 + } + } +} From 20f4720cb010e6a0a2f1d6b795e5643ad6619dca Mon Sep 17 00:00:00 2001 From: Erik JA Date: Fri, 30 Jul 2021 09:23:43 -0500 Subject: [PATCH 14/33] Delete Add-NetworkPrinter.ps1 --- Scripts/Add-NetworkPrinter.ps1 | 127 --------------------------------- 1 file changed, 127 deletions(-) delete mode 100644 Scripts/Add-NetworkPrinter.ps1 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 From aeb3f9e1c1bab79e4a83b11c354999c8386154b6 Mon Sep 17 00:00:00 2001 From: Erik JA Date: Fri, 30 Jul 2021 09:23:47 -0500 Subject: [PATCH 15/33] Create Add-NetworkPrinter.ps1 --- Scripts/archive-olds/Add-NetworkPrinter.ps1 | 127 ++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 Scripts/archive-olds/Add-NetworkPrinter.ps1 diff --git a/Scripts/archive-olds/Add-NetworkPrinter.ps1 b/Scripts/archive-olds/Add-NetworkPrinter.ps1 new file mode 100644 index 0000000..2ce3202 --- /dev/null +++ b/Scripts/archive-olds/Add-NetworkPrinter.ps1 @@ -0,0 +1,127 @@ +#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 From 7235d4ecc4a8639240ce4ec198bb39e13c1f268c Mon Sep 17 00:00:00 2001 From: Erik JA Date: Fri, 30 Jul 2021 09:24:15 -0500 Subject: [PATCH 16/33] Moved files --- Scripts/Update-ManifestModule.ps1 | 19 +++++++++++++++++++ .../{ => archive-olds}/Compare-Folders.ps1 | 0 .../{ => archive-olds}/FolderRedirection.ps1 | 0 .../Get-FolderRedirection.ps1 | 0 .../Get-InstalledSoftware.ps1 | 0 .../{ => archive-olds}/Get-SystemUpTime.ps1 | 0 .../{ => archive-olds}/New-TimeStampFile.ps1 | 0 .../New-TimeStampFileName.ps1 | 0 .../Repair-FolderRedirection.txt | 0 .../Set-FolderRedirection.ps1 | 0 .../Test-AdWorkstationConnections.ps1 | 0 .../Test-FiberSatellite.ps1 | 0 .../{ => archive-olds}/Test-PrinterStatus.ps1 | 0 .../{ => archive-olds}/Test-Replication.ps1 | 0 14 files changed, 19 insertions(+) create mode 100644 Scripts/Update-ManifestModule.ps1 rename Scripts/{ => archive-olds}/Compare-Folders.ps1 (100%) rename Scripts/{ => archive-olds}/FolderRedirection.ps1 (100%) rename Scripts/{ => archive-olds}/Get-FolderRedirection.ps1 (100%) rename Scripts/{ => archive-olds}/Get-InstalledSoftware.ps1 (100%) rename Scripts/{ => archive-olds}/Get-SystemUpTime.ps1 (100%) rename Scripts/{ => archive-olds}/New-TimeStampFile.ps1 (100%) rename Scripts/{ => archive-olds}/New-TimeStampFileName.ps1 (100%) rename Scripts/{ => archive-olds}/Repair-FolderRedirection.txt (100%) rename Scripts/{ => archive-olds}/Set-FolderRedirection.ps1 (100%) rename Scripts/{ => archive-olds}/Test-AdWorkstationConnections.ps1 (100%) rename Scripts/{ => archive-olds}/Test-FiberSatellite.ps1 (100%) rename Scripts/{ => archive-olds}/Test-PrinterStatus.ps1 (100%) rename Scripts/{ => archive-olds}/Test-Replication.ps1 (100%) diff --git a/Scripts/Update-ManifestModule.ps1 b/Scripts/Update-ManifestModule.ps1 new file mode 100644 index 0000000..a88a9a5 --- /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 = 'D:\GitHub\KnarrStudio\ITPS.OMCS.Tools\ITPS.OMCS.Tools.psd1' +RootModule = '.\loader.psm1' +Guid = "$(New-Guid)" +Author = 'Erik' +CompanyName = 'Knarr Studio' +ModuleVersion = '1.11.1.7' +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 = '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/Scripts/Compare-Folders.ps1 b/Scripts/archive-olds/Compare-Folders.ps1 similarity index 100% rename from Scripts/Compare-Folders.ps1 rename to Scripts/archive-olds/Compare-Folders.ps1 diff --git a/Scripts/FolderRedirection.ps1 b/Scripts/archive-olds/FolderRedirection.ps1 similarity index 100% rename from Scripts/FolderRedirection.ps1 rename to Scripts/archive-olds/FolderRedirection.ps1 diff --git a/Scripts/Get-FolderRedirection.ps1 b/Scripts/archive-olds/Get-FolderRedirection.ps1 similarity index 100% rename from Scripts/Get-FolderRedirection.ps1 rename to Scripts/archive-olds/Get-FolderRedirection.ps1 diff --git a/Scripts/Get-InstalledSoftware.ps1 b/Scripts/archive-olds/Get-InstalledSoftware.ps1 similarity index 100% rename from Scripts/Get-InstalledSoftware.ps1 rename to Scripts/archive-olds/Get-InstalledSoftware.ps1 diff --git a/Scripts/Get-SystemUpTime.ps1 b/Scripts/archive-olds/Get-SystemUpTime.ps1 similarity index 100% rename from Scripts/Get-SystemUpTime.ps1 rename to Scripts/archive-olds/Get-SystemUpTime.ps1 diff --git a/Scripts/New-TimeStampFile.ps1 b/Scripts/archive-olds/New-TimeStampFile.ps1 similarity index 100% rename from Scripts/New-TimeStampFile.ps1 rename to Scripts/archive-olds/New-TimeStampFile.ps1 diff --git a/Scripts/New-TimeStampFileName.ps1 b/Scripts/archive-olds/New-TimeStampFileName.ps1 similarity index 100% rename from Scripts/New-TimeStampFileName.ps1 rename to Scripts/archive-olds/New-TimeStampFileName.ps1 diff --git a/Scripts/Repair-FolderRedirection.txt b/Scripts/archive-olds/Repair-FolderRedirection.txt similarity index 100% rename from Scripts/Repair-FolderRedirection.txt rename to Scripts/archive-olds/Repair-FolderRedirection.txt diff --git a/Scripts/Set-FolderRedirection.ps1 b/Scripts/archive-olds/Set-FolderRedirection.ps1 similarity index 100% rename from Scripts/Set-FolderRedirection.ps1 rename to Scripts/archive-olds/Set-FolderRedirection.ps1 diff --git a/Scripts/Test-AdWorkstationConnections.ps1 b/Scripts/archive-olds/Test-AdWorkstationConnections.ps1 similarity index 100% rename from Scripts/Test-AdWorkstationConnections.ps1 rename to Scripts/archive-olds/Test-AdWorkstationConnections.ps1 diff --git a/Scripts/Test-FiberSatellite.ps1 b/Scripts/archive-olds/Test-FiberSatellite.ps1 similarity index 100% rename from Scripts/Test-FiberSatellite.ps1 rename to Scripts/archive-olds/Test-FiberSatellite.ps1 diff --git a/Scripts/Test-PrinterStatus.ps1 b/Scripts/archive-olds/Test-PrinterStatus.ps1 similarity index 100% rename from Scripts/Test-PrinterStatus.ps1 rename to Scripts/archive-olds/Test-PrinterStatus.ps1 diff --git a/Scripts/Test-Replication.ps1 b/Scripts/archive-olds/Test-Replication.ps1 similarity index 100% rename from Scripts/Test-Replication.ps1 rename to Scripts/archive-olds/Test-Replication.ps1 From f154cd5bd0701b873d85e3cc85361f51e5d8e2a5 Mon Sep 17 00:00:00 2001 From: Erik JA Date: Fri, 30 Jul 2021 23:37:03 -0500 Subject: [PATCH 17/33] Delete ITPS.OMCS.Tools - Copy.psd1 --- ITPS.OMCS.Tools - Copy.psd1 | 91 ------------------------------------- 1 file changed, 91 deletions(-) delete mode 100644 ITPS.OMCS.Tools - Copy.psd1 diff --git a/ITPS.OMCS.Tools - Copy.psd1 b/ITPS.OMCS.Tools - Copy.psd1 deleted file mode 100644 index 4bbc89e..0000000 --- a/ITPS.OMCS.Tools - Copy.psd1 +++ /dev/null @@ -1,91 +0,0 @@ - -# -# Module Manifest for Module 'ITPS.OMCS.Tools.psd1 -# -# This manifest file is a PowerShell hashtable with all technical requirements for this module -# This module was autogenerated by ISESteroids (http://www.isesteroids.com) -# -# Generated: 2021-03-30 -# - -@{ - -# Module Loader File -RootModule = 'loader.psm1' - -# Version Number -ModuleVersion = '1.11.1.4' - -# Unique Module ID -GUID = '35352390-cd15-4e29-b27b-ac200adabbda' - -# Module Author -Author = 'Erik' - -# Company -CompanyName = 'Knarr Studio' - -# Copyright -Copyright = '(c) 2019 Knarr Studio. All rights reserved.' - -# Module Description -Description = 'IT PowerShell tools for the Open Minded Common Sense tech' - -# Minimum PowerShell Version Required -PowerShellVersion = '3.0' - -# Name of Required PowerShell Host -#PowerShellHostName = '' - -# Minimum Host Version Required -#PowerShellHostVersion = '' - -# Minimum .NET Framework-Version -#DotNetFrameworkVersion = '' - -# Minimum CLR (Common Language Runtime) Version -#CLRVersion = '' - -# Processor Architecture Required (X86, Amd64, IA64) -#ProcessorArchitecture = '' - -# Required Modules (will load before this module loads) -RequiredModules = @() - -# Required Assemblies -RequiredAssemblies = @() - -# PowerShell Scripts (.ps1) that need to be executed before this module loads -ScriptsToProcess = @() - -# Type files (.ps1xml) that need to be loaded when this module loads -TypesToProcess = @() - -# Format files (.ps1xml) that need to be loaded when this module loads -FormatsToProcess = @() - -# -NestedModules = @('Modules\ConnectionsModule.psm1', 'Modules\FoldersModule.psm1', 'Modules\PrintersModule.psm1', 'Modules\SystemInfoModule.psm1') - -# List of exportable functions -FunctionsToExport = 'Get-SystemUpTime, Get-InstalledSoftware, Test-PrinterStatus, Add-NetworkPrinter, Test-SQLConnection, Write-Report, Test-AdWorkstationConnections, Test-FiberSatellite, Test-Replication, Compare-Folders, Set-FolderRedirection, Get-FolderRedirection' -#FunctionsToExport = '*' - -# List of exportable cmdlets -CmdletsToExport = '*' - -# List of exportable variables -VariablesToExport = '*' - -# List of exportable aliases -AliasesToExport = '*' - -# List of all modules contained in this module -ModuleList = @('ConnectionsModule.psm1','FoldersModule.psm1','PrintersModule.psm1','SystemInfoModule.psm1','Test-SQLConnection.ps1') -# List of all files contained in this module -FileList = @() - -# Private data that needs to be passed to this module -PrivateData = '' - -} \ No newline at end of file From 959a81be0e6811d8573d9c108b506ac50e925a2e Mon Sep 17 00:00:00 2001 From: Erik JA Date: Sun, 1 Aug 2021 10:26:09 -0500 Subject: [PATCH 18/33] Create Publish-Install.ps1 --- Scripts/Publish-Install.ps1 | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Scripts/Publish-Install.ps1 diff --git a/Scripts/Publish-Install.ps1 b/Scripts/Publish-Install.ps1 new file mode 100644 index 0000000..7196e93 --- /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 + From 9bf4bbedb8a3bf161c843e2ce1f6d7ffa1ed53fd Mon Sep 17 00:00:00 2001 From: Erik JA Date: Sun, 1 Aug 2021 22:50:13 -0500 Subject: [PATCH 19/33] Update ITPS.OMCS.Tools.psd1 --- ITPS.OMCS.Tools.psd1 | Bin 8984 -> 9030 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/ITPS.OMCS.Tools.psd1 b/ITPS.OMCS.Tools.psd1 index 6f60b6ca4722a7327808a101b2b45f1882bdb406..8b258fbac5327fa56661a0d3a433f64b0faa79d6 100644 GIT binary patch delta 212 zcmbQ?cFb+U0agnJeFnpg$72~ejTrP8K-glkF4JT8WQIfr0|r9|V+K>uB~a9aAqmJbWv~G9Qh@9@G5tI4ER3`5c dk(>NS#0f6vC8{*JPt*_0zb9(2*+A?C4*<8}PrwUAdB^)t1MMP&Zmzc`r zNg`pBxkMEvzYtNGJVBIevYDva}>?a5C>G&U!QJ>vlYfP*P$ From 58185ef0b8e1ab7064050a2a877b2a4e0f827534 Mon Sep 17 00:00:00 2001 From: Erik JA Date: Sun, 1 Aug 2021 22:50:18 -0500 Subject: [PATCH 20/33] Update loader.psm1 --- loader.psm1 | 1 + 1 file changed, 1 insertion(+) diff --git a/loader.psm1 b/loader.psm1 index a1986bd..7b9d5c9 100644 --- a/loader.psm1 +++ b/loader.psm1 @@ -13,3 +13,4 @@ #. $PSScriptRoot\Modules\PrintersModule.psm1 #. $PSScriptRoot\Modules\SystemInfoModule.psm1 . $PSScriptRoot\Scripts\Test-SQLConnection.ps1 +. $PSScriptRoot\Scripts\Repair-WindowsUpdate.ps1 From d105b75a73c81576dee7cef441383facb53b8945 Mon Sep 17 00:00:00 2001 From: Erik JA Date: Sun, 1 Aug 2021 22:50:22 -0500 Subject: [PATCH 21/33] Create Repair-WindowsUpdate.ps1 --- Scripts/Repair-WindowsUpdate.ps1 | 119 +++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 Scripts/Repair-WindowsUpdate.ps1 diff --git a/Scripts/Repair-WindowsUpdate.ps1 b/Scripts/Repair-WindowsUpdate.ps1 new file mode 100644 index 0000000..7e1c296 --- /dev/null +++ b/Scripts/Repair-WindowsUpdate.ps1 @@ -0,0 +1,119 @@ +function Repair-WindowsUpdate +{ + <# + .SYNOPSIS + Short Description + .DESCRIPTION + Detailed Description + .EXAMPLE + Repair-WindowsUpdate + explains how to use the command + can be multiple lines + .EXAMPLE + Repair-WindowsUpdate + another example + can have as many examples as you like + #> + #requires -Version 3.0 + <#PSScriptInfo + + .VERSION 1.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 + + #> + + $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 + } + } + Set-ServiceState -services $UpdateServices -Stop + Rename-Files -Files $RenameFiles + Set-ServiceState -services $UpdateServices -Start +} + From 5b9dc8c9470f0c88c58ee820e43773989bcb94fb Mon Sep 17 00:00:00 2001 From: Erik JA Date: Sun, 1 Aug 2021 22:58:37 -0500 Subject: [PATCH 22/33] removed old files --- .../Start-DailyChecks.ps1 | 0 Scripts/archive-olds/Add-NetworkPrinter.ps1 | 127 ------- Scripts/archive-olds/Compare-Folders.ps1 | 142 -------- Scripts/archive-olds/FolderRedirection.ps1 | 315 ----------------- .../archive-olds/Get-FolderRedirection.ps1 | 156 --------- .../archive-olds/Get-InstalledSoftware.ps1 | 190 ----------- Scripts/archive-olds/Get-SystemUpTime.ps1 | 210 ------------ Scripts/archive-olds/New-TimeStampFile.ps1 | 193 ----------- .../archive-olds/New-TimeStampFileName.ps1 | 119 ------- .../archive-olds/Repair-FolderRedirection.txt | 212 ------------ .../archive-olds/Set-FolderRedirection.ps1 | 185 ---------- .../Test-AdWorkstationConnections.ps1 | 166 --------- Scripts/archive-olds/Test-FiberSatellite.ps1 | 317 ------------------ Scripts/archive-olds/Test-PrinterStatus.ps1 | 166 --------- Scripts/archive-olds/Test-Replication.ps1 | 285 ---------------- 15 files changed, 2783 deletions(-) rename Start-DailyChecks.ps1 => Scripts/Start-DailyChecks.ps1 (100%) delete mode 100644 Scripts/archive-olds/Add-NetworkPrinter.ps1 delete mode 100644 Scripts/archive-olds/Compare-Folders.ps1 delete mode 100644 Scripts/archive-olds/FolderRedirection.ps1 delete mode 100644 Scripts/archive-olds/Get-FolderRedirection.ps1 delete mode 100644 Scripts/archive-olds/Get-InstalledSoftware.ps1 delete mode 100644 Scripts/archive-olds/Get-SystemUpTime.ps1 delete mode 100644 Scripts/archive-olds/New-TimeStampFile.ps1 delete mode 100644 Scripts/archive-olds/New-TimeStampFileName.ps1 delete mode 100644 Scripts/archive-olds/Repair-FolderRedirection.txt delete mode 100644 Scripts/archive-olds/Set-FolderRedirection.ps1 delete mode 100644 Scripts/archive-olds/Test-AdWorkstationConnections.ps1 delete mode 100644 Scripts/archive-olds/Test-FiberSatellite.ps1 delete mode 100644 Scripts/archive-olds/Test-PrinterStatus.ps1 delete mode 100644 Scripts/archive-olds/Test-Replication.ps1 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/archive-olds/Add-NetworkPrinter.ps1 b/Scripts/archive-olds/Add-NetworkPrinter.ps1 deleted file mode 100644 index 2ce3202..0000000 --- a/Scripts/archive-olds/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/archive-olds/Compare-Folders.ps1 b/Scripts/archive-olds/Compare-Folders.ps1 deleted file mode 100644 index 1a48712..0000000 --- a/Scripts/archive-olds/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/archive-olds/FolderRedirection.ps1 b/Scripts/archive-olds/FolderRedirection.ps1 deleted file mode 100644 index c9db6b2..0000000 --- a/Scripts/archive-olds/FolderRedirection.ps1 +++ /dev/null @@ -1,315 +0,0 @@ -#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 - } -} - diff --git a/Scripts/archive-olds/Get-FolderRedirection.ps1 b/Scripts/archive-olds/Get-FolderRedirection.ps1 deleted file mode 100644 index 4c017e7..0000000 --- a/Scripts/archive-olds/Get-FolderRedirection.ps1 +++ /dev/null @@ -1,156 +0,0 @@ -function Get-FolderRedirection -{ - <#PSScriptInfo - - .VERSION 1.3 - - .GUID 0786a98d-55c0-46a3-9fcf-ed33512b2ff7 - - .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 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 = 'High')] - [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 - } -} \ No newline at end of file diff --git a/Scripts/archive-olds/Get-InstalledSoftware.ps1 b/Scripts/archive-olds/Get-InstalledSoftware.ps1 deleted file mode 100644 index ea607ee..0000000 --- a/Scripts/archive-olds/Get-InstalledSoftware.ps1 +++ /dev/null @@ -1,190 +0,0 @@ -#requires -Version 3.0 -Function Get-InstalledSoftware -{ - <# - .SYNOPSIS - "Get-InstalledSoftware" collects all the software listed in the Uninstall registry. - - .DESCRIPTION - Add a more complete description of what the function does. - - .PARAMETER SortList - Allows you to sort by Name, Installed Date or Version Number. 'InstallDate' or 'DisplayName' or 'DisplayVersion' - - .PARAMETER SoftwareName - This wil provide the installed date, version, and name of the software in the "value". You can use part of a name or two words, but they must be in quotes. Mozil or "Mozilla Firefox" - - .PARAMETER File - Future Use: Will be used to send to a file instead of the screen. - - .EXAMPLE - Get-InstalledSoftware -SortList DisplayName - - InstallDate DisplayVersion DisplayName - ----------- -------------- ----------- - 20150128 6.1.1600.0 Windows MultiPoint Server Log Collector - 02/06/2007 3.1 Windows Driver Package - Silicon Labs Software (DSI_SiUSBXp_3_1) USB (02/06/2007 3.1) - 07/25/2013 10.30.0.288 Windows Driver Package - Lenovo (WUDFRd) LenovoVhid (07/25/2013 10.30.0.288) - - - .EXAMPLE - Get-InstalledSoftware -SoftwareName 'Mozilla Firefox',Green,vlc - - Installdate DisplayVersion DisplayName - ----------- -------------- ----------- - 69.0 Mozilla Firefox 69.0 (x64 en-US) - 20170112 1.2.9.112 Greenshot 1.2.9.112 - 2.1.5 VLC media player - - .NOTES - Place additional notes here. - - .LINK - https://github.com/KnarrStudio/ITPS.OMCS.Tools - - - .OUTPUTS - To the screen until the File parameter is working - - #> - - [cmdletbinding(DefaultParameterSetName = 'SortList',SupportsPaging = $true)] - Param( - - [Parameter(Mandatory = $true,HelpMessage = 'At least part of the software name to test', Position = 0,ParameterSetName = 'SoftwareName')] - [String[]]$SoftwareName, - [Parameter(ParameterSetName = 'SortList')] - [Parameter(ParameterSetName = 'SoftwareName')] - [ValidateSet('DateInstalled', 'DisplayName','DisplayVersion')] - [String]$SortList = 'DateInstalled' - - ) - - Begin { - $SoftwareOutput = @() - $InstalledSoftware = (Get-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*) - } - - Process { - Try - { - if($SoftwareName -eq $null) - { - $SoftwareOutput = $InstalledSoftware | - #Sort-Object -Descending -Property $SortList | - Select-Object -Property @{ - Name = 'DateInstalled' - Exp = { - $_.InstallDate - } - }, @{ - Name = 'Version' - Exp = { - $_.DisplayVersion - } - }, DisplayName #, UninstallString - } - Else - { - foreach($Item in $SoftwareName) - { - $SoftwareOutput += $InstalledSoftware | - Where-Object -Property DisplayName -Match -Value $SoftwareName| - Select-Object -Property @{ - Name = 'DateInstalled' - Exp = { - $_.InstallDate - } - }, @{ - Name = 'Version' - Exp = { - $_.DisplayVersion - } - }, DisplayName #, UninstallString - } - } - } - Catch - { - # get error record - [Management.Automation.ErrorRecord]$e = $_ - - # retrieve information about runtime error - $info = New-Object -TypeName PSObject -Property @{ - 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 - } - } - - End{ - Switch ($SortList){ - 'DisplayName' - { - $SoftwareOutput | - Sort-Object -Property 'displayname' - } - 'DisplayVersion' - { - $SoftwareOutput | - Sort-Object -Property 'Version' - } - 'UninstallString' - { - - } - 'DateInstalled' - { - $SoftwareOutput | - Sort-Object -Property 'DateInstalled' - } - default - { - $SoftwareOutput | - Sort-Object -Property 'DateInstalled' - } #'InstallDate' - - } - } -} - -# -# 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 diff --git a/Scripts/archive-olds/Get-SystemUpTime.ps1 b/Scripts/archive-olds/Get-SystemUpTime.ps1 deleted file mode 100644 index 2e297bb..0000000 --- a/Scripts/archive-olds/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/archive-olds/New-TimeStampFile.ps1 b/Scripts/archive-olds/New-TimeStampFile.ps1 deleted file mode 100644 index 9ebda54..0000000 --- a/Scripts/archive-olds/New-TimeStampFile.ps1 +++ /dev/null @@ -1,193 +0,0 @@ -#requires -Version 1.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 FilePath - where to put the file, if "create" is added. - To create the file add -FilePath. -Use the create parameter for this. - - .PARAMETER Create - This will create the file, otherwise the filename only will be returned. - - .PARAMETER NoClober - If this is sent, then the file name will not overwrite an existing file, but add a (X) to the end of the file name, where X is a number - - .EXAMPLE - New-TimeStampFile -baseNAME Value -FileType Value -StampFormat Value -FilePath Value - Actually creates the file in the folder specified in the -FilePath 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 -Create -NoClober - This creates a file TestFile-20191026.log if it does not exist - This creates a file TestFile-20191026(1).log if the original does exist - - - .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 -Create - 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 - If the "create" switch is selected, then the file will be created. - #> - - param - ( - [Parameter(Mandatory = $true,HelpMessage = 'Prefix of file or log name')] - [String]$baseNAME, - [Parameter(Mandatory = $true,HelpMessage = 'Extention of file. txt, csv, log')] - [alias('Extension')] - [String]$FileType, - [Parameter(HelpMessage = 'Formatting Choice 1 to 4')] - [ValidateRange(1,4)] - [AllowNull()] - [int]$StampFormat, - [Switch]$Create, - [Parameter(ValueFromPipeline = $true,HelpMessage = 'File Path')] - [AllowNull()] - [String]$FilePath, - [Switch]$NoClobber - - ) - - - if (-not $FilePath) - { - $FilePath = Get-Location - } - - 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' - } - } - - if ($StampFormat) - { - $FullFileName = ('{0}-{1}.{2}' -f $baseNAME, $DateStamp, $FileType) - } - else - { - $FullFileName = ('{0}.{1}' -f $baseNAME, $FileType) - } - - If ($Create) - { - if(Test-Path -Path $FullFileName) - { - if ($NoClobber) - { - $i = 0 - - if (-not (Test-Path -Path $FullFileName)) - { - New-Item -Path $FullFileName -ItemType File - } - else - { - $baseNAME = $($FullFileName.Split('.'))[0] - $FileType = $($FullFileName.Split('.'))[1] - - while (Test-Path -Path ('{0}.{1}' -f $baseNAME, $FileType)) - { - $i++ - $baseNAME = $($baseNAME.Split('(')[0]+"($i)") - } - $FullFileName = ('{0}.{1}' -f $baseNAME, $FileType) - $null = New-Item -Path $FullFileName -ItemType File - } - } - else - { - $null = New-Item -Path $FullFileName -ItemType File -Force - } - } - else - { - #Test path - If(-not (Test-Path -Path $FilePath)) - { - $null = New-Item -Path $FilePath -ItemType Directory -Force - } - $null = New-Item -Path ('{0}\{1}' -f $FilePath, $FullFileName) -ItemType File -Force - } - } - else - { - Return $FullFileName - } -} - - -<# -BaseName : mytest-20210603 -Target : {} -LinkType : -Name : mytest-20210603.txt -Length : 0 -DirectoryName : C:\Users\erika\testfile -Directory : C:\Users\erika\testfile -IsReadOnly : False -Exists : True -FullName : C:\Users\erika\testfile\mytest-20210603.txt -Extension : .txt -#> diff --git a/Scripts/archive-olds/New-TimeStampFileName.ps1 b/Scripts/archive-olds/New-TimeStampFileName.ps1 deleted file mode 100644 index 9e31a53..0000000 --- a/Scripts/archive-olds/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/archive-olds/Repair-FolderRedirection.txt b/Scripts/archive-olds/Repair-FolderRedirection.txt deleted file mode 100644 index 9956248..0000000 --- a/Scripts/archive-olds/Repair-FolderRedirection.txt +++ /dev/null @@ -1,212 +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 -# MIID7QYJKoZIhvcNAQcCoIID3jCCA9oCAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB -# gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR -# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUjmAd7kYOiD3flXoNRiLrKxTD -# Zs2gggINMIICCTCCAXagAwIBAgIQyWSKL3Rtw7JMh5kRI2JlijAJBgUrDgMCHQUA -# MBYxFDASBgNVBAMTC0VyaWtBcm5lc2VuMB4XDTE3MTIyOTA1MDU1NVoXDTM5MTIz -# MTIzNTk1OVowFjEUMBIGA1UEAxMLRXJpa0FybmVzZW4wgZ8wDQYJKoZIhvcNAQEB -# BQADgY0AMIGJAoGBAKYEBA0nxXibNWtrLb8GZ/mDFF6I7tG4am2hs2Z7NHYcJPwY -# CxCw5v9xTbCiiVcPvpBl7Vr4I2eR/ZF5GN88XzJNAeELbJHJdfcCvhgNLK/F4DFp -# kvf2qUb6l/ayLvpBBg6lcFskhKG1vbEz+uNrg4se8pxecJ24Ln3IrxfR2o+BAgMB -# AAGjYDBeMBMGA1UdJQQMMAoGCCsGAQUFBwMDMEcGA1UdAQRAMD6AEMry1NzZravR -# UsYVhyFVVoyhGDAWMRQwEgYDVQQDEwtFcmlrQXJuZXNlboIQyWSKL3Rtw7JMh5kR -# I2JlijAJBgUrDgMCHQUAA4GBAF9beeNarhSMJBRL5idYsFZCvMNeLpr3n9fjauAC -# CDB6C+V3PQOvHXXxUqYmzZpkOPpu38TCZvBuBUchvqKRmhKARANLQt0gKBo8nf4b -# OXpOjdXnLeI2t8SSFRltmhw8TiZEpZR1lCq9123A3LDFN94g7I7DYxY1Kp5FCBds -# fJ/uMYIBSjCCAUYCAQEwKjAWMRQwEgYDVQQDEwtFcmlrQXJuZXNlbgIQyWSKL3Rt -# w7JMh5kRI2JlijAJBgUrDgMCGgUAoHgwGAYKKwYBBAGCNwIBDDEKMAigAoAAoQKA -# ADAZBgkqhkiG9w0BCQMxDAYKKwYBBAGCNwIBBDAcBgorBgEEAYI3AgELMQ4wDAYK -# KwYBBAGCNwIBFTAjBgkqhkiG9w0BCQQxFgQUctcJjKxjdAhy4CGJaV9LBJ0FOC4w -# DQYJKoZIhvcNAQEBBQAEgYCZhwOAn0fhGce6aS0MRuiKRGNtUWlW6yJerLacIQGx -# X/O3EJtWgSQBBXhu2DDPFLOWig0ghcIkBB4srhfUGiNMPZ9ER3Kyi8KpOSM/Lku9 -# yUf5aaPSRxLJR0OTObBMzCgaxshSnOBy2V+JnU8uJf1FeEcivu4c5yjFfnyl/HIO -# 6A== -# SIG # End signature block diff --git a/Scripts/archive-olds/Set-FolderRedirection.ps1 b/Scripts/archive-olds/Set-FolderRedirection.ps1 deleted file mode 100644 index 0ef9de1..0000000 --- a/Scripts/archive-olds/Set-FolderRedirection.ps1 +++ /dev/null @@ -1,185 +0,0 @@ -function Set-FolderRedirection -{ - <#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 - - #> - <# - .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 - Stops 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',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" - - ) - - 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 - { - # 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 - } -} \ No newline at end of file diff --git a/Scripts/archive-olds/Test-AdWorkstationConnections.ps1 b/Scripts/archive-olds/Test-AdWorkstationConnections.ps1 deleted file mode 100644 index e7f930e..0000000 --- a/Scripts/archive-olds/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/archive-olds/Test-FiberSatellite.ps1 b/Scripts/archive-olds/Test-FiberSatellite.ps1 deleted file mode 100644 index 8dffbcc..0000000 --- a/Scripts/archive-olds/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/archive-olds/Test-PrinterStatus.ps1 b/Scripts/archive-olds/Test-PrinterStatus.ps1 deleted file mode 100644 index 2b8626a..0000000 --- a/Scripts/archive-olds/Test-PrinterStatus.ps1 +++ /dev/null @@ -1,166 +0,0 @@ -#requires -Version 3.0 -Modules PrintManagement - -$PrinterSplat = @{ - 'PrintServer' = 'PrinterServerName' - 'PingReportFolder' = '\\FileServerName\Share\Reports' - 'Verbose' = $true -} - -function Test-PrinterStatus -{ - <# - .SYNOPSIS - Tests the status of the printers on the network. - - .DESCRIPTION - What started as a oneline script to find out which printers are erroring out has turned into this module. It creates two files, one that has a list of all of the printers and one that has a list of the printers that are not in a "Normal" status. It also finds the port IP Address and attempts to "ping" it. It returns those results to the screen. - - .PARAMETER PrintServer - Assigns the print server name to the variable. - - .PARAMETER PingReportFolder - Assigns a location to where the files will be stored. - - .EXAMPLE - Test-PrinterStatus -PrintServer Value -PingReportFolder Value - The simple form of this returns the staus of the printers. - - .LINK - https://knarrstudio.github.io/ITPS.OMCS.Tools/ - The first link is opened by Get-Help -Online Test-PrinterStatus - - .INPUTS - Print server Name - Report location - - .OUTPUTS - Screen and Files - #> - - param - ( - [Parameter(Mandatory ,HelpMessage = 'Add PrintServer name', Position = 0)] - [string]$PrintServer, - - [Parameter(HelpMessage = '\\NetworkShare\Reports\PrinterStatus\report.csv or c:\temp\report.csv',Position = 1)] - [string]$PingReportFolder = '\\NetworkShare\Reports\PrinterStatus'<#, - - [Parameter(Mandatory,HelpMessage = '\\NetworkShare\Reports\PrinterStatus\report.csv or c:\temp\report.csv',Position = 2)] - [string]$PrinterStatusReport - - , - - [Parameter(Mandatory,HelpMessage = '\\NetworkShare\Reports\PrinterStatus\report.csv or c:\temp\report.csv',Position = 2)] - [string]$PrinterListFull - #> - ) - - #$PingReportFolder = $env:HOMEDRIVE\temp - $BadCount = $i = 0 - $DateStampFile = Get-Date -UFormat %Y%m%d-%H%M%S - $DateStampData = Get-Date -Format G - - $PrinterStatusReport = (('{0}\{1}-PrinterReport.csv' -f $PingReportFolder, $DateStampFile)) - $PrinterSiteList = (('{0}\{1}-FullPrinterList.csv' -f $PingReportFolder, $DateStampFile)) - - # For testing that an IP address is in correct format. - $Octet = '(?:0?0?[0-9]|0?[1-9][0-9]|1[0-9]{2}|2[0-5][0-5]|2[0-4][0-9])' - [regex] $IPv4Regex = "^(?:$Octet\.){3}$Octet$" - - $PrinterStatus = [Ordered]@{ - 'DateStamp' = $DateStampData - } - - <# - $PrinterStatus['PrinterName'] = '' - $PrinterStatus['PrinterPort'] = '' - $PrinterStatus['PingResponse'] = '' - $PrinterStatus['DuplexingMode'] = '' - $PrinterStatus['PaperSize'] = '' - $PrinterStatus['Collate'] = '' - $PrinterStatus['Color'] = '' - #> - - if(!(Test-Path -Path $PingReportFolder)) - { -New-Item -Path $PingReportFolder -ItemType Directory -} - - $AllPrinters = Get-Printer -ComputerName $PrintServer | Select-Object -Property * - #$AllPrinters = Get-Printer -Name 'EPSON XP-440 Series' | Select-Object -Property * - #$AllPrinters = Get-Printer | Select-Object -Property * - - # Export AllPrinters to a CSV - $AllPrinters | Export-Csv $PrinterSiteList -NoTypeInformation - - $CountTotalPrinters = $AllPrinters.count - if($CountTotalPrinters -gt 0) - { - foreach($OnePrinter in $AllPrinters) - { - $PrinterStatus['PrinterPort'] = $PortName = $OnePrinter.PortName - $PrinterStatus['PrinterName'] = $PrinterName = $OnePrinter.Name - Write-Verbose -Message ('Printer/Port Name: {0} / {1}' -f $PrinterName, $PortName) - Write-Progress -Activity ('Testing {0}' -f $PrinterName) -PercentComplete ($i / $CountTotalPrinters*100) - $i++ - - # Get Print Configuration - $PrintConfig = Get-PrintConfiguration -ComputerName $PrintServer -PrinterName $PrinterName - $PrinterStatus['DuplexingMode'] = $PrintConfig.DuplexingMode - $PrinterStatus['PaperSize'] = $PrintConfig.PaperSize - $PrinterStatus['Collate'] = $PrintConfig.Collate - $PrinterStatus['Color'] = $PrintConfig.Color - # Write-Verbose ('Printer Config Status: {0}' -f $PrinterStatus) - # Get-PrinterProperty -PrinterName 'EPSON XP-440 Series' - # $PrintConfig = Get-PrintConfiguration -PrinterName 'EPSON XP-440 Series' - - $PrinterStatus['PortIpAddress'] = $PortIpAddress = (Get-PrinterPort -ComputerName $PrintServer -Name $PortName).PrinterHostAddress - Write-Verbose -Message ('Port Name / Port IP Address {0} / {1}' -f $PortName, $PortIpAddress) - if ($PortIpAddress -match $IPv4Regex) - { - $PingPortResult = Test-NetConnection -ComputerName $PortIpAddress -InformationLevel Quiet - Write-Verbose -Message ('Port Address Ping Response: {0}' -f $PingPortResult) - } - else -{ -$PingPortResult = 'IncorrectFormat' -} - - Switch ($PingPortResult) { - $False - { - Write-Host -Object ('The printer {0} failed to respond to a ping! ' -f $PrinterName) -ForegroundColor Red - $BadCount ++ - $PrinterProperties = $OnePrinter - } - $true - { -Write-Host -Object ('The printer {0} responded to a ping! ' -f $PrinterName) -ForegroundColor Green -} - Default - { -$PingPortResult = 'N/A' -} - } - $PrinterStatus['PingPortResult'] = $PingPortResult - - If($PrinterStatusReport -ne $null) - { - # Export the hashtable to the file - $PrinterStatus | - ForEach-Object -Process { -[pscustomobject]$_ -} | - Export-Csv -Path $PrinterStatusReport -NoTypeInformation -Force -Append - } - } -} - - Write-Verbose -Message ('Total Printers found: {0}' -f $CountTotalPrinters) - 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 - diff --git a/Scripts/archive-olds/Test-Replication.ps1 b/Scripts/archive-olds/Test-Replication.ps1 deleted file mode 100644 index 705da8f..0000000 --- a/Scripts/archive-olds/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 From 87cfaefbd9f19bf6b6ffdeebcd7ff47e46ebb370 Mon Sep 17 00:00:00 2001 From: Erik JA Date: Mon, 2 Aug 2021 06:59:16 -0500 Subject: [PATCH 23/33] Update README.md --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index ca91ee7..a2e6727 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,22 @@ This is the second go around of some tools. The first was a bunch of scripts, t 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: + +* _Get-SystemUpTime_ +* _Get-InstalledSoftware_ +* _Test-PrinterStatus_ +* _Add-NetworkPrinter_ +* _Test-SQLConnection_ +* _Write-Report_ +* _Test-AdWorkstationConnections_ +* _Test-FiberSatellite_ +* _Test-Replication_ +* _Compare-Folders_ +* _Set-FolderRedirection_ +* _Get-FolderRedirection_ + + + * **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. From 478658700cb61603463d5541c44b7b52a52041ec Mon Sep 17 00:00:00 2001 From: Erik JA Date: Mon, 2 Aug 2021 07:57:13 -0500 Subject: [PATCH 24/33] Update README.md --- README.md | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index a2e6727..4516b1c 100644 --- a/README.md +++ b/README.md @@ -3,11 +3,9 @@ #### (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. -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: +### Current Toolset: * _Get-SystemUpTime_ * _Get-InstalledSoftware_ @@ -17,22 +15,22 @@ The original idea was to create a series of tools that could be used by the desk * _Write-Report_ * _Test-AdWorkstationConnections_ * _Test-FiberSatellite_ -* _Test-Replication_ +* _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. * _Compare-Folders_ * _Set-FolderRedirection_ * _Get-FolderRedirection_ - -* **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. +### 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** - 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 +* **Test-Replication** - Perform a test to ensure Replication is working. You must know at least two of the replication partners. ```PowerShell From 09e2cfea40e8e1bfd1cdcea4f85ccdcad2f0dbf2 Mon Sep 17 00:00:00 2001 From: Erik JA Date: Mon, 2 Aug 2021 13:27:08 -0500 Subject: [PATCH 25/33] Update Publish-Install.ps1 --- Scripts/Publish-Install.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Scripts/Publish-Install.ps1 b/Scripts/Publish-Install.ps1 index 7196e93..a5cf415 100644 --- a/Scripts/Publish-Install.ps1 +++ b/Scripts/Publish-Install.ps1 @@ -29,5 +29,5 @@ $InstallSplat = @{ Publish-Module @PublishSplat -#Install-Module @InstallSplat +Install-Module @InstallSplat From edd9f85da86e6ac4374434fa59f00a63ccad60c6 Mon Sep 17 00:00:00 2001 From: Erik JA Date: Mon, 2 Aug 2021 13:27:17 -0500 Subject: [PATCH 26/33] Update Update-ManifestModule.ps1 --- Scripts/Update-ManifestModule.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Scripts/Update-ManifestModule.ps1 b/Scripts/Update-ManifestModule.ps1 index a88a9a5..961f571 100644 --- a/Scripts/Update-ManifestModule.ps1 +++ b/Scripts/Update-ManifestModule.ps1 @@ -1,16 +1,16 @@ #!/usr/bin/env powershell #requires -Version 2.0 -Modules Microsoft.PowerShell.Utility $SplatSettings = @{ -Path = 'D:\GitHub\KnarrStudio\ITPS.OMCS.Tools\ITPS.OMCS.Tools.psd1' +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.11.1.7' +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 = '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 = '*' +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' } From dd4a721fc0516f1075b599e0a22fd565f053a3d3 Mon Sep 17 00:00:00 2001 From: Erik JA Date: Mon, 2 Aug 2021 14:52:34 -0500 Subject: [PATCH 27/33] Update README.md Added information about the new tools and better write-up on the old ones. --- README.md | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 4516b1c..a2f7a0f 100644 --- a/README.md +++ b/README.md @@ -5,32 +5,28 @@ 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. -### Current Toolset: - -* _Get-SystemUpTime_ -* _Get-InstalledSoftware_ -* _Test-PrinterStatus_ -* _Add-NetworkPrinter_ -* _Test-SQLConnection_ -* _Write-Report_ -* _Test-AdWorkstationConnections_ -* _Test-FiberSatellite_ -* _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. -* _Compare-Folders_ -* _Set-FolderRedirection_ -* _Get-FolderRedirection_ - - ### 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** - 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. +* **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** - 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. +* **Get-FolderRedirection** - Changeds 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. + ```PowerShell From 219737bbb749af4fc056d37a5b5d1d8f37886212 Mon Sep 17 00:00:00 2001 From: Erik JA Date: Mon, 2 Aug 2021 14:56:38 -0500 Subject: [PATCH 28/33] Update ConnectionsModule.psm1 --- Modules/ConnectionsModule.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/ConnectionsModule.psm1 b/Modules/ConnectionsModule.psm1 index 70bcfa8..658aae0 100644 --- a/Modules/ConnectionsModule.psm1 +++ b/Modules/ConnectionsModule.psm1 @@ -413,7 +413,7 @@ function Test-FiberSatellite {0} {2} {3} -'@ -f $(f_$OutputTable.Report), ('-' * 31), ('You can find the full report at: {0}' -f $ReportFile), ('=' * 31)) +'@ -f $($OutputTable.Report), ('-' * 31), ('You can find the full report at: {0}' -f $ReportFile), ('=' * 31)) $LogOutput | Add-Content -Path $ReportFile From 0a5d351119b48e1a29bfd3ceb468daa8ee5886a4 Mon Sep 17 00:00:00 2001 From: Erik JA Date: Mon, 2 Aug 2021 15:31:06 -0500 Subject: [PATCH 29/33] Update README.md --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a2f7a0f..1aa2b08 100644 --- a/README.md +++ b/README.md @@ -24,20 +24,20 @@ This is the ~~second~~ third go around of some tools. The original idea was to ### 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** - 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. -* **Get-FolderRedirection** - Changeds 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. +* **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. ```PowerShell -Test-FiberSatellite -Sites Value -Simple +Import-Module -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. From 9699f77ae67bff957e72084300f0545aef6bccb1 Mon Sep 17 00:00:00 2001 From: Erik JA Date: Mon, 2 Aug 2021 15:32:58 -0500 Subject: [PATCH 30/33] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1aa2b08..28e077d 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ This is the ~~second~~ third go around of some tools. The original idea was to ```PowerShell -Import-Module -Scope Local # When using this as a normal user. +Import-Module -Name ITPS.OMCS.Tools -Scope Local # When using this as a normal user. ``` From c2d390a9f5b9ef8429454a1fb79adacf3bf5a8b7 Mon Sep 17 00:00:00 2001 From: Erik JA Date: Mon, 2 Aug 2021 15:52:29 -0500 Subject: [PATCH 31/33] Update Repair-WindowsUpdate.ps1 --- Scripts/Repair-WindowsUpdate.ps1 | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/Scripts/Repair-WindowsUpdate.ps1 b/Scripts/Repair-WindowsUpdate.ps1 index 7e1c296..eca5d2b 100644 --- a/Scripts/Repair-WindowsUpdate.ps1 +++ b/Scripts/Repair-WindowsUpdate.ps1 @@ -1,19 +1,5 @@ function Repair-WindowsUpdate { - <# - .SYNOPSIS - Short Description - .DESCRIPTION - Detailed Description - .EXAMPLE - Repair-WindowsUpdate - explains how to use the command - can be multiple lines - .EXAMPLE - Repair-WindowsUpdate - another example - can have as many examples as you like - #> #requires -Version 3.0 <#PSScriptInfo From b41f0653e93af0b3716d062dcae33e8a6c6038bc Mon Sep 17 00:00:00 2001 From: Erik JA Date: Mon, 2 Aug 2021 16:06:47 -0500 Subject: [PATCH 32/33] Update Repair-WindowsUpdate.ps1 Added test for admin --- Scripts/Repair-WindowsUpdate.ps1 | 147 +++++++++++++++++-------------- 1 file changed, 82 insertions(+), 65 deletions(-) diff --git a/Scripts/Repair-WindowsUpdate.ps1 b/Scripts/Repair-WindowsUpdate.ps1 index eca5d2b..8e643be 100644 --- a/Scripts/Repair-WindowsUpdate.ps1 +++ b/Scripts/Repair-WindowsUpdate.ps1 @@ -3,103 +3,120 @@ #requires -Version 3.0 <#PSScriptInfo - .VERSION 1.0 + .VERSION 1.0 - .GUID ebdf766e-f61c-49a4-a764-1102ed0ac4dc + .GUID ebdf766e-f61c-49a4-a764-1102ed0ac4dc - .AUTHOR Erik@home + .AUTHOR Erik@home - .COMPANYNAME KnarrStudio + .COMPANYNAME KnarrStudio - .COPYRIGHT 2021 KnarrStudio + .COPYRIGHT 2021 KnarrStudio - .RELEASENOTES - Quick script to automate a manual process + .RELEASENOTES + Quick script to automate a manual process #> <# - .SYNOPSIS - Automates the steps used to repair Windows Updates. + .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 + .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 + 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 + .EXAMPLE + As an admin, run: Repair-WindowsUpdate - .NOTES + .NOTES - .LINK - https://support.microsoft.com/help/4089834?ocid=20SMC10164Windows10 + .LINK + https://support.microsoft.com/help/4089834?ocid=20SMC10164Windows10 #> - - $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) + 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 { - ForEach ($service in $services) + <# + .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) { - try + ForEach ($service in $services) { - Stop-Service -InputObject $service -PassThru + try + { + Stop-Service -InputObject $service -PassThru + } + catch + { + Stop-Service -InputObject $service -Force + } } - catch + } + if ($Start) + { + ForEach ($service in $services) { - Stop-Service -InputObject $service -Force + Start-Service -InputObject $service } } } - if ($Start) + + function Rename-Files { - ForEach ($service in $services) + <# + .SYNOPSIS + Renames files to ".old" + #> + param( + [Parameter(Mandatory,HelpMessage = 'list of files to be renamed with ".old"')][string[]]$Files + ) + ForEach($File in $Files) { - Start-Service -InputObject $service + Rename-Item -Path $File -NewName ('{0}.old' -f $File) -Force } } } - 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) + + PROCESS{ + if ($asAdmin -eq $true) + { + Set-ServiceState -services $UpdateServices -Stop + Rename-Files -Files $RenameFiles + Set-ServiceState -services $UpdateServices -Start + } + else { - Rename-Item -Path $File -NewName ('{0}.old' -f $File) -Force + Write-Host -Object '*** Re-run as an administrator ******' -ForegroundColor Black -BackgroundColor Yellow } } - Set-ServiceState -services $UpdateServices -Stop - Rename-Files -Files $RenameFiles - Set-ServiceState -services $UpdateServices -Start + + END{ + } } From 2517888ffdec37a8441b295696d9d122a89a3e02 Mon Sep 17 00:00:00 2001 From: Erik JA Date: Mon, 2 Aug 2021 16:15:59 -0500 Subject: [PATCH 33/33] Update Repair-WindowsUpdate.ps1 --- Scripts/Repair-WindowsUpdate.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Scripts/Repair-WindowsUpdate.ps1 b/Scripts/Repair-WindowsUpdate.ps1 index 8e643be..844bb57 100644 --- a/Scripts/Repair-WindowsUpdate.ps1 +++ b/Scripts/Repair-WindowsUpdate.ps1 @@ -3,7 +3,7 @@ #requires -Version 3.0 <#PSScriptInfo - .VERSION 1.0 + .VERSION 2.0 .GUID ebdf766e-f61c-49a4-a764-1102ed0ac4dc