Created
August 8, 2017 01:03
-
-
Save HarmJ0y/ccac1fe5c7b7edee4984f85f59df748c to your computer and use it in GitHub Desktop.
Compresses all of SYSVOL to a local .zip file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function New-SYSVOLZip { | |
<# | |
.SYNOPSIS | |
Compresses all folders/files in SYSVOL to a .zip file. | |
Author: Will Schroeder (@harmj0y) | |
License: BSD 3-Clause | |
Required Dependencies: None | |
.PARAMETER Domain | |
The domain to clone GPOs from. Defaults to $ENV:USERDNSDOMAIN. | |
.PARAMETER Path | |
The output file for the zip archive, defaults to "$Domain.sysvol.zip". | |
#> | |
[CmdletBinding()] | |
Param( | |
[Parameter(Position = 0)] | |
[ValidateNotNullOrEmpty()] | |
[String] | |
$Domain = $ENV:USERDNSDOMAIN, | |
[Parameter(Position = 1)] | |
[Alias('Out', 'OutFile')] | |
[ValidateNotNullOrEmpty()] | |
[String] | |
$Path | |
) | |
if ($PSBoundParameters['Path']) { | |
$ZipPath = $PSBoundParameters['Path'] | |
} | |
else { | |
$ZipPath = "$($Domain).sysvol.zip" | |
} | |
if (-not (Test-Path -Path $ZipPath)) { | |
Set-Content -Path $ZipPath -Value ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18)) | |
} | |
else { | |
throw "Output zip path '$ZipPath' already exists" | |
} | |
$ZipFileName = (Resolve-Path -Path $ZipPath).Path | |
Write-Verbose "Outputting to .zip file: $ZipFileName" | |
$SysVolPath = "\\$($ENV:USERDNSDOMAIN)\SYSVOL\" | |
Write-Verbose "Using SysVolPath: $SysVolPath" | |
$SysVolFolder = Get-Item "\\$($ENV:USERDNSDOMAIN)\SYSVOL\" | |
# create the zip file | |
$ZipFile = (New-Object -Com Shell.Application).NameSpace($ZipFileName) | |
# 1024 -> do not display errors | |
$ZipFile.CopyHere($SysVolFolder.FullName, 1024) | |
"$SysVolPath zipped to $ZipFileName" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment