Skip to content

Instantly share code, notes, and snippets.

@tuantmb
Forked from HarmJ0y/New-SYSVOLZip.ps1
Created August 12, 2022 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuantmb/3fb34d5bfc9029628d7fff3fabdf42bf to your computer and use it in GitHub Desktop.
Save tuantmb/3fb34d5bfc9029628d7fff3fabdf42bf to your computer and use it in GitHub Desktop.
Compresses all of SYSVOL to a local .zip file.
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