Jume - My Virtualization Blog

My personal and professional virtualization blog. Everything about VMware, PowerCLI, Powershell, Agile, Scrum, VSAN and Cloud related.

Some short Powershell tips #1

Tip 1: 

If you're in a folder (using your file explorer), and want to open a Powershell box there (or command box also works), type 'powershell.exe' in its path and the new window opens at that location.

If you run PowerShell Core, you can also use 'pwsh' or if you want a command box window, use 'cmd'.

Tip 2: 

Last few days I've been creating an Excel sheet with data gathered using PowerShell. And yes, I know you have a great Excel module, and yes, I know you can export the data to .CSV and then import it in Excel… But I just want to paste the data on a sheet somewhere I liked.

There is a cool cmdlet called: Set-Clipboard

PS H:\> get-help Set-Clipboard

NAME

Set-Clipboard

SYNTAX

Set-Clipboard [-Append] [-AsHtml] [-WhatIf] [-Confirm] [<CommonParameters>]

Set-Clipboard [-Value] <string[]> [-Append] [-AsHtml] [-WhatIf] [-Confirm] [<CommonParameters>]

Set-Clipboard -Path <string[]> [-Append] [-AsHtml] [-WhatIf] [-Confirm] [<CommonParameters>]

Set-Clipboard -LiteralPath <string[]> [-Append] [-AsHtml] [-WhatIf] [-Confirm] [<CommonParameters>]

ALIASES
    scb 

That's handy, but Excel likes to have <tabs> between the cells, and you can do that too (note scb is the default alias):

Example:

Get-Process -Name pwsh | ConvertTo-Csv -NoTypeInformation -Delimiter "`t" | scb 

Now you can just paste the info in Excel, and all is put in separate cells:

Very cool! Please note the -Delimiter option: the value is `t, the ` isn't the same as '. So it's the one just below the <ESC> key (the ~ on my keyboard).

You can also pipe it into clip.exe (if you're on Windows) – and this is also compatible with PowerShell Core (Core doesn't have Set-Clipboard by the way). Here is a one-liner which works for PowerShell Core:

Get-Process -Name pwsh | ConvertTo-Csv -NoTypeInformation -Delimiter "`t" | clip 

By the way, the ImportExcel modules is quite cool, check it out: https://github.com/dfinke/ImportExcel

Install-Module -Name ImportExcel -Scope CurrentUser -Force 
×
Stay Informed

When you subscribe to the blog, we will send you an e-mail when there are new updates on the site so you wouldn't miss them.

Some short PowerShell tips #2
ForEach vs Select-Object -ExpandProperty

Related Posts

 

Comments 1

Guest
Guest - سود پرک (website) on Monday, 13 January 2020 12:53

Thanks for your very useful site

Thanks for your very useful site
Guest
Tuesday, 28 November 2023