1
param([String]$fileName)
$Target = "C:\Users\pb\Desktop\destination"

if (Test-Path $fileName)
{
Copy-Item $fileName $Target
} Else
{
"File does not exist"
}
EBGreen
  • 36,735
  • 12
  • 65
  • 85
Philab
  • 13
  • 1
  • 1
  • 6
  • You need to put a little more effort into your question. I'm pretty sure that I know what you are asking but to be honest with you your lack of effort sucks all the desire to answer right out of me. Where in the name do you want the date? A simple google search would have answered this including the duplicate question. – EBGreen Jun 02 '15 at 16:15
  • I had been google searching and then I was having trouble figuring out how the cases applied to mine. I've never used Powershell until now so my understanding of the syntax is limited even though I understand that it is supposed to be very simple. I figured it out – Philab Jun 02 '15 at 19:13

1 Answers1

3

You could do something like this:

param([String]$fileName)

if (Test-Path $fileName)
{
  $file   = [io.path]::GetFileNameWithoutExtension($fileName)
  $ext    = [io.path]::GetExtension($fileName)
  $Target = "C:\Users\pb\Desktop\destination" + $file + $(get-date -f yyyy-MM-dd) + $ext
  Move-Item $fileName $Target
} 
Else {
  Write-Host "File does not exist!"
}
S.Spieker
  • 7,005
  • 8
  • 44
  • 50