thinker123
thinker123

Reputation: 39

Powershell script runs but throws error "cannot find file specified"

it runs the script up until the if clause (for running url) I cannot include the other url here but the script is

"welcome, want to go to site?"

$goyn=read-host -prompt "enter y or n"

if($goyn -eq 'y'){
start-process -Filepath chrome.exe -ArgumentList www.google.ca
}
else{"continue on your journey of awesomeness"}


Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
Get-WmiObject -Class Win32_OperatingSystem -ComputerName localhost |
Select-Object -Property CSName,@{n="Last Booted";
e={[Management.ManagementDateTimeConverter]::ToDateTime($_.LastBootUpTime)}}

for the start-process it throws the error "cannot find file specified followed by the path for $profile. wanted a quicker way of of getting to my work service page.

Upvotes: 1

Views: 2449

Answers (2)

thinker123
thinker123

Reputation: 39

So figured it out. it did not like start-process not one bit no matter how outrageously obvious I made the path. So I used the start cmdlet instead and put site in single quotes. Code looks like this:

"welcome, want to go to site?"

$goyn=read-host -prompt "enter y or n"

if($goyn -eq 'y'){
start 'www.google.ca'
}
else{"continue on your journey of awesomeness"}


Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
Get-WmiObject -Class Win32_OperatingSystem -ComputerName localhost |
Select-Object -Property CSName,@{n="Last Booted";
e={[Management.ManagementDateTimeConverter]::ToDateTime($_.LastBootUpTime)}}

Upvotes: 0

bahrep
bahrep

Reputation: 30662

Specify full path to chrome.exe and other used items. E.g. C:\Program Files (x86)\Google\Application\chrome.exe. Adjust %PATH% otherwise. But I'd better specify full path.

Upvotes: 1

Related Questions