Bill Prew
asked on
Powershell: Extra blank lines in pipeline to CLIP command?
I'm trying to get a file path and place it into the clipboard using Powershell. Below is what I have, and while it likely could be optimized, it seems to be finding a single file path as I desire. But the output that ends up in the clipboard includes some extra blank lines above and below the actual file path I want. I've tried a number of ways to try and remove these with no success, so looking for help.
For background I'm trying to query the Windows recently used files and pull out the single most recent one that was for a *.pdf or *.png file. That logic seems to be working (feel free to suggest improvements), but the problem is the result file path has blank lines above and below in the clipboard after this runs.
I may be mixing up objects and strings (still rooted in a DOS CMD background) or maybe there is something else involved.
»bp
For background I'm trying to query the Windows recently used files and pull out the single most recent one that was for a *.pdf or *.png file. That logic seems to be working (feel free to suggest improvements), but the problem is the result file path has blank lines above and below in the clipboard after this runs.
I may be mixing up objects and strings (still rooted in a DOS CMD background) or maybe there is something else involved.
$WScript = New-Object -ComObject WScript.Shell; Get-ChildItem -Path "$env:APPDATA\Microsoft\Windows\Recent\*.lnk" | Sort-Object -Property LastWriteTime -Descending | ForEach-Object {$WScript.CreateShortcut($_.FullName).TargetPath} | Select-String -Pattern '\.(pdf|png)$' | Select-Object -First 1 | Clip
»bp
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
EXPERT CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What are you planning on doing with the data stored in the clipboard?
ASKER
Thanks for the guidance.
»bp
»bp
Ok then
ASKER
What are you planning on doing with the data stored in the clipboard?It's just being consumed by another Windows application.
»bp
ASKER
»bp