Difference between revisions of "Windows Powershell"
Jump to navigation
Jump to search
| Line 2: | Line 2: | ||
<pre> | <pre> | ||
$datecurrent = get-date -Format MM-dd-yyyy | $datecurrent = get-date -Format MM-dd-yyyy | ||
$apath = "C:\Users\ | $apath = "C:\Users\John\Desktop\leaves" | ||
$btest = "C:\Users\john\Desktop\leaves\pdf-sliced" | $btest = "C:\Users\john\Desktop\leaves\pdf-sliced" | ||
$ctest = "C:\Users\john\Desktop\leaves\atest" | $ctest = "C:\Users\john\Desktop\leaves\atest" | ||
#create directory | #create directory | ||
if ( -not (Test-Path "$ctest\$datecurrent" -PathType Container) ){ | |||
New-Item -ItemType directory -Path "$ctest\$datecurrent" | New-Item -ItemType directory -Path "$ctest\$datecurrent" | ||
}else{ | |||
"Directory already exist! Maybe you ran the program twice" | |||
Read-Host -Prompt "Hit Enter to Exit" | |||
break | |||
} | |||
if( Test-Path "$ctest\$datecurrent" -PathType Container ){ | |||
#open folder | #open folder | ||
ii "$ctest\$datecurrent" | ii "$ctest\$datecurrent" | ||
#copy files from source to destination | |||
Copy-Item -Path $btest\* -Destination "$ctest\$datecurrent" -Verbose | |||
}else{ | |||
"There Was an error - Contact Robert" | |||
} | |||
Read-Host -Prompt "Hit Enter to Exit" | |||
</pre> | </pre> | ||
Revision as of 19:14, 1 April 2020
Script that create a folder based on today's date, then copy the contents of one folder to another
$datecurrent = get-date -Format MM-dd-yyyy
$apath = "C:\Users\John\Desktop\leaves"
$btest = "C:\Users\john\Desktop\leaves\pdf-sliced"
$ctest = "C:\Users\john\Desktop\leaves\atest"
#create directory
if ( -not (Test-Path "$ctest\$datecurrent" -PathType Container) ){
New-Item -ItemType directory -Path "$ctest\$datecurrent"
}else{
"Directory already exist! Maybe you ran the program twice"
Read-Host -Prompt "Hit Enter to Exit"
break
}
if( Test-Path "$ctest\$datecurrent" -PathType Container ){
#open folder
ii "$ctest\$datecurrent"
#copy files from source to destination
Copy-Item -Path $btest\* -Destination "$ctest\$datecurrent" -Verbose
}else{
"There Was an error - Contact Robert"
}
Read-Host -Prompt "Hit Enter to Exit"
save with .ps1 extension
CD to a specific directory
set-location 'g:\box\All Flds\web\amazon\test'