2

I'm learning power shell and I have problem with this code. when I parse it, it all works, but not together. what could be the problem? Thank you for answer.

$hotfix = read-host "Enter hotfixID"

Start-Process firefox.exe (get-hotfix | 
Where-Object -filter {$_.hotfixID -eq $hotfix} | 
Select-Object -ExpandProperty Caption)
1
  • What is it that doesn't work? Commented Aug 15, 2013 at 13:51

2 Answers 2

1

Your script works correctly here. Note that I don't have Firefox installed, but it works fine with iexplore. What issue are you experiencing?

Also, as @Colyn1337 stated, you do not need to use Where-Object; you can simplify this script as follows:

$Hotfix = Read-Host "Enter Hotfix ID"

Start-Process firefox.exe
(
    Get-HotFix -Id "$Hotfix" | 
        Select-Object -ExpandProperty Caption
)

EDIT: As discussed in the below comments, the issue was that the arguments do not work when called via powershell.exe -command scriptname. The solution would be to pass the arguments implicitly via ArgumentList:

$Hotfix = Read-Host "Enter Hotfix ID"

Start-Process firefox.exe -ArgumentList `
(
    Get-HotFix -Id "$Hotfix" | 
        Select-Object -ExpandProperty Caption
)
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you. Script looks nice this short. Find out, that problem isn't in code, but in how I start it. I want executable script like batch file. So I created shortcut "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command "C:\Users\Isis\Desktop\hotfix.ps1" and it won't open adress, only firefox.
Yes, it looks like the argument isn't passed when called this way. I'll edit the fix into my answer for visibility.
Great, glad to hear you got it sorted. Please remember to accept this answer if it solved your problem. (Click the check mark.)
0

To get a specific hotfix, you'd want to try something lik this:

$hotFix = Read-Host "Enter hotfixID"
Get-Hotfix -Id $hotFix

If I understand what you're trying to do, creating a browser process is not necessary.

1 Comment

I want open URL stored in caption property, that's why I start firefox. I found out, that problem is in starting script through shortcut: "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command "C:\Users\Isis\Desktop\hotfix.ps1" adress won't open, but firefox does.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.