forked from stcu/SharedScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBackup-File.ps1
More file actions
24 lines (20 loc) · 807 Bytes
/
Copy pathBackup-File.ps1
File metadata and controls
24 lines (20 loc) · 807 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<#
.SYNOPSIS
Create a backup as a sibling to a file, with date and time values in the name.
.INPUTS
System.String, a file path to back up.
.EXAMPLE
Backup-File.ps1 logfile.log
Copies logfile.log to logfile-201612311159.log (on that date & time).
#>
[CmdletBinding()][OutputType([void])] Param(
<#
Specifies a path to the items being removed. Wildcards are permitted.
The parameter name ("-Path") is optional.
#>
[Parameter(Position=0,Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,ValueFromRemainingArguments=$true)]
[string]$Path
)
$name = Split-Path $Path -Leaf
$name = "$([IO.Path]::GetFileNameWithoutExtension($name))-$(Get-Date -Format yyyyMMddHHmmss).$([IO.Path]::GetExtension($name))"
Copy-Item $Path (Join-Path (Split-Path $Path) $name)