Skip to content

Instantly share code, notes, and snippets.

Created August 8, 2017 01:03
  • Star 9 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Compresses all of SYSVOL to a local .zip file.
function New-SYSVOLZip {
Compresses all folders/files in SYSVOL to a .zip file.
Author: Will Schroeder (@harmj0y)
License: BSD 3-Clause
Required Dependencies: None
The domain to clone GPOs from. Defaults to $ENV:USERDNSDOMAIN.
The output file for the zip archive, defaults to "$".
[Parameter(Position = 0)]
[Parameter(Position = 1)]
[Alias('Out', 'OutFile')]
if ($PSBoundParameters['Path']) {
$ZipPath = $PSBoundParameters['Path']
else {
$ZipPath = "$($Domain)"
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"
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