Ejemplo script powershell

Un ejemplo de script en powershell para pillar una copia de seguridad con "aritmética de fechas" lol.

$dia = [DateTime]::Today.toString('dd')
$mes = [DateTime]::Today.toString('MM')
$ano = [DateTime]::Today.toString('yyyy')
$diaa = [DateTime]::Today.AddDays(-1).toString('dd')
$mesa = [DateTime]::Today.AddDays(-1).toString('MM')
$anoa = [DateTime]::Today.AddDays(-1).toString('yy')

$out = "c:\backup\$ano$mes$dia" + "_ddbb.7z"
$block = "c:\historian\Data\Circular\A$anoa$mesa$diaa" + "_*"

& 'net' use z: \\192.168.1.10\datos password /user:backup 

& 'C:\Program Files\7-Zip\7z.exe' a "$out" c:\backup\*.bak "$block"
& 'xcopy' c:\backup\*.7z \\192.168.1.19\e$\FTP\backup
& 'xcopy' c:\backup\*.7z z:\Historian\
& 'del' c:\backup\*.bak
& 'move' c:\backup\*.7z c:\backup2\

& 'net' use z: /d

exit

Comentarios