*** Please fill in the fields below. If you leave fields empty or specify 'latest' rather than the actual version your answer will be delayed as we will be forced to ask you for this information. ***
SAPIEN PowerShell Studio 2019
Version 5.6.159
32 or 64 bit version of product:
64
Operating system:
Windows 10 1809
32 or 64 bit OS:
64
Ok. So I used powershell studio to create a powershell GUI with a datagridview control that is populated at runtime. Below is the code for this powershell script:
Code: Select all
#------------------------------------------------------------------------
# Source File Information (DO NOT MODIFY)
# Source ID: a13cf6f4-4592-4901-9096-e9ca07a09e57
# Source File: C:\Users\whiggs\Documents\SAPIEN\PowerShell Studio\Projects\clipboard\clipboard.psproj
#------------------------------------------------------------------------
#region Project Recovery Data (DO NOT MODIFY)
<#RecoveryData:
TQIAAB+LCAAAAAAABACFUltPgzAYfV+y/0D6aMKAuUuIXR/MgtmDl4zFV9OVD6mWlpQyN3+9hYLZ
osaXrz3t4ZycQ/EWmDqAPq2poWQ88jz8pNUbMOOlJ8kKrST/hGyFEipqQN1hwoUBvUJXk6qObtpZ
uiVzS3QsRbfJu1nb6U4KENXEHA3qjKzVM+iaK0mmkwgHA+jvrAts1oRG1yxf5DN/No+n/iwOIz8O
44UPMaPhkoYxzJc46Mn9p32C3akCEuLgHA7iSmTWzgvO3eoe9NC7bbiwyUNEUkO1aao2jPP6i+ml
BdVtXTvd2La2kIMGySBpJDM23Apt5EG9g38n1J6KF1sWIm5ft839o/6LXlqoD/+ecpkoXVq9HJEB
tX/gQtABF/O7FoceNX/lkoqW8EBLIEzwaq+ozqxKZZk4+EEZj3Bw8Xy+ADEXlptNAgAA#>
#endregion
<#
.NOTES
--------------------------------------------------------------------------------
Code generated by: SAPIEN Technologies, Inc., PowerShell Studio 2019 v5.6.159
Generated on: 2/22/2019 5:46 PM
Generated by: whiggs
--------------------------------------------------------------------------------
.DESCRIPTION
Script generated by PowerShell Studio 2019
#>
#region Source: Startup.pss
#region File Recovery Data (DO NOT MODIFY)
<#RecoveryData:
YQAAAB+LCAAAAAAABACzCUpNzi9LLap0SSxJVAAyijPz82yVjPUMlex4uRQUbPyLMtMz8xJz3DJz
Uv0Sc1PtgksSi0pKC/QKiott9DFkebls9JGNtAMAoyFkEGEAAAA=#>
#endregion
#----------------------------------------------
#region Import Assemblies
#----------------------------------------------
#endregion Import Assemblies
#Define a Param block to use custom parameters in the project
#Param ($CustomParameter)
function Main {
<#
.SYNOPSIS
The Main function starts the project application.
.PARAMETER Commandline
$Commandline contains the complete argument string passed to the script packager executable.
.NOTES
Use this function to initialize your script and to call GUI forms.
.NOTES
To get the console output in the Packager (Forms Engine) use:
$ConsoleOutput (Type: System.Collections.ArrayList)
#>
Param ([String]$Commandline)
#--------------------------------------------------------------------------
#TODO: Add initialization script here (Load modules and check requirements)
#--------------------------------------------------------------------------
if((Show-MainForm_psf) -eq 'OK')
{
}
$script:ExitCode = 0 #Set the exit code for the Packager
}
#endregion Source: Startup.pss
#region Source: Globals.ps1
#--------------------------------------------
# Declare Global Variables and Functions here
#--------------------------------------------
#Sample function that provides the location of the script
function Get-ScriptDirectory
{
<#
.SYNOPSIS
Get-ScriptDirectory returns the proper location of the script.
.OUTPUTS
System.String
.NOTES
Returns the correct path within a packaged executable.
#>
[OutputType([string])]
param ()
if ($null -ne $hostinvocation)
{
Split-Path $hostinvocation.MyCommand.path
}
else
{
Split-Path $script:MyInvocation.MyCommand.Path
}
}
$JobTrackerList = New-Object System.Collections.ArrayList
function Add-JobTracker
{
<#
.SYNOPSIS
Add a new job to the JobTracker and starts the timer.
.DESCRIPTION
Add a new job to the JobTracker and starts the timer.
.PARAMETER Name
The name to assign to the Job
.PARAMETER JobScript
The script block that the Job will be performing.
Important: Do not access form controls from this script block.
.PARAMETER ArgumentList
The arguments to pass to the job
.PARAMETER CompleteScript
The script block that will be called when the job is complete.
The job is passed as an argument. The Job argument is null when the job fails.
.PARAMETER UpdateScript
The script block that will be called each time the timer ticks.
The job is passed as an argument. Use this to get the Job's progress.
.EXAMPLE
Job-Begin -Name "JobName" `
-JobScript {
#Important: Do not access form controls from this script block.
Get-WmiObject Win32_Process -Namespace "root\CIMV2"
}`
-CompletedScript {
Param($Job)
$results = Receive-Job -Job $Job
}`
-UpdateScript {
Param($Job)
#$results = Receive-Job -Job $Job -Keep
}
.LINK
#>
Param (
[ValidateNotNull()]
[Parameter(Mandatory = $true)]
[string]$Name,
[ValidateNotNull()]
[Parameter(Mandatory = $true)]
[ScriptBlock]$JobScript,
$ArgumentList = $null,
[ScriptBlock]$CompletedScript,
[ScriptBlock]$UpdateScript)
#Start the Job
$job = Start-Job -Name $Name -ScriptBlock $JobScript -ArgumentList $ArgumentList
if ($job -ne $null)
{
#Create a Custom Object to keep track of the Job & Script Blocks
$psObject = New-Object System.Management.Automation.PSObject
Add-Member -InputObject $psObject -MemberType 'NoteProperty' -Name Job -Value $job
Add-Member -InputObject $psObject -MemberType 'NoteProperty' -Name CompleteScript -Value $CompletedScript
Add-Member -InputObject $psObject -MemberType 'NoteProperty' -Name UpdateScript -Value $UpdateScript
[void]$JobTrackerList.Add($psObject)
#Start the Timer
if (-not $timerJobTracker.Enabled)
{
$timerJobTracker.Start()
}
}
elseif ($CompletedScript -ne $null)
{
#Failed
Invoke-Command -ScriptBlock $CompletedScript -ArgumentList $null
}
}
function Update-JobTracker
{
<#
.SYNOPSIS
Checks the status of each job on the list.
#>
#Poll the jobs for status updates
$timerJobTracker.Stop() #Freeze the Timer
for ($index = 0; $index -lt $JobTrackerList.Count; $index++)
{
$psObject = $JobTrackerList[$index]
if ($psObject -ne $null)
{
if ($psObject.Job -ne $null)
{
if ($psObject.Job.State -ne "Running")
{
#Call the Complete Script Block
if ($psObject.CompleteScript -ne $null)
{
#$results = Receive-Job -Job $psObject.Job
Invoke-Command -ScriptBlock $psObject.CompleteScript -ArgumentList $psObject.Job
}
$JobTrackerList.RemoveAt($index)
Remove-Job -Job $psObject.Job
$index-- #Step back so we don't skip a job
}
elseif ($psObject.UpdateScript -ne $null)
{
#Call the Update Script Block
Invoke-Command -ScriptBlock $psObject.UpdateScript -ArgumentList $psObject.Job
}
}
}
else
{
$JobTrackerList.RemoveAt($index)
$index-- #Step back so we don't skip a job
}
}
if ($JobTrackerList.Count -gt 0)
{
$timerJobTracker.Start() #Resume the timer
}
}
function Stop-JobTracker
{
<#
.SYNOPSIS
Stops and removes all Jobs from the list.
#>
#Stop the timer
$timerJobTracker.Stop()
#Remove all the jobs
while ($JobTrackerList.Count -gt 0)
{
$job = $JobTrackerList[0].Job
$JobTrackerList.RemoveAt(0)
Stop-Job $job
Remove-Job $job
}
}#endregion
#Sample variable that provides the location of the script
[string]$ScriptDirectory = Get-ScriptDirectory
#endregion Source: Globals.ps1
#region Source: MainForm.psf
function Show-MainForm_psf
{
#region File Recovery Data (DO NOT MODIFY)
<#RecoveryData:
qwQAAB+LCAAAAAAABABllFmPqkoUhd9N/A/mvHLSQDEIN3YnBSgIKDIqpl8YCkTmScXcH3/tPnfM
rXqpvXdqZSVf1l5ZKKpvqJukYAgWr0ef1dX7D+qN/PExny0WK6PL0qwKik1WoH1Qoo9dkFWbuivf
mj5Z4f8bf3/6mn887DAnU2IXwxxC0ZBE+OsIUCQ9jzyAJ3STM0bgQCoMXwPqRsyHYev68qMTQP1E
2hQx6y2vSOOkuB1gKRTPZ4NmEJewddr8Yh16lqmwGPGAtSkGBofkymVnAXGEuvNcKSlJJzAVhngS
ZsngXW23LTcmQw4mLKG2ij2fOdsGi/b2VBBYljeDbXo8DCynOHT5sOaWtkJKGy4t1odnvqzBOqi6
8ODc1TqOOH5bZkZ1wc3T0F9Z//l4qYmKkbHm3a70gTxuslqPtU0r7AZb4DQfRI3qSEI0CECEJhpb
h8+rG4JVbFmUKulPYXPqgsnPaQjW5Xy2hJy9U7LkspbpHDedJc+mTklU+9o/+WBvYXZIcJeC1yl4
XJ/kZusNftUxGGtRp0kGRB04uHg4M1LYhPOZ4BoBlDBa0q/kuufTSXcYG1K3ve6NDvvQgHa9qL0M
KGvcHbU2L1JMdrSreYaadkiyfP2Fc3jhPJvNfLY/Z9QeyyJBzPguNSoistoqZXO124AGG52tIsHH
02HUq0qbPq2PjY+sfBfd8bLYnlUmDfNKER9Lybjs57NdotDOzVs+aApShgdMk+Lb4gIeQHjR8QrW
uFuVA679HTsRQniO7GV1hJw33W+pL4s7iLaRyzKxpV/c+Sy0LaY0b7Eu2oRsKhVKMYwPa0o+xUHu
Zm2fp0cvMrCNYIWox3eOGpZydgFkEp4eXhab7sEiOYjO+BHMZydoky+st/LYUMleHQxPkIHigztq
q0dHTU9rwtjwLgX0k6HMCzKO3Dlc33cokpvUiyzc52Nycq2qRvR8pu70vYuLVz2Uyam9KRfm6Cpm
yKVto1a83+5JCr9RAddtlzhgkricJJkjiTiBrs9ix6Ujqxtiik2q858vChrtnIi9QS89wsPV8DB2
wonVQ/8QE6IJ4Qr/DuJ3JGHfozIsMtR/1/90pg+hfrx54OfC+zP95BvxdX8uxLEYxg69V2gcuqD4
uTiML4VIQ5NT56h6j+M44BLE0nGMyCCifhd/+3RQ2XxWY4qGz1+6b69dAt6IzyILPys00Mxf/bgo
VvjfJr5N4v9xucL/vZw+/gCo3OfgqwQAAA==#>
#endregion
#----------------------------------------------
#region Import the Assemblies
#----------------------------------------------
[void][reflection.assembly]::LoadFile('C:\Temp\nuget\Box.V2.3.12.0\lib\net45\Box.V2.dll')
[void][reflection.assembly]::Load('System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
[void][reflection.assembly]::Load('System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')
#endregion Import Assemblies
#----------------------------------------------
#region Generated Form Objects
#----------------------------------------------
[System.Windows.Forms.Application]::EnableVisualStyles()
$form1 = New-Object 'System.Windows.Forms.Form'
$labelTheList = New-Object 'System.Windows.Forms.Label'
$datagridview1 = New-Object 'System.Windows.Forms.DataGridView'
$timerJobTracker = New-Object 'System.Windows.Forms.Timer'
$InitialFormWindowState = New-Object 'System.Windows.Forms.FormWindowState'
#endregion Generated Form Objects
#----------------------------------------------
# User Generated Script
#----------------------------------------------
$form1_Load={
#TODO: Initialize Form Controls here
connect-box
$assemblies = [System.AppDomain]::CurrentDomain.GetAssemblies() | Where-Object { $_.Location -like "*Box.V2.dll" }
If ($assemblies -is [array])
{
$assemblies = $assemblies[0]
}
$retrieve = $assemblies.GetExportedTypes() | Where-Object { $_.BaseType -like "Box.V2.Models*" } | Sort-Object -Property "Name"
$array = New-Object System.Collections.ArrayList
foreach ($item in $retrieve)
{
$psob = New-Object -TypeName System.Management.Automation.PSObject
$psob | Add-Member -MemberType NoteProperty -Name Object -Value $item.ToString()
If ($item.Name -like "*request*")
{
$ur = "https://github.com/box/box-windows-sdk-v2/blob/master/Box.V2/Models/Request/$($item.Name).cs"
}
elseif ($item.Name -like "*permission*")
{
$ur = "https://github.com/box/box-windows-sdk-v2/blob/master/Box.V2/Models/Permissions/$($item.Name).cs"
}
Else
{
$ur = "https://github.com/box/box-windows-sdk-v2/blob/master/Box.V2/Models/$($item.Name).cs"
}
$ping = . http-ping.exe $ur -n 1 -q
If ($ping[3] -like "*OK*")
{
$split = $item.ToString().Split(".")
$replace = $split[-1] -creplace "([A-Z])", " $&"
$input = "[$($replace.Trim()) Object:]($ur)"
$psob | Add-Member -MemberType NoteProperty -Name URL -Value "$input"
}
Else
{
$psob | Add-Member -MemberType NoteProperty -Name URL -Value ""
}
#$ur = "https://github.com/box/box-windows-sdk-v2/blob/master/Box.V2/Models/$($item.Name).cs"
#$psob | Add-Member -MemberType NoteProperty -Name URL -Value $ur
$array.Add($psob)
}
$timerJobTracker.Enabled = $true
Update-DataGridView -DataGridView $datagridview1 -Item $array # -AutoSizeColumns
}
#region Control Helper Functions
function Update-DataGridView
{
<#
.SYNOPSIS
This functions helps you load items into a DataGridView.
.DESCRIPTION
Use this function to dynamically load items into the DataGridView control.
.PARAMETER DataGridView
The DataGridView control you want to add items to.
.PARAMETER Item
The object or objects you wish to load into the DataGridView's items collection.
.PARAMETER DataMember
Sets the name of the list or table in the data source for which the DataGridView is displaying data.
.PARAMETER AutoSizeColumns
Resizes DataGridView control's columns after loading the items.
#>
Param (
[ValidateNotNull()]
[Parameter(Mandatory=$true)]
[System.Windows.Forms.DataGridView]$DataGridView,
[ValidateNotNull()]
[Parameter(Mandatory=$true)]
$Item,
[Parameter(Mandatory=$false)]
[string]$DataMember,
[System.Windows.Forms.DataGridViewAutoSizeColumnsMode]$AutoSizeColumns = 'None'
)
$DataGridView.SuspendLayout()
$DataGridView.DataMember = $DataMember
if ($null -eq $Item)
{
$DataGridView.DataSource = $null
}
elseif ($Item -is [System.Data.DataSet] -and $Item.Tables.Count -gt 0)
{
$DataGridView.DataSource = $Item.Tables[0]
}
elseif ($Item -is [System.ComponentModel.IListSource]`
-or $Item -is [System.ComponentModel.IBindingList] -or $Item -is [System.ComponentModel.IBindingListView] )
{
$DataGridView.DataSource = $Item
}
else
{
$array = New-Object System.Collections.ArrayList
if ($Item -is [System.Collections.IList])
{
$array.AddRange($Item)
}
else
{
$array.Add($Item)
}
$DataGridView.DataSource = $array
}
if ($AutoSizeColumns -ne 'None')
{
$DataGridView.AutoResizeColumns($AutoSizeColumns)
}
$DataGridView.ResumeLayout()
}
function ConvertTo-DataTable
{
<#
.SYNOPSIS
Converts objects into a DataTable.
.DESCRIPTION
Converts objects into a DataTable, which are used for DataBinding.
.PARAMETER InputObject
The input to convert into a DataTable.
.PARAMETER Table
The DataTable you wish to load the input into.
.PARAMETER RetainColumns
This switch tells the function to keep the DataTable's existing columns.
.PARAMETER FilterWMIProperties
This switch removes WMI properties that start with an underline.
.EXAMPLE
$DataTable = ConvertTo-DataTable -InputObject (Get-Process)
#>
[OutputType([System.Data.DataTable])]
param(
$InputObject,
[ValidateNotNull()]
[System.Data.DataTable]$Table,
[switch]$RetainColumns,
[switch]$FilterWMIProperties)
if($null -eq $Table)
{
$Table = New-Object System.Data.DataTable
}
if ($null -eq $InputObject)
{
$Table.Clear()
return @( ,$Table)
}
if ($InputObject -is [System.Data.DataTable])
{
$Table = $InputObject
}
elseif ($InputObject -is [System.Data.DataSet] -and $InputObject.Tables.Count -gt 0)
{
$Table = $InputObject.Tables[0]
}
else
{
if (-not $RetainColumns -or $Table.Columns.Count -eq 0)
{
#Clear out the Table Contents
$Table.Clear()
if ($null -eq $InputObject) { return } #Empty Data
$object = $null
#find the first non null value
foreach ($item in $InputObject)
{
if ($null -ne $item)
{
$object = $item
break
}
}
if ($null -eq $object) { return } #All null then empty
#Get all the properties in order to create the columns
foreach ($prop in $object.PSObject.Get_Properties())
{
if (-not $FilterWMIProperties -or -not $prop.Name.StartsWith('__')) #filter out WMI properties
{
#Get the type from the Definition string
$type = $null
if ($null -ne $prop.Value)
{
try { $type = $prop.Value.GetType() }
catch { Out-Null }
}
if ($null -ne $type) # -and [System.Type]::GetTypeCode($type) -ne 'Object')
{
[void]$table.Columns.Add($prop.Name, $type)
}
else #Type info not found
{
[void]$table.Columns.Add($prop.Name)
}
}
}
if ($object -is [System.Data.DataRow])
{
foreach ($item in $InputObject)
{
$Table.Rows.Add($item)
}
return @( ,$Table)
}
}
else
{
$Table.Rows.Clear()
}
foreach ($item in $InputObject)
{
$row = $table.NewRow()
if ($item)
{
foreach ($prop in $item.PSObject.Get_Properties())
{
if ($table.Columns.Contains($prop.Name))
{
$row.Item($prop.Name) = $prop.Value
}
}
}
[void]$table.Rows.Add($row)
}
}
return @(,$Table)
}
#endregion
$datagridview1_CellContentClick=[System.Windows.Forms.DataGridViewCellEventHandler]{
#Event Argument: $_ = [System.Windows.Forms.DataGridViewCellEventArgs]
#TODO: Place custom script here
If ($datagridview1.SelectedCells[0].Value.Startswith("["))
{
Set-Clipboard "$($datagridview1.SelectedCells[0].Value)`r`n`r`n"
}
Else
{
Set-Clipboard $datagridview1.SelectedCells[0].Value
}
}
$timerJobTracker_Tick={
#TODO: Place custom script here
Update-jobtracker
}
$form1_FormClosed=[System.Windows.Forms.FormClosedEventHandler]{
#Event Argument: $_ = [System.Windows.Forms.FormClosedEventArgs]
#TODO: Place custom script here
Stop-JobTracker
}
# --End User Generated Script--
#----------------------------------------------
#region Generated Events
#----------------------------------------------
$Form_StateCorrection_Load=
{
#Correct the initial state of the form to prevent the .Net maximized form issue
$form1.WindowState = $InitialFormWindowState
}
$Form_StoreValues_Closing=
{
#Store the control values
$script:MainForm_datagridview1 = $datagridview1.SelectedCells
if ($datagridview1.SelectionMode -eq 'FullRowSelect')
{ $script:MainForm_datagridview1_SelectedObjects = $datagridview1.SelectedRows | Select-Object -ExpandProperty DataBoundItem }
else { $script:MainForm_datagridview1_SelectedObjects = $datagridview1.SelectedCells | Select-Object -ExpandProperty RowIndex -Unique | ForEach-Object { if ($_ -ne -1) { $datagridview1.Rows[$_].DataBoundItem } } }
}
$Form_Cleanup_FormClosed=
{
#Remove all event handlers from the controls
try
{
$datagridview1.remove_CellContentClick($datagridview1_CellContentClick)
$form1.remove_FormClosed($form1_FormClosed)
$form1.remove_Load($form1_Load)
$timerJobTracker.remove_Tick($timerJobTracker_Tick)
$form1.remove_Load($Form_StateCorrection_Load)
$form1.remove_Closing($Form_StoreValues_Closing)
$form1.remove_FormClosed($Form_Cleanup_FormClosed)
}
catch { Out-Null <# Prevent PSScriptAnalyzer warning #> }
}
#endregion Generated Events
#----------------------------------------------
#region Generated Form Code
#----------------------------------------------
$form1.SuspendLayout()
#
# form1
#
$form1.Controls.Add($labelTheList)
$form1.Controls.Add($datagridview1)
$form1.AutoScaleDimensions = '6, 13'
$form1.AutoScaleMode = 'Font'
$form1.ClientSize = '619, 545'
$form1.Name = 'form1'
$form1.Text = 'Form'
$form1.add_FormClosed($form1_FormClosed)
$form1.add_Load($form1_Load)
#
# labelTheList
#
$labelTheList.AutoSize = $True
$labelTheList.Font = 'Microsoft Sans Serif, 24pt'
$labelTheList.Location = '234, 18'
$labelTheList.Name = 'labelTheList'
$labelTheList.Size = '128, 44'
$labelTheList.TabIndex = 1
$labelTheList.Text = 'The List'
$labelTheList.UseCompatibleTextRendering = $True
#
# datagridview1
#
$datagridview1.AllowUserToDeleteRows = $False
$datagridview1.AutoSizeColumnsMode = 'AllCells'
$datagridview1.AutoSizeRowsMode = 'AllCells'
$datagridview1.ClipboardCopyMode = 'EnableWithoutHeaderText'
$datagridview1.ColumnHeadersHeightSizeMode = 'AutoSize'
$datagridview1.Location = '12, 80'
$datagridview1.MultiSelect = $False
$datagridview1.Name = 'datagridview1'
$datagridview1.ReadOnly = $True
$datagridview1.RowTemplate.ReadOnly = $True
$datagridview1.Size = '595, 453'
$datagridview1.TabIndex = 0
$datagridview1.add_CellContentClick($datagridview1_CellContentClick)
#
# timerJobTracker
#
$timerJobTracker.add_Tick($timerJobTracker_Tick)
$form1.ResumeLayout()
#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($Form_StateCorrection_Load)
#Clean up the control events
$form1.add_FormClosed($Form_Cleanup_FormClosed)
#Store the control values when form is closing
$form1.add_Closing($Form_StoreValues_Closing)
#Show the Form
return $form1.ShowDialog()
}
#endregion Source: MainForm.psf
#Start the application
Main ($CommandLine)