Answered by:
Powershell help for newbie - Check for file existence, If exist exit script, If not continue script.

Question
-
Hi All,
I have been playing about with an install script using bits of line from here and there as I have no formal training in PS. I have ran into a problem I was hoping to get some help with.
I need the script to first check for an ini file, if it is there, exit. If it is not continue.
The application does not have an installer, but relies on the most awkward method of installation, A script is the way forward so I can get this out to our domain users.
What I have so far:
### Check for ini existence, If it exists, exit script (NEED HELP HERE) $IniFile = "c:\Tessitura\Tessitura.ini" ### ini does not exist, copy files Copy-Item -recurse -Path \\server\Tessitura\PBVM\ -Destination C:\PBVM\ -force Copy-Item -recurse -Path \\server\Tessitura\TessituraClient\ -Destination C:\Tessitura\Client\ -force Copy-Item -recurse -Path \\server\Tessitura\StartUp\Tessitura.ini -Destination C:\Tessitura\Tessitura.ini -force Copy-Item -recurse -Path "\\server\Tessitura\StartUp\Tessitura Live.lnk" -Destination "C:\Users\Public\Desktop\Tessitura Live.lnk" -force ### Add to PATH (machine system variable) $oldPath=(Get-ItemProperty -Path ‘Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment’ -Name PATH).Path $newPath=$oldPath+’;C:\PBVM\;C:\Tessitura\Client\Tessitura.ini’ Set-ItemProperty -Path ‘Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment’ -Name PATH –Value $newPath ### Uninstall Paralells Desktop (Start-Process -FilePath "msiexec.exe" -ArgumentList "/X {405D241C-AF65-4FD0-840C-C3ABB361EF98} /QN" -Wait -Passthru).ExitCode Restart-Computer
If anyone can help it would be much appreciated.
Cheers
Andy
- Moved by Bill_Stewart Monday, May 1, 2017 5:10 PM This is not "fix/debug/rewrite my script for me" forum
Thursday, March 30, 2017 8:48 AM
Answers
-
If you are asking how to check for the existence of the INI file then you need to look at
get-help test-path -full
It will give you examples of how to check for a file.
- Marked as answer by Tynecider Monday, April 23, 2018 3:31 PM
Thursday, March 30, 2017 2:24 PM
All replies
-
??????? You need to ask a question.
\_(ツ)_/
Thursday, March 30, 2017 9:02 AM -
The question is: Could somebody help me getting this script to work.Thursday, March 30, 2017 1:26 PM
-
Whether entire script is not working or at any point of the script it is throwing error. Question should be crisp and clear. Please tell us what exact issue you are facing
Naveen Basati
Thursday, March 30, 2017 2:05 PM -
If you are asking how to check for the existence of the INI file then you need to look at
get-help test-path -full
It will give you examples of how to check for a file.
- Marked as answer by Tynecider Monday, April 23, 2018 3:31 PM
Thursday, March 30, 2017 2:24 PM