Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
0e9a068
Inject Preferences and Script Blocks
dpaulson45 Feb 24, 2022
589be3c
Moved the Logic that injects the script block to its own function
dpaulson45 Mar 8, 2022
cea68f9
Removed dependency on Write-InvokeCommandReturnWriter type functions
dpaulson45 Mar 9, 2022
1923978
Moved Files out of Remote Script Block extern
dpaulson45 Mar 9, 2022
7002e8e
Use $PSScriptRoot when loading the files
dpaulson45 Mar 9, 2022
90a902b
Fixed Bug In Brake Out of Script Block Injection
dpaulson45 Mar 9, 2022
2c0ba4f
Removed Write-VerboseWriter from extern in ExchangeLogCollector
dpaulson45 Mar 9, 2022
0458e94
New Script Debug Methods
dpaulson45 Mar 9, 2022
0813cd8
Moved functions out of extern path
dpaulson45 Mar 9, 2022
102e24d
Addressed the callers of Start-JobManager
dpaulson45 Mar 9, 2022
dca27c9
Switch Logging Functionality to Use LoggerFunctions vs New-LoggerObject
dpaulson45 Mar 10, 2022
dc64032
Removed old methods no longer used
dpaulson45 Mar 10, 2022
1499858
Removed methods no longer used from Exchange Log Collector
dpaulson45 Mar 10, 2022
5181d1e
Write-Host to accept from Pipeline for Object
dpaulson45 Mar 10, 2022
6e4556c
Removed Old ScriptBlock Variables
dpaulson45 Mar 17, 2022
5c9f323
Set Write-Verbose action to call Write-DebugLog
dpaulson45 Mar 22, 2022
2e1bd9b
Create PipelineFunctions for logging reasons
dpaulson45 Mar 22, 2022
14b686f
Fixed issue with injecting functions
dpaulson45 Mar 23, 2022
0a48ecc
Verbose Info to call out what was from pipeline
dpaulson45 Mar 23, 2022
d68cf60
Remote Logging on Invoke-Commands
dpaulson45 Mar 24, 2022
5fdfcdc
Removed old scripts no longer used
dpaulson45 Mar 24, 2022
aeaac86
Moved Get-ExchangeBuildVersionInformation to Shared
dpaulson45 Mar 24, 2022
5ed61ec
Improved Logic in Get-ExchangeBasicServerObject
dpaulson45 Mar 24, 2022
3797b44
Added dependencies in the correct location
dpaulson45 Mar 24, 2022
ab24774
Improved Code Reading in Get-ArgumentList
dpaulson45 Mar 24, 2022
63afb65
Manipulate Message String with Write-Host
dpaulson45 Mar 24, 2022
2136ec6
Manipulate Message String with Write-Verbose
dpaulson45 Mar 24, 2022
2e84e6a
Action to Manipulate String for Native Functions
dpaulson45 Mar 24, 2022
fff90b7
Write-ScriptDebug to Write-Verbose
dpaulson45 Mar 24, 2022
60fe776
Write-ScriptHost to Write-Host
dpaulson45 Mar 24, 2022
dbfabcb
PSUseCorrectCasing fix
dpaulson45 Mar 25, 2022
1c3c166
Removed old debug and host functions
dpaulson45 Mar 25, 2022
8834fdd
Fixed Verbose Calling Remotely
dpaulson45 Mar 25, 2022
0a61436
Moved Add-ScriptBlockInjection out of Shared
dpaulson45 Mar 29, 2022
1167c7d
Removed Add-ScriptBlockInjection dependency
dpaulson45 Mar 29, 2022
5509111
Removed Write-Debug in catch
dpaulson45 Mar 29, 2022
1287a26
Moved dependency location for Add-ScriptBlockInjection
dpaulson45 Mar 29, 2022
8e38695
Added CatchActionFunction to Add-ScriptBlockInjection
dpaulson45 Mar 30, 2022
6e2e7db
Don't manipulate Write-Host Object
dpaulson45 Mar 30, 2022
d1c279d
Include which server remote context came from
dpaulson45 Mar 30, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Databases/VSSTester/VSSTester.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ param(
)

. $PSScriptRoot\..\..\Shared\Confirm-ExchangeShell.ps1
. $PSScriptRoot\..\..\Shared\Write-HostWriter.ps1
. $PSScriptRoot\..\..\Shared\Write-VerboseWriter.ps1
. .\DiskShadow\Invoke-CreateDiskShadowFile.ps1
. .\DiskShadow\Invoke-DiskShadow.ps1
. .\DiskShadow\Invoke-RemoveExposedDrives.ps1
Expand Down
145 changes: 55 additions & 90 deletions Diagnostics/ExchangeLogCollector/ExchangeLogCollector.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -76,111 +76,73 @@ Param (

$BuildVersion = ""

$Script:VerboseEnabled = $false

if ($PSBoundParameters["Verbose"]) { $Script:VerboseEnabled = $true }
if ($PSBoundParameters["Verbose"]) { $Script:ScriptDebug = $true }

if ($PSCmdlet.ParameterSetName -eq "Worth") { $Script:LogAge = New-TimeSpan -Days $DaysWorth -Hours $HoursWorth }

. $PSScriptRoot\..\..\Shared\Confirm-Administrator.ps1
. $PSScriptRoot\..\..\Shared\Confirm-ExchangeShell.ps1
. .\extern\Enter-YesNoLoopAction.ps1
. .\extern\Import-ScriptConfigFile.ps1
. .\extern\Start-JobManager.ps1
. .\ExchangeServerInfo\Get-DAGInformation.ps1
. .\ExchangeServerInfo\Get-ExchangeBasicServerObject.ps1
. .\ExchangeServerInfo\Get-ServerObjects.ps1
. .\ExchangeServerInfo\Get-TransportLoggingInformationPerServer.ps1
. .\ExchangeServerInfo\Get-VirtualDirectoriesLdap.ps1
. .\Write\Get-WritersToAddToScriptBlock.ps1
. .\Write\Write-DataOnlyOnceOnMasterServer.ps1
. .\Write\Write-LargeDataObjectsOnMachine.ps1
. .\Helpers\Get-ArgumentList.ps1
. .\Helpers\Invoke-ServerRootZipAndCopy.ps1
. .\Helpers\Test-DiskSpace.ps1
. .\Helpers\Test-NoSwitchesProvided.ps1
. .\Helpers\Test-PossibleCommonScenarios.ps1
. .\Helpers\Test-RemoteExecutionOfServers.ps1

Function Invoke-RemoteFunctions {
param(
[Parameter(Mandatory = $true)][object]$PassedInfo
)

. .\RemoteScriptBlock\extern\Compress-Folder.ps1
. .\RemoteScriptBlock\extern\Get-ClusterNodeFileVersions.ps1
. .\RemoteScriptBlock\extern\Get-ExchangeInstallDirectory.ps1
. .\RemoteScriptBlock\extern\Get-FreeSpace.ps1
. .\RemoteScriptBlock\extern\New-Folder.ps1
. $PSScriptRoot\..\..\Shared\New-LoggerObject.ps1
. .\RemoteScriptBlock\extern\Save-DataToFile.ps1
. $PSScriptRoot\..\..\Shared\Write-HostWriter.ps1
. .\RemoteScriptBlock\extern\Write-InvokeCommandReturnHostWriter.ps1
. .\RemoteScriptBlock\extern\Write-InvokeCommandReturnVerboseWriter.ps1
. .\RemoteScriptBlock\extern\Write-ScriptMethodHostWriter.ps1
. $PSScriptRoot\..\..\Shared\Write-ScriptMethodVerboseWriter.ps1
. $PSScriptRoot\..\..\Shared\Write-VerboseWriter.ps1
. .\RemoteScriptBlock\Add-ServerNameToFileName.ps1
. .\RemoteScriptBlock\Get-ItemsSize.ps1
. .\RemoteScriptBlock\Get-StringDataForNotEnoughFreeSpace.ps1
. .\RemoteScriptBlock\Get-IISLogDirectory.ps1
. .\RemoteScriptBlock\Test-CommandExists.ps1
. .\RemoteScriptBlock\Test-FreeSpace.ps1
. .\RemoteScriptBlock\Invoke-ZipFolder.ps1
. .\RemoteScriptBlock\IO\Copy-BulkItems.ps1
. .\RemoteScriptBlock\IO\Copy-FullLogFullPathRecurse.ps1
. .\RemoteScriptBlock\IO\Copy-LogmanData.ps1
. .\RemoteScriptBlock\IO\Copy-LogsBasedOnTime.ps1
. .\RemoteScriptBlock\IO\Invoke-CatchBlockActions.ps1
. .\RemoteScriptBlock\IO\Save-DataInfoToFile.ps1
. .\RemoteScriptBlock\IO\Save-FailoverClusterInformation.ps1
. .\RemoteScriptBlock\IO\Save-LogmanExmonData.ps1
. .\RemoteScriptBlock\IO\Save-LogmanExperfwizData.ps1
. .\RemoteScriptBlock\IO\Save-ServerInfoData.ps1
. .\RemoteScriptBlock\IO\Save-WindowsEventLogs.ps1
. .\RemoteScriptBlock\IO\Write-DebugLog.ps1
. .\RemoteScriptBlock\IO\Write-ScriptDebug.ps1
. .\RemoteScriptBlock\IO\Write-ScriptHost.ps1
. .\RemoteScriptBlock\Logman\Get-LogmanData.ps1
. .\RemoteScriptBlock\Logman\Get-LogmanExt.ps1
. .\RemoteScriptBlock\Logman\Get-LogmanObject.ps1
. .\RemoteScriptBlock\Logman\Get-LogmanRootPath.ps1
. .\RemoteScriptBlock\Logman\Get-LogmanStartDate.ps1
. .\RemoteScriptBlock\Logman\Get-LogmanStatus.ps1
. .\RemoteScriptBlock\Logman\Start-Logman.ps1
. .\RemoteScriptBlock\Logman\Stop-Logman.ps1
. .\RemoteScriptBlock\Invoke-RemoteMain.ps1
. $PSScriptRoot\..\..\Shared\LoggerFunctions.ps1
. $PSScriptRoot\..\..\Shared\Write-Host.ps1
. $PSScriptRoot\RemoteScriptBlock\Get-ExchangeInstallDirectory.ps1
. $PSScriptRoot\RemoteScriptBlock\Invoke-ZipFolder.ps1
. $PSScriptRoot\RemoteScriptBlock\IO\Invoke-CatchBlockActions.ps1
. $PSScriptRoot\RemoteScriptBlock\IO\Write-Verbose.ps1
. $PSScriptRoot\RemoteScriptBlock\IO\WriteFunctions.ps1
. $PSScriptRoot\RemoteScriptBlock\Invoke-RemoteMain.ps1

try {
$Script:VerboseFunctionCaller = ${Function:Write-ScriptDebug}
$Script:HostFunctionCaller = ${Function:Write-ScriptHost}

if ($PassedInfo.ByPass -ne $true) {
$Script:RootCopyToDirectory = "{0}{1}" -f $PassedInfo.RootFilePath, $env:COMPUTERNAME
$Script:Logger = New-LoggerObject -LogDirectory $Script:RootCopyToDirectory -LogName ("ExchangeLogCollector-Instance-Debug") `
-HostFunctionCaller $Script:HostFunctionCaller `
-VerboseFunctionCaller $Script:VerboseFunctionCaller
Write-ScriptDebug("Root Copy To Directory: $Script:RootCopyToDirectory")
$Script:Logger = Get-NewLoggerInstance -LogName "ExchangeLogCollector-Instance-Debug" -LogDirectory $Script:RootCopyToDirectory
SetWriteHostManipulateObjectAction ${Function:Get-ManipulateWriteHostValue}
SetWriteVerboseManipulateMessageAction ${Function:Get-ManipulateWriteVerboseValue}
SetWriteHostAction ${Function:Write-DebugLog}
SetWriteVerboseAction ${Function:Write-DebugLog}

if ($PassedInfo.ScriptDebug) {
$Script:VerbosePreference = "Continue"
}

Write-Verbose("Root Copy To Directory: $Script:RootCopyToDirectory")
Invoke-RemoteMain
} else {
Write-ScriptDebug("Loading common functions")
Write-Verbose("Loading common functions")
}
} catch {
Write-ScriptHost -WriteString ("An error occurred in Invoke-RemoteFunctions") -ForegroundColor "Red"
Write-Host "An error occurred in Invoke-RemoteFunctions" -ForegroundColor "Red"
Invoke-CatchBlockActions
#This is a bad place to catch the error that just occurred
#Being that there is a try catch block around each command that we run now, we should never hit an issue here unless it is is prior to that.
Write-ScriptDebug "Critical Failure occurred."
Write-Verbose "Critical Failure occurred."
} finally {
Write-ScriptDebug("Exiting: Invoke-RemoteFunctions")
Write-ScriptDebug("[double]TotalBytesSizeCopied: {0} | [double]TotalBytesSizeCompressed: {1} | [double]AdditionalFreeSpaceCushionGB: {2} | [double]CurrentFreeSpaceGB: {3} | [double]FreeSpaceMinusCopiedAndCompressedGB: {4}" -f $Script:TotalBytesSizeCopied,
Write-Verbose("Exiting: Invoke-RemoteFunctions")
Write-Verbose("[double]TotalBytesSizeCopied: {0} | [double]TotalBytesSizeCompressed: {1} | [double]AdditionalFreeSpaceCushionGB: {2} | [double]CurrentFreeSpaceGB: {3} | [double]FreeSpaceMinusCopiedAndCompressedGB: {4}" -f $Script:TotalBytesSizeCopied,
$Script:TotalBytesSizeCompressed,
$Script:AdditionalFreeSpaceCushionGB,
$Script:CurrentFreeSpaceGB,
$Script:FreeSpaceMinusCopiedAndCompressedGB)
}
}

# Need to dot load the files outside of the remote functions after them to avoid issues with encapsulation
. $PSScriptRoot\..\..\Shared\Confirm-Administrator.ps1
. $PSScriptRoot\..\..\Shared\Confirm-ExchangeShell.ps1
. $PSScriptRoot\Write\Write-DataOnlyOnceOnMasterServer.ps1
. $PSScriptRoot\Write\Write-LargeDataObjectsOnMachine.ps1
. $PSScriptRoot\Helpers\Enter-YesNoLoopAction.ps1
. $PSScriptRoot\Helpers\Get-ArgumentList.ps1
. $PSScriptRoot\Helpers\Import-ScriptConfigFile.ps1
. $PSScriptRoot\Helpers\Invoke-ServerRootZipAndCopy.ps1
. $PSScriptRoot\Helpers\Test-DiskSpace.ps1
. $PSScriptRoot\Helpers\Test-NoSwitchesProvided.ps1
. $PSScriptRoot\Helpers\Test-PossibleCommonScenarios.ps1
. $PSScriptRoot\Helpers\Test-RemoteExecutionOfServers.ps1

Function Main {

Start-Sleep 1
Expand Down Expand Up @@ -209,21 +171,21 @@ Function Main {
"@ -f $BuildVersion, ($Script:StandardFreeSpaceInGBCheckSize = 10), $Script:StandardFreeSpaceInGBCheckSize

Clear-Host
Write-ScriptHost -WriteString $display -ShowServer $false
Write-Host $display

if (-not($AcceptEULA)) {
Enter-YesNoLoopAction -Question "Do you wish to continue? " -YesAction {} -NoAction { exit }
}

if (-not (Confirm-Administrator)) {
Write-ScriptHost -WriteString ("Hey! The script needs to be executed in elevated mode. Start the Exchange Management Shell as an Administrator.") -ForegroundColor "Yellow"
Write-Host "Hey! The script needs to be executed in elevated mode. Start the Exchange Management Shell as an Administrator." -ForegroundColor "Yellow"
exit
}

$Script:LocalExchangeShell = Confirm-ExchangeShell -Identity $env:COMPUTERNAME

if (!($Script:LocalExchangeShell.ShellLoaded)) {
Write-ScriptHost -WriteString ("It appears that you are not on an Exchange 2010 or newer server. Sorry I am going to quit.") -ShowServer $false
Write-Host "It appears that you are not on an Exchange 2010 or newer server. Sorry I am going to quit."
exit
}

Expand All @@ -234,7 +196,7 @@ Function Main {
if ($Script:LocalExchangeShell.EdgeServer) {
#If we are on an Exchange Edge Server, we are going to treat it like a single server on purpose as we recommend that the Edge Server is a non domain joined computer.
#Because it isn't a domain joined computer, we can't use remote execution
Write-ScriptHost -WriteString ("Determined that we are on an Edge Server, we can only use locally collection for this role.") -ForegroundColor "Yellow"
Write-Host "Determined that we are on an Edge Server, we can only use locally collection for this role." -ForegroundColor "Yellow"
$Script:EdgeRoleDetected = $true
$Servers = @($env:COMPUTERNAME)
}
Expand Down Expand Up @@ -268,21 +230,24 @@ Function Main {
} else {

if ($null -eq (Test-DiskSpace -Servers $env:COMPUTERNAME -Path $FilePath -CheckSize $Script:StandardFreeSpaceInGBCheckSize)) {
Write-ScriptHost -ShowServer $false -WriteString ("Failed to have enough space available locally. We can't continue with the data collection") -ForegroundColor "Yellow"
Write-Host "Failed to have enough space available locally. We can't continue with the data collection" -ForegroundColor "Yellow"
exit
}
if (-not($Script:EdgeRoleDetected)) {
Write-ScriptHost -ShowServer $false -WriteString ("Note: Remote Collection is now possible for Windows Server 2012 and greater on the remote machine. Just use the -Servers paramater with a list of Exchange Server names") -ForegroundColor "Yellow"
Write-ScriptHost -ShowServer $false -WriteString ("Going to collect the data locally")
Write-Host "Note: Remote Collection is now possible for Windows Server 2012 and greater on the remote machine. Just use the -Servers parameter with a list of Exchange Server names" -ForegroundColor "Yellow"
Write-Host "Going to collect the data locally"
}
$Script:ArgumentList = (Get-ArgumentList -Servers $env:COMPUTERNAME)
Invoke-RemoteFunctions -PassedInfo $Script:ArgumentList
# Don't manipulate the host object when running locally after the Invoke-RemoteFunctions to
# make it the same as when having multiple servers executing the script against.
SetWriteHostManipulateObjectAction $null
Write-DataOnlyOnceOnMasterServer
Write-LargeDataObjectsOnMachine
Invoke-ServerRootZipAndCopy -RemoteExecute $false
}

Write-ScriptHost -WriteString "`r`n`r`n`r`nLooks like the script is done. If you ran into any issues or have additional feedback, please feel free to reach out ExToolsFeedback@microsoft.com." -ShowServer $false
Write-Host "`r`n`r`n`r`nLooks like the script is done. If you ran into any issues or have additional feedback, please feel free to reach out ExToolsFeedback@microsoft.com."
}
#Need to do this here otherwise can't find the script path
$configPath = "{0}\{1}.json" -f (Split-Path -Parent $MyInvocation.MyCommand.Path), (Split-Path -Leaf $MyInvocation.MyCommand.Path)
Expand All @@ -303,21 +268,21 @@ try {
try {
Import-ScriptConfigFile -ScriptConfigFileLocation $configPath
} catch {
Write-ScriptHost "Failed to load the config file at $configPath. `r`nPlease update the config file to be able to run 'ConvertFrom-Json' against it" -ForegroundColor "Red"
Write-Host "Failed to load the config file at $configPath. `r`nPlease update the config file to be able to run 'ConvertFrom-Json' against it" -ForegroundColor "Red"
Invoke-CatchBlockActions
Enter-YesNoLoopAction -Question "Do you wish to continue?" -YesAction {} -NoAction { exit }
}
}
$Script:RootFilePath = "{0}\{1}\" -f $FilePath, (Get-Date -Format yyyyMd)
$Script:Logger = New-LoggerObject -LogDirectory ("{0}{1}" -f $RootFilePath, $env:COMPUTERNAME) -LogName "ExchangeLogCollector-Main-Debug" `
-HostFunctionCaller $Script:HostFunctionCaller `
-VerboseFunctionCaller $Script:VerboseFunctionCaller
$Script:Logger = Get-NewLoggerInstance -LogName "ExchangeLogCollector-Main-Debug" -LogDirectory ("$RootFilePath$env:COMPUTERNAME")
SetWriteVerboseAction ${Function:Write-DebugLog}
SetWriteHostAction ${Function:Write-DebugLog}

Main
} finally {

if ($Script:VerboseEnabled -or
($Error.Count -ne $Script:ErrorsFromStartOfCopy)) {
$Script:Logger.RemoveLatestLogFile()
#$Script:Logger.RemoveLatestLogFile()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ Function Get-DAGInformation {
try {
$dag = Get-DatabaseAvailabilityGroup $DAGName -Status -ErrorAction Stop
} catch {
Write-ScriptDebug("Failed to run Get-DatabaseAvailabilityGroup on $DAGName")
Write-Verbose("Failed to run Get-DatabaseAvailabilityGroup on $DAGName")
Invoke-CatchBlockActions
}

try {
$dagNetwork = Get-DatabaseAvailabilityGroupNetwork $DAGName -ErrorAction Stop
} catch {
Write-ScriptDebug("Failed to run Get-DatabaseAvailabilityGroupNetwork on $DAGName")
Write-Verbose("Failed to run Get-DatabaseAvailabilityGroupNetwork on $DAGName")
Invoke-CatchBlockActions
}

Expand Down
Loading