1

I need to get a string from powershell output. I need to get package name
i.e prompt-toolkit and use it in the pipe below

> pip list --outdated
Package        Version Latest Type
-------------- ------- ------ -----
prompt-toolkit 1.0.15  2.0.3  wheel

pip list --outdated | Where-Object { $exclude -notcontains $_ } | ForEach { pip install -U $_.split(" ")[0] }

UPDATE.
The modified working script

    $(
    $exclude = 'virtualenv', 'prompt-toolkit'
    pip list --outdated --format=freeze  | ForEach{ $_.split("=")[0]} | Where-Object { $exclude -notcontains $_ } | ForEach { pip install -U $_ }                                    
    ) *>&1 >> Python_Modules_Updates_Log.txt
2
  • 1
    Consider passing the pip list in json format pip list --outdated --format=json | ConvertFrom-Json Commented Jun 27, 2018 at 13:48
  • @LotPings, thank you. I have looked into the --format options, and have chosen freeze option. That way i need not use the select-object -skip 2 Commented Jun 27, 2018 at 14:06

2 Answers 2

1

simply try

pip list --outdated | select-object -skip 2 | Where-Object { $exclude -notcontains $_ } | ForEach { pip install -U $_.split(" ")[0] }
Sign up to request clarification or add additional context in comments.

1 Comment

The Where can't work properly as $_ still contains all columns. I'd do the split in a calculated property pip list --outdated | select-object -skip 2 -property @{n='Package';e={$_.split(' ')[0]}} | Where-Object Package -notin $exclude
0

To get the Packagenames of the list, you can use the -ExpandProperty feature of Select-Object and pipe it to the install command:

pip list --outdated | Select-Object -ExpandProperty Package | Where-Object { $exclude -notcontains $_ } | ForEach { pip install -U $_}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.