This has got to be a simple question, but I can’t seem to get this right.
I have a script that copies photos from one share to my local machine, and then will upload them to AD and Azure. Often the photos are not named properly so I want to pause the script for a moment to review the names and then continue on if good or once I have manually gone in an edited the broken names. I’ve tried start-sleep, pause, read-host and no matter which one I use the pause happens before the list of the names.
#variables
$source = "\\server\photos"
$dest = "C:\Scripts\Photos\"
$oldphotos = "C:\scripts\Photos\old\"
#copy files from share to dest
Get-Childitem $source | Copy-Item -Destination $dest
#prompt for manual review of files to ensure they are in the proper format
Get-ChildItem $dest *.jpg | select name
Read-Host "Review names and make sure they are correct"
The only way to pause-and-review would be to “break” the script. Start-Sleep just initiates a countdown and then proceeds.
Try adding a Write-Debug, with a message of some kind. When you run the script, that should produce a prompt. You can [S]uspend, review the contents of a variable or what’s on the screen, and run “Exit” to resume.
It’d be better to capture the output of your command into a variable than just letting it dump to the screen. That’ll make it easier to review.
$output = Get-ChildItem -Include '*.jpg' | Select-Object -ExpandProperty Name
# short version with aliases:
$output = Get-ChildItem '*.jpg' | Select -Expand Name