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

start 2 processes in script with if / else command

$
0
0

Hy Everybody,

I am new to powershell scripting and i am facing the following problem,

For a specific application, that uses security dongles, i want to create a script that looks at the hardware id's of 2 types of usb security dongles.

  • one has limited runs
  • second has unlimited runs

For the dongle with unlimited runs i want to change a specific file in a specific folder before it starts the application for the second one i want to do nothing but just starting the application.

i have made the following script.

$devices = Get-WmiObject Win32_PNPEntity
$found = 0
foreach ($device in $devices) {
    if ($device.deviceid -eq 'USB Dongle with limited runs')
    { $found = 1 }
}

if ($found -eq 1)
{start-process "D:\Rename.cmd"} & {"C:\Program Files (x86)\App name\x.exe"}
else
{start-process "C:\Program Files (x86)\App name\x.EXE"}

if i run this it gives me the error:

The term 'else' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:5
+ else <<<<
    + CategoryInfo          : ObjectNotFound: (else:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
 

Can anyone please provide me the correct solution?

Thank you in advance.

Marc


Viewing all articles
Browse latest Browse all 21975

Trending Articles