Native Powershell Equivalent to 7-Zip using recurse and include path

#Define Variables 
$DomainController = "DC01"
$DomainName = "MYCORP.COM"
$FileName = "C:\ADBackup\GPOXMLs.zip"

#Check if file exists and delete
if (Test-Path $FileName) {
  Remove-Item $FileName
}

#Assumes 7-Zip is installed
.$Env:ProgramFiles\7-Zip\7z.exe a -r $FileName \\$domainController\sysvol\$domainName\Policies\*.xml

Trying to figure out a way to use Powershell Compress-Archive to add *.xml files to a ZIP file and include the path. 7-Zip does a great job, but I can’t assume it’d be installed on a Domain Controller and am looking for a native Powershell way to to it.

#This does not include the path, just the files
Get-ChildItem -Path \$domainController\sysvol$domainName\Policies\ -Recurse | Compress-Archive -DestinationPath c:\ADBackup\GPOXMLs.zip -force

#This grabs everything and does not filter based on *.xml
Compress-Archive -Path \$domainController\sysvol$domainName\Policies\ -DestinationPath c:\ADBackup\GPOXMLs.zip

Depending on the amount of files and folders you want to compress it might be worth it to copy the folder structure to a temprary folder but only include XML files. Then you can use your second option to compress the temporary folder structure. :wink: