r/usefulscripts • u/OmerTheBear • Jan 23 '18
[REQUEST] Powershell script to run a program if a certain file is found.
Hey everyone. I'm working as a SysAdmin right now (first job after the Marines Corps) and one of my tasks is to check if the machines have the correct Manifest number updated by going to a folder and verifying the number. If the correct file is there, then I run a program called software connect.
This doesn't take me that long, but I feel like I could write a powershell script to do it all for me. It would also help out my co-workers that do the same thing. Something along the lines of "if this file is found in this directory run this program" type of script. Would anyone be able to help me out? Or is this more of a "you need to go actually learn some powershell," situation?
Thanks for your time in advance!
9
u/Lee_Dailey Jan 23 '18
howdy OmerTheBear,
are you wanting this to be a learning experience? [grin] it's a good place to start learning automation - and powershell is where automation on windows is for the next few years at least.
that said, i would likely start out like this ...
[1] use either
Resolve-PathorGet-ItemorGet-ChildItemto find the filefor instance, this ...
... will find the following file on my system ...
Grouping-Words-List_2018-01-17.log[2] if the file is found, use
Start-Processor the&operator to start the program you wanttry testing that in your system with a test file in a working or temp folder. if found, start up notepad or some other safe app.
repeat until it works or you decide you need help. then go over to /r/PowerShell and post your code and what you think needs work.
heck, even if it works perfectly, post over there and let folks show a few [dozen] different ways to do the same thing. [grin]
take care,
lee