Please feel free to provide feedback or file bugs here.

Out-GridView should not leave a trailing tab character when ctrl+c is used with only one data row present.

I wrote a script that takes a MAC address in any common format as input and outputs it to all other standard MAC formats. This is all in a single row of data and is meant to be a convenient tool for working between systems that use different formats of MACs without having to constantly reformat them by hand. However, when copying the output from the gridview a trailing tab is placed at the end of the MAC even though there is only a single row in the view and no tabs in the original text. It's like it is setting up for the next row of data that isn't there.

I would expect a ctrl+c on a single row of data containing "64-00-6A-77-9A-50" to return "64-00-6A-77-9A-50" to the clipboard but instead it captures "64-00-6A-77-9A-50 " to the clipboard.

1 vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    I agree to the terms of service
    Signed in as (Sign out)

    We’ll send you updates on this idea

    Alan McLaughlin Jr. shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    2 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      Submitting...
      • Alan McLaughlin Jr. commented  ·   ·  Flag as inappropriate

        I've worked around this by setting the gridview's -outputmode to "single" and writing a function that when data is selected and OK is pressed then invoke [Windows.Forms.Clipboard]::SetText($Selection) sending the text exactly as it appears in the gridview to the clipboard. But just using a ctrl+c would be preferred.

      • Alan McLaughlin Jr. commented  ·   ·  Flag as inappropriate

        Including script for reference in case anyone wants to reproduce the issue:

        #MAC Formater - takes a MAC in any various standard formats and outputs it back to gridview in all standard formats. (2/16/2017) -AJM
        #Last Edit: 7-25-2017

        [System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | Out-Null
        [Collections.Arraylist]$Collection = @()
        $hyphen = ""; $colon = ""; $nodlim = ""; $dotdelim = ""

        if($Args.Count -gt 0) {$MACAddress = $Args[0]}
        else {cls;$MACAddress = [Microsoft.VisualBasic.Interaction]::InputBox("Input MAC Address`n`nField pre-loads from clipboard", "MAC Formatter", (Get-Clipboard -Format Text))}
        if($MACAddress.Length -eq 0){Return}

        $MACAddress = $MACAddress.Replace("-","").Replace(".","").Replace(":","").Replace(" ","").Replace(" ","").ToLower()

        $nodelim = $MACAddress

        if($MACAddress.Length -gt 12) {cls; "Input too long."; return}
        if($MACAddress.Length -lt 12) {cls; "Input too short."; return}

        $dotdelim = "$($nodelim.Substring(0,4)).$($nodelim.Substring(4,4)).$($nodelim.Substring(8,4))"

        $MACAddress = $MACAddress.ToCharArray()

        $i = 0
        Do{
        $colon = $colon + ":" + ($MACAddress[$i] + $MACAddress[$i + 1])
        $hyphen = $hyphen + "-" + ($MACAddress[$i] + $MACAddress[$i + 1])
        $i += 2
        }While($i -lt $MACAddress.Count)

        $colon = $colon.Substring(1,17)
        $hyphen = $hyphen.Substring(1,17)

        $Collection.Add($nodelim) | Out-Null
        $Collection.Add($nodelim.ToUpper()) | Out-Null
        $Collection.Add("") | Out-Null
        $Collection.Add($dotdelim) | Out-Null
        $Collection.Add($dotdelim.ToUpper()) | Out-Null
        $Collection.Add("") | Out-Null
        $Collection.Add($hyphen) | Out-Null
        $Collection.Add($hyphen.ToUpper()) | Out-Null
        $Collection.Add("") | Out-Null
        $Collection.Add($colon) | Out-Null
        $Collection.Add($colon.ToUpper()) | Out-Null

        Do{
        $Selection = $Collection | Out-GridView -OutputMode Single -Title "Select a MAC to copy it to Clipboard"
        If($Selection.Length -gt 0) {[Windows.Forms.Clipboard]::SetText($Selection)}
        }Until($Selection.Length -eq 0)

      Feedback and Knowledge Base