Asked by:
Command line with a pipe symbol

Question
-
I'm trying to run the following command in Powershell
cmd /c net use | find "K:"
It's failing with FIND: Parameter format not correc
I've tried everything like invoke-expression but it doesn't work!
I've also tried where{$_ -match "K"}) but this fails presumably because its coming out of the commandline and is not a string.
What's the best practive for this?
Alter De Ruine
Wednesday, February 6, 2019 2:50 PM
All replies
-
The following worked for me in PowerShell:
cmd /c 'net use | find "K:"'
I enclosed the entire command in single quotes.Richard Mueller - MVP Enterprise Mobility (Identity and Access)
Wednesday, February 6, 2019 3:36 PM -
take a look of select-string instead of find
Chris
Wednesday, February 6, 2019 5:31 PM -
You don't need to run cmd. The find command needs the doublequotes literally passed to it. You can use findstr or select-string or where-object instead.
net use | find '"K:"'
net use | findstr K:
net use | select-string K:
net use | where { $_ -match 'K:' }
get-psdrive | where name -eq K- Edited by JS2010 Wednesday, February 6, 2019 8:05 PM
- Proposed as answer by LeeSeenLiMicrosoft contingent staff Thursday, February 28, 2019 2:48 PM
Wednesday, February 6, 2019 7:44 PM -
Hi,
Was your issue resolved?
If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.
If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.
If no, please reply and tell us the current situation in order to provide further help.
Best Regards,
Lee
Just do it.
Thursday, February 21, 2019 6:41 AM