PowerShell – Create Zip and Backup File

email me
 

Code.cpp

 

# MrNetTek
# eddiejackson.net
# 5/16/2021
# free for public use
# free to claim as your own

# Load assembly
Add-Type -assembly "system.io.compression.filesystem"

# Variables
$zipSource = "C:\PowerShell\Files"
$zipPath = "C:\PowerShell"
$zipName = "files.zip"
$zipDestination = "C:\PowerShell\Backup"

# Join archive path
$ArchiveFile = Join-Path -Path $zipPath -ChildPath $zipName

# Compress files
[io.compression.zipfile]::CreateFromDirectory($zipSource, $ArchiveFile)

# Copy to backup
Copy-Item -Path $ArchiveFile -Destination $zipDestination -Force

# Clear session
# Delete temp
If(Test-Path $ArchiveFile) {Remove-Item $ArchiveFile}


 
 
 

Notes


Add-Type

Join-Path

Copy-Item

Test-Path

Remove-Item

io.compression.zipfile


Get Basic Details of a Loaded Assembly

[appdomain]::currentdomain.GetAssemblies() | Where-Object Location -match ‘mscorlib’


Discover The Types/Classes Inside a Given Assembly

([appdomain]::currentdomain.GetAssemblies() | Where-Object Location -Match ‘mscorlib’).gettypes()


To Discover the Members Within a Class

(([appdomain]::currentdomain.GetAssemblies() | Where-Object location -match ‘mscorlib’).gettypes() | Where-Object name -eq ‘string’).getmembers() | Format-Table name, membertype