Out-Gridview中的Word Wrap文本

时间:2018-04-24 15:16:03

标签: powershell powershell-v2.0 powershell-v3.0 powershell-v4.0

使用powershell离网视图。有没有办法包装文本,所以用户不必滚动查看所有内容?

Invoke-RestMethod -uri "https://clasd.freshdesk.com/api/v2/tickets? email=xyz@clasd.net" -Headers $FDHeaders -ContentType application/json -Method Get |
    Convertto-json | Out-File C:\csiu\test.txt
$file = "C:\csiu\test.txt"
$data = Get-Content $file -Raw |
    ConvertFrom-Json |
    Select-Object -Expand Value $data |
    Select id, subject, description_text |
    Sort-Object ID |
    Out-GridView -Title "My Tickets" -passthru

希望out-grid视图包裹文本

或者,如果有另一种方式来显示数据“更漂亮”我就是全部。

更新

我一直在玩数据网格,它实际上正在运行。唯一的事情是列的大小不正确,或者它们不会自行调整大小。相关专栏涉及description_text。

#Generated Form Function
function GenerateForm {
    ########################################################################
    # Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.8.0
    # Generated On: 4/6/2013 3:10 PM
    # Generated By: jvierra
    ########################################################################

    #region Import the Assemblies
    [reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
    [reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
    #endregion

    #region Generated Form Objects
    $form1 = New-Object System.Windows.Forms.Form
    $button1 = New-Object System.Windows.Forms.Button
    $dataGrid1 = New-Object System.Windows.Forms.DataGrid
    $InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
    #endregion Generated Form Objects

    #----------------------------------------------
    #Generated Event Script Blocks
    #----------------------------------------------
    #Provide Custom Code for events specified in PrimalForms.
    $button1_OnClick= {
    #TODO: Place custom script here

    }
# API Key
$FDApiKey="key"
#################################################

# Force TLS1.2 as Powershell defaults to TLS 1.0 and Freshdesk will fail connections 
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::TLS12

# Prep
$pair = "$($FDApiKey):$($FDApiKey)"
$bytes = [System.Text.Encoding]::ASCII.GetBytes($pair)
$base64 = [System.Convert]::ToBase64String($bytes)
$basicAuthValue = "Basic $base64"
$FDHeaders = @{ Authorization = $basicAuthValue }
##################################################

<#$Body = @{
description = $description.Text
email = $email.Text
subject = $subject.Text
type = $request.Text
priority = 1
status = 2
}#>

Invoke-RestMethod -uri "https://clasd.freshdesk.com/api/v2/tickets?email=mgirt@clasd.net&order_by=status" -Headers $FDHeaders -ContentType application/json -Method Get | Convertto-json | Out-File c:\temp\mytickets.txt
$file = "c:\temp\mytickets.txt"
$data = Get-Content $file -Raw | ConvertFrom-Json | Select-Object -Expand Value


    $handler_form1_Load= 
    {
    $list=[system.collections.arraylist]($data | select id, subject, description_text)
    $datagrid1.DataSource=$list

    }

    $OnLoadForm_StateCorrection=
    {#Correct the initial state of the form to prevent the .Net maximized form issue
        $form1.WindowState = $InitialFormWindowState
    }

    #----------------------------------------------
    #region Generated Form Code
    $form1.Text = "My Tickets"
    $form1.Name = "form1"
    $form1.DataBindings.DefaultDataSourceUpdateMode = 0
    $System_Drawing_Size = New-Object System.Drawing.Size
    $System_Drawing_Size.Width = 616
    $System_Drawing_Size.Height = 312
    $form1.ClientSize = $System_Drawing_Size
    $form1.add_Load($handler_form1_Load)

    $button1.TabIndex = 1
    $button1.Name = "button1"
    $System_Drawing_Size = New-Object System.Drawing.Size
    $System_Drawing_Size.Width = 75
    $System_Drawing_Size.Height = 23
    $button1.Size = $System_Drawing_Size
    $button1.UseVisualStyleBackColor = $False

    $button1.Text = "Ok"

    $System_Drawing_Point = New-Object System.Drawing.Point
    $System_Drawing_Point.X = 507
    $System_Drawing_Point.Y = 469
    $button1.Location = $System_Drawing_Point
    $button1.DataBindings.DefaultDataSourceUpdateMode = 0
    $button1.DialogResult = 1
    $button1.add_Click($button1_OnClick)

    $form1.Controls.Add($button1)

    $System_Drawing_Size = New-Object System.Drawing.Size
    $System_Drawing_Size.Width = 600
    $System_Drawing_Size.Height = 433
    $dataGrid1.Size = $System_Drawing_Size
    $dataGrid1.DataBindings.DefaultDataSourceUpdateMode = 0
    $dataGrid1.HeaderForeColor = [System.Drawing.Color]::FromArgb(255,0,0,0)
    $dataGrid1.Name = "dataGrid1"
    $dataGrid1.DataMember = ""
    $dataGrid1.TabIndex = 0
    $System_Drawing_Point = New-Object System.Drawing.Point
    $System_Drawing_Point.X = 1
    $System_Drawing_Point.Y = 12
    $dataGrid1.Location = $System_Drawing_Point

    $form1.Controls.Add($dataGrid1)

    #endregion Generated Form Code

    #Save the initial state of the form
    $InitialFormWindowState = $form1.WindowState
    #Init the OnLoad event to correct the initial state of the form
    $form1.add_Load($OnLoadForm_StateCorrection)
    #Show the Form
    $form1.ShowDialog()| Out-Null

} #End Function

#Call the Function
GenerateForm

0 个答案:

没有答案
相关问题