Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

File Verification - If File Exists Continue - If Not Quit

$
0
0

Hello,

I'm having a little issue, below is an abstract from my script...

Enter-PSSession $compname
cd c:\local\NewLocalProfile
$tname = Read-Host "Enter Target Username"
takeown /F c:\users\$tname
New-Item  -ItemType File - Path c:\users\$tname\appdata\local\stampt.txt
robocopy c:\users\$tname c:\local\profilebackup\$tname /E /ZB /COPY:DAT /XJ /TEE /R:1 /W:1

(Get-WmiObject Win32_UserProfile | Where {$_.LocalPath -Match $tname}).Delete()

You can see on Line 5 a .txt file is created, and then a backup is done using ROBOCOPY, on line 7 i would like a statement to check the .txt file created in line 5 exists in the copied location... If it does i want it to continue to the WMI stage, and if not, i want the script to end with a Warning advising it's not completed.

I have had a look around but cannot find any statements online for if existing continue, if not error... has anyone got any ideas?

In the days of DOS i would use 

IF NOT EXIST C:\local\profilebackup\%username%\appdata\local\stamp.txt GOTO :failure
IF EXIST C:\local\profilebackup\%username%\appdata\local\stamp.txt GOTO :Continue

Making reference points in my script, but can't seem to get my head around this in PowerShell.

Help would be much appreciated.

:)

Thanks!


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>