Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,94 +11,65 @@ Function Compress-Folder {
[Parameter(Position = 4)][bool]$ReturnCompressedLocation = $false
)

Function Get-DirectorySize {
param(
[Parameter(Mandatory = $true)][string]$Directory,
[Parameter(Mandatory = $false)][bool]$IsCompressed = $false
)
$itemSize = 0
if ($IsCompressed) {
$itemSize = (Get-Item $Directory).Length
} else {
$childItems = Get-ChildItem $Directory -Recurse | Where-Object { -not($_.Mode.StartsWith("d-")) }
foreach ($item in $childItems) {
$itemSize += $item.Length
}
}
return $itemSize
}

if ($Folder.EndsWith("\")) {
$Folder = $Folder.TrimEnd("\")
}
$Folder = $Folder.TrimEnd("\")
$compressedLocation = [string]::Empty
Write-Verbose "Calling: $($MyInvocation.MyCommand)"
Write-Verbose "Passed - [string]Folder: $Folder | [bool]IncludeDisplayZipping: $IncludeDisplayZipping | [bool]ReturnCompressedLocation: $ReturnCompressedLocation"

$compressedLocation = [string]::Empty
if (Test-Path $Folder) {
if (-not (Test-Path $Folder)) {
Write-Host "Failed to find the folder $Folder"
return $null
}

$successful = ([Appdomain]::CurrentDomain.GetAssemblies() | Where-Object { $_.Location -like "*System.IO.Compression.Filesystem*" }).Count -ge 1
Write-Verbose "Found IO Compression loaded: $successful"

$assemblies = [Appdomain]::CurrentDomain.GetAssemblies()
$successful = $false
foreach ($assembly in $assemblies) {
if ($assembly.Location -like "*System.IO.Compression.Filesystem*") {
$successful = $true
break
}
if ($successful -eq $false) {
# Try to load the IO Compression
try {
Add-Type -AssemblyName System.IO.Compression.Filesystem -ErrorAction Stop
Write-Verbose "Loaded .NET Compression Assembly."
} catch {
Write-Host "Failed to load .NET Compression assembly. Unable to compress up the data."
return $null
}
}

Write-Verbose "Found IO Compression loaded: $successful"
if ($IncludeMonthDay) {
$zipFolderNoEXT = "{0}-{1}" -f $Folder, (Get-Date -Format Md)
} else {
$zipFolderNoEXT = $Folder
}
Write-Verbose "[string]zipFolderNoEXT: $zipFolderNoEXT"
$zipFolder = "{0}.zip" -f $zipFolderNoEXT
[int]$i = 1
while (Test-Path $zipFolder) {
$zipFolder = "{0}-{1}.zip" -f $zipFolderNoEXT, $i
$i++
}
Write-Verbose "Using Zip Folder Path: $zipFolder"

if ($successful -eq $false) {
# Try to load the IO Compression
$loadedIOCompression = $false
try {
Add-Type -AssemblyName System.IO.Compression.Filesystem -ErrorAction Stop
$loadedIOCompression = $true
} catch {
Write-Host "Failed to load .NET Compression assembly. Unable to compress up the data."
}
if ($IncludeDisplayZipping) {
Write-Host "Compressing Folder $Folder"
}
$sizeBytesBefore = 0
Get-ChildItem $Folder -Recurse |
Where-Object { -not ($_.Mode.StartsWith("d-")) } |
ForEach-Object { $sizeBytesBefore += $_.Length }

if ($loadedIOCompression -eq $false) {
Write-Verbose "Unable to compress folder $Folder"
Write-Verbose "Unable to enable IO compression on this system"
return $null
}
}
$timer = [System.Diagnostics.Stopwatch]::StartNew()
[System.IO.Compression.ZipFile]::CreateFromDirectory($Folder, $zipFolder)
$timer.Stop()
$sizeBytesAfter = (Get-Item $zipFolder).Length
Write-Verbose ("Compressing directory size of {0} MB down to the size of {1} MB took {2} seconds." -f ($sizeBytesBefore / 1MB), ($sizeBytesAfter / 1MB), $timer.Elapsed.TotalSeconds)

if ($IncludeMonthDay) {
$zipFolderNoEXT = "{0}-{1}" -f $Folder, (Get-Date -Format Md)
} else {
$zipFolderNoEXT = $Folder
}
Write-Verbose "[string]zipFolderNoEXT: $zipFolderNoEXT"
$zipFolder = "{0}.zip" -f $zipFolderNoEXT
if (Test-Path $zipFolder) {
[int]$i = 1
do {
$zipFolder = "{0}-{1}.zip" -f $zipFolderNoEXT, $i
$i++
}while (Test-Path $zipFolder)
}
Write-Verbose "Using Zip Folder Path: $zipFolder"
if ((Test-Path -Path $zipFolder)) {
Write-Verbose "Compress successful, removing folder."
Remove-Item $Folder -Force -Recurse
}

if ($IncludeDisplayZipping) {
Write-Host "Compressing Folder $Folder"
}
$sizeBytesBefore = Get-DirectorySize -Directory $Folder
$timer = [System.Diagnostics.Stopwatch]::StartNew()
[System.IO.Compression.ZipFile]::CreateFromDirectory($Folder, $zipFolder)
$timer.Stop()
$sizeBytesAfter = Get-DirectorySize -Directory $zipFolder -IsCompressed $true
Write-Verbose ("Compressing directory size of {0} MB down to the size of {1} MB took {2} seconds." -f ($sizeBytesBefore / 1MB), ($sizeBytesAfter / 1MB), $timer.Elapsed.TotalSeconds)
if ((Test-Path -Path $zipFolder)) {
Write-Verbose "Compress successful, removing folder."
Remove-Item $Folder -Force -Recurse
}
if ($ReturnCompressedLocation) {
$compressedLocation = $zipFolder
}
} else {
Write-Host "Failed to find the folder $Folder"
if ($ReturnCompressedLocation) {
$compressedLocation = $zipFolder
}

Write-Verbose "Returning: $compressedLocation"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

. $PSScriptRoot\New-Folder.ps1
. $PSScriptRoot\..\Get-StringDataForNotEnoughFreeSpace.ps1
. $PSScriptRoot\..\Test-FreeSpace.ps1
Function Copy-BulkItems {
param(
[string]$CopyToLocation,
[Array]$ItemsToCopyLocation
)
if (-not(Test-Path $CopyToLocation)) {
New-Folder -NewFolder $CopyToLocation -IncludeDisplayCreate $true
}

New-Item -ItemType Directory -Path $CopyToLocation -Force | Out-Null

if (Test-FreeSpace -FilePaths $ItemsToCopyLocation) {
foreach ($item in $ItemsToCopyLocation) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

. $PSScriptRoot\New-Folder.ps1
. $PSScriptRoot\..\Get-StringDataForNotEnoughFreeSpace.ps1
. $PSScriptRoot\..\Test-FreeSpace.ps1
Function Copy-FullLogFullPathRecurse {
Expand All @@ -11,7 +10,7 @@ Function Copy-FullLogFullPathRecurse {
)
Write-Verbose("Function Enter: Copy-FullLogFullPathRecurse")
Write-Verbose("Passed: [string]LogPath: {0} | [string]CopyToThisLocation: {1}" -f $LogPath, $CopyToThisLocation)
New-Folder -NewFolder $CopyToThisLocation -IncludeDisplayCreate $true
New-Item -ItemType Directory -Path $CopyToThisLocation -Force | Out-Null
if (Test-Path $LogPath) {
$childItems = Get-ChildItem $LogPath -Recurse
$items = @()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Licensed under the MIT License.

. $PSScriptRoot\Copy-BulkItems.ps1
. $PSScriptRoot\New-Folder.ps1
Function Copy-LogmanData {
param(
[Parameter(Mandatory = $true)]$ObjLogman
Expand All @@ -18,7 +17,7 @@ Function Copy-LogmanData {

$strDirectory = $ObjLogman.RootPath
$copyTo = $Script:RootCopyToDirectory + "\" + $folderName
New-Folder -NewFolder $copyTo -IncludeDisplayCreate $true
New-Item -ItemType Directory -Path $copyTo -Force | Out-Null
if (Test-Path $strDirectory) {
$wildExt = "*" + $objLogman.Ext
$filterDate = $objLogman.StartDate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Licensed under the MIT License.

. $PSScriptRoot\Copy-BulkItems.ps1
. $PSScriptRoot\New-Folder.ps1
Function Copy-LogsBasedOnTime {
param(
[Parameter(Mandatory = $false)][string]$LogPath,
Expand All @@ -16,7 +15,7 @@ Function Copy-LogsBasedOnTime {
return
}

New-Folder -NewFolder $CopyToThisLocation -IncludeDisplayCreate $true
New-Item -ItemType Directory -Path $CopyToThisLocation -Force | Out-Null

Function NoFilesInLocation {
param(
Expand Down Expand Up @@ -66,7 +65,7 @@ Function Copy-LogsBasedOnTime {
foreach ($dir in $directories) {
$newLogPath = $dir.FullName
$newCopyToThisLocation = "{0}\{1}" -f $CopyToThisLocation, $dir.Name
New-Folder -NewFolder $newCopyToThisLocation -IncludeDisplayCreate $true
New-Item -ItemType Directory -Path $newCopyToThisLocation -Force | Out-Null
$files = Get-ChildItem $newLogPath | Sort-Object LastWriteTime -Descending | Where-Object { $_.LastWriteTime -ge $copyFromDate -and $_.Mode -notlike "d*" }

if ($null -eq $files) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

. $PSScriptRoot\New-Folder.ps1
. $PSScriptRoot\Save-DataInfoToFile.ps1
. $PSScriptRoot\..\Get-ClusterNodeFileVersions.ps1
#Save out the failover cluster information for the local node, besides the event logs.
Function Save-FailoverClusterInformation {
Write-Verbose("Function Enter: Save-FailoverClusterInformation")
$copyTo = "$Script:RootCopyToDirectory\Cluster_Information"
New-Folder -NewFolder $copyTo -IncludeDisplayCreate $true
New-Item -ItemType Directory -Path $copyTo -Force | Out-Null

try {
Save-DataInfoToFile -DataIn (Get-Cluster -ErrorAction Stop) -SaveToLocation "$copyTo\GetCluster"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

. $PSScriptRoot\New-Folder.ps1
. $PSScriptRoot\Save-DataInfoToFile.ps1
. $PSScriptRoot\..\Add-ServerNameToFileName.ps1
. $PSScriptRoot\..\Test-CommandExists.ps1
Function Save-ServerInfoData {
Write-Verbose("Function Enter: Save-ServerInfoData")
$copyTo = $Script:RootCopyToDirectory + "\General_Server_Info"
New-Folder -NewFolder $copyTo -IncludeDisplayCreate $true
New-Item -ItemType Directory -Path $copyTo -Force | Out-Null

#Get MSInfo from server
msinfo32.exe /nfo (Add-ServerNameToFileName -FilePath ("{0}\msinfo.nfo" -f $copyTo))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Licensed under the MIT License.

. $PSScriptRoot\..\ExchangeServerInfo\Get-VirtualDirectoriesLdap.ps1
. $PSScriptRoot\..\RemoteScriptBlock\IO\New-Folder.ps1
. $PSScriptRoot\..\RemoteScriptBlock\IO\Save-DataInfoToFile.ps1
Function Write-DataOnlyOnceOnMasterServer {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseUsingScopeModifierInNewRunspaces', '', Justification = 'Can not use using for an env variable')]
Expand Down Expand Up @@ -31,7 +30,7 @@ Function Write-DataOnlyOnceOnMasterServer {

if ($SendConnectors) {
$create = $RootCopyToDirectory + "\Connectors"
New-Folder -NewFolder $create -IncludeDisplayCreate $true
New-Item -ItemType Directory -Path $create -Force | Out-Null
$saveLocation = $create + "\Send_Connectors"
Save-DataInfoToFile -dataIn (Get-SendConnector) -SaveToLocation $saveLocation -AddServerName $false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
. $PSScriptRoot\..\RemoteScriptBlock\Get-ExchangeInstallDirectory.ps1
. $PSScriptRoot\..\RemoteScriptBlock\IO\Compress-Folder.ps1
. $PSScriptRoot\..\RemoteScriptBlock\IO\Invoke-CatchBlockActions.ps1
. $PSScriptRoot\..\RemoteScriptBlock\IO\New-Folder.ps1
. $PSScriptRoot\..\RemoteScriptBlock\IO\Save-DataToFile.ps1
#This function job is to write out the Data that is too large to pass into the main script block
#This is for mostly Exchange Related objects.
Expand Down Expand Up @@ -184,7 +183,7 @@ Function Write-LargeDataObjectsOnMachine {
$rootSaveToLocation = $DAGWriteInfo.RootSaveToLocation
$mailboxDatabaseSaveToLocation = "{0}\MailboxDatabase\" -f $rootSaveToLocation
$copyStatusSaveToLocation = "{0}\MailboxDatabaseCopyStatus\" -f $rootSaveToLocation
New-Folder -NewFolders @($mailboxDatabaseSaveToLocation, $copyStatusSaveToLocation)
New-Item -ItemType Directory -Path @($mailboxDatabaseSaveToLocation, $copyStatusSaveToLocation) -Force | Out-Null
Save-DataToFile -DataIn $DAGWriteInfo.DAGInfo -SaveToLocation ("{0}{1}_DatabaseAvailabilityGroup" -f $rootSaveToLocation, $dagName)
Save-DataToFile -DataIn $DAGWriteInfo.DAGNetworkInfo -SaveToLocation ("{0}{1}_DatabaseAvailabilityGroupNetwork" -f $rootSaveToLocation, $dagName)
Save-DataToFile -DataIn $DAGWriteInfo.MailboxDatabaseCopyStatusServer -SaveToLocation ("{0}{1}_MailboxDatabaseCopyStatus" -f $copyStatusSaveToLocation, $serverName)
Expand Down Expand Up @@ -237,7 +236,7 @@ Function Write-LargeDataObjectsOnMachine {
Write-Verbose("Remote Copy Location: $remoteLocation")
$rootTempLocation = "{0}{1}\{2}_Exchange_DAG_Information\" -f $localServerTempLocation, $_.ServerName, $_.DAGInfo.Name
Write-Verbose("Local Root Temp Location: $rootTempLocation")
New-Folder -NewFolders $rootTempLocation
New-Item -ItemType Directory -Path $rootTempLocation -Force | Out-Null
$_ | Add-Member -MemberType NoteProperty -Name RootSaveToLocation -Value $rootTempLocation
Write-DatabaseAvailabilityGroupDataLocal -DAGWriteInfo $_

Expand Down Expand Up @@ -267,7 +266,7 @@ Function Write-LargeDataObjectsOnMachine {
ForEach-Object {
$failed = $false
$reportPath = "{0}\{1}_FailoverMetrics" -f $localServerTempLocation, $_.Name
New-Folder -NewFolders $reportPath
New-Item -ItemType Directory -Path $reportPath -Force | Out-Null

try {
Write-Host "Attempting to run CollectOverMetrics.ps1 against $($_.Name)"
Expand Down Expand Up @@ -381,12 +380,8 @@ Function Write-LargeDataObjectsOnMachine {
Write-Verbose("Creating Script Block")
$getExchangeInstallDirectoryScriptBlock = [scriptblock]::Create($getExchangeInstallDirectoryString)

Write-Verbose("Getting New-Folder string to create Script Block")
$newFolderString = Add-ScriptBlockInjection @scriptBlockInjectParams `
-PrimaryScriptBlock ${Function:New-Folder} `
-CatchActionFunction ${Function:Invoke-CatchBlockActions}
Write-Verbose("Creating script block")
$newFolderScriptBlock = [scriptblock]::Create($newFolderString)
Write-Verbose("New-Item create Script Block")
$newFolderScriptBlock = { param($path) New-Item -ItemType Directory -Path $path -Force | Out-Null }

$serverArgListExchangeInstallDirectory = @()
$serverArgListDirectoriesToCreate = @()
Expand All @@ -402,9 +397,10 @@ Function Write-LargeDataObjectsOnMachine {
ArgumentList = $null
}

# Use , prior to the array to make sure it doesn't unwrap
$serverArgListDirectoriesToCreate += [PSCustomObject]@{
ServerName = $serverName
ArgumentList = @(@("$Script:RootFilePath$serverName\Exchange_Server_Data\Config", "$Script:RootFilePath$serverName\Exchange_Server_Data\WebAppPools"), $false)
ArgumentList = (, @("$Script:RootFilePath$serverName\Exchange_Server_Data\Config", "$Script:RootFilePath$serverName\Exchange_Server_Data\WebAppPools"))
}
}

Expand Down Expand Up @@ -438,7 +434,7 @@ Function Write-LargeDataObjectsOnMachine {
$rootTempLocation = "{0}{1}" -f $localServerTempLocation, $serverName
Write-Verbose("Local Root Temp Location: {0}" -f $rootTempLocation)
#Create the temp location and write out the data
New-Folder -NewFolders $rootTempLocation
New-Item -ItemType Directory -Path $rootTempLocation -Force | Out-Null
Write-ExchangeObjectDataLocal -ServerData $serverData -Location $rootTempLocation
Get-ChildItem $rootTempLocation |
ForEach-Object {
Expand All @@ -465,7 +461,7 @@ Function Write-LargeDataObjectsOnMachine {
}
$location = "{0}{1}\Exchange_Server_Data" -f $Script:RootFilePath, $exchangeServerData.ServerName
[array]$createFolders = @(("{0}\Config" -f $location), ("{0}\WebAppPools" -f $location))
New-Folder -NewFolders $createFolders -IncludeDisplayCreate $true
New-Item -ItemType Directory -Path $createFolders -Force | Out-Null
Write-ExchangeObjectDataLocal -Location $location -ServerData $exchangeServerData

$passInfo = @{
Expand Down