Created
June 10, 2016 16:24
-
-
Save Hexalon/7427d5af01f5dfc03fbea0260ca919ac to your computer and use it in GitHub Desktop.
GUI version of queries redirected folder locations using the .NET Framework. Stores data in an ordered hash table and writes to the pipline.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.NOTES | |
-------------------------------------------------------------------------------- | |
Code generated by: SAPIEN Technologies, Inc., PowerShell Studio 2016 v5.2.122 | |
Generated on: 6/10/2016 10:44 | |
Generated by: Colin Squier <[email protected] | |
-------------------------------------------------------------------------------- | |
.DESCRIPTION | |
GUI script generated by PowerShell Studio 2016 | |
#> | |
#---------------------------------------------- | |
#region Application Functions | |
#---------------------------------------------- | |
#endregion Application Functions | |
#---------------------------------------------- | |
# Generated Form Function | |
#---------------------------------------------- | |
function Call-CheckFolderRedirection_psf { | |
#---------------------------------------------- | |
#region Import the Assemblies | |
#---------------------------------------------- | |
[void][reflection.assembly]::Load('System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089') | |
[void][reflection.assembly]::Load('System.Data, 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() | |
$formCheckFolderRedirecti = New-Object 'System.Windows.Forms.Form' | |
$richtextbox1 = New-Object 'System.Windows.Forms.RichTextBox' | |
$buttonCopy = New-Object 'System.Windows.Forms.Button' | |
$buttonExit = New-Object 'System.Windows.Forms.Button' | |
$buttonLoad = New-Object 'System.Windows.Forms.Button' | |
$InitialFormWindowState = New-Object 'System.Windows.Forms.FormWindowState' | |
#endregion Generated Form Objects | |
#---------------------------------------------- | |
# User Generated Script | |
#---------------------------------------------- | |
$formCheckFolderRedirecti_Load={ | |
#TODO: Initialize Form Controls here | |
} | |
$buttonExit_Click={ | |
#TODO: Place custom script here | |
$formCheckFolderRedirecti.Close() | |
} | |
$buttonLoad_Click={ | |
Load-Text | |
} | |
$buttonCopy_Click={ | |
#The following requires STA mode | |
# if($textbox1.Text.Length -gt 0) | |
# { | |
# [System.Windows.Forms.Clipboard]::SetText($textbox1.Text) | |
# } | |
#Alternative - Does not require STA | |
$richtextbox1.SelectAll() #Select all the text | |
$richtextbox1.Copy() #Copy selected text to clipboard | |
$richtextbox1.Select(0,0); #Unselect all the text | |
} | |
################################################# | |
# Customize LoadText Function | |
################################################# | |
function Load-Text | |
{ | |
# ------------------------- | |
# Sample Code to Load Text | |
# ------------------------- | |
# $richtextbox1.Text = Get-Process | Out-String | |
$stringBuilder = New-Object System.Text.StringBuilder | |
$FolderLocations = Get-FolderLocations | |
$FolderLocations = ($FolderLocations | Out-String).Trim() | |
$stringBuilder.AppendLine($FolderLocations) | |
$richtextbox1.Text = $stringBuilder.ToString() | |
} | |
function Get-FolderLocations | |
{ | |
$RedirectedFolders = @() | |
$Props = [ordered]@{ | |
'Computer' = $env:COMPUTERNAME | |
'UserName' = $env:USERNAME | |
'AppData' = ([System.Environment]::GetFolderPath("ApplicationData")) | |
'Desktop' = ([System.Environment]::GetFolderPath("Desktop")) | |
'Documents' = ([System.Environment]::GetFolderPath("MyDocuments")) | |
'Favorites' = ([System.Environment]::GetFolderPath("Favorites")) | |
'StartMenu' = ([System.Environment]::GetFolderPath("StartMenu")) | |
} | |
$RedirectedFolders += New-Object -TypeName PSObject -Property $Props | |
Write-Output $RedirectedFolders | |
} | |
$richtextbox1_TextChanged={ | |
#TODO: Place custom script here | |
$richtextbox1.SelectionStart = $richtextbox1.TextLength; | |
$richtextbox1.ScrollToCaret() | |
$richtextbox1.Focus() | |
} | |
$formCheckFolderRedirecti_KeyPress = [System.Windows.Forms.KeyPressEventHandler]{ | |
#Event Argument: $_ = [System.Windows.Forms.KeyPressEventArgs] | |
#TODO: Place custom script here | |
if ($_.KeyChar -eq 27) | |
{ | |
$formCheckFolderRedirecti.Close() | |
} | |
} | |
# --End User Generated Script-- | |
#---------------------------------------------- | |
#region Generated Events | |
#---------------------------------------------- | |
$Form_StateCorrection_Load= | |
{ | |
#Correct the initial state of the form to prevent the .Net maximized form issue | |
$formCheckFolderRedirecti.WindowState = $InitialFormWindowState | |
} | |
$Form_Cleanup_FormClosed= | |
{ | |
#Remove all event handlers from the controls | |
try | |
{ | |
$richtextbox1.remove_TextChanged($richtextbox1_TextChanged) | |
$buttonCopy.remove_Click($buttonCopy_Click) | |
$buttonExit.remove_Click($buttonExit_Click) | |
$buttonLoad.remove_Click($buttonLoad_Click) | |
$formCheckFolderRedirecti.remove_Load($formCheckFolderRedirecti_Load) | |
$formCheckFolderRedirecti.remove_Load($Form_StateCorrection_Load) | |
$formCheckFolderRedirecti.remove_FormClosed($Form_Cleanup_FormClosed) | |
} | |
catch [Exception] | |
{ } | |
} | |
#endregion Generated Events | |
#---------------------------------------------- | |
#region Generated Form Code | |
#---------------------------------------------- | |
$formCheckFolderRedirecti.SuspendLayout() | |
# | |
# formCheckFolderRedirecti | |
# | |
$formCheckFolderRedirecti.Controls.Add($richtextbox1) | |
$formCheckFolderRedirecti.Controls.Add($buttonCopy) | |
$formCheckFolderRedirecti.Controls.Add($buttonExit) | |
$formCheckFolderRedirecti.Controls.Add($buttonLoad) | |
$formCheckFolderRedirecti.AcceptButton = $buttonLoad | |
$formCheckFolderRedirecti.CancelButton = $buttonExit | |
$formCheckFolderRedirecti.ClientSize = '584, 362' | |
$formCheckFolderRedirecti.FormBorderStyle = 'FixedDialog' | |
$formCheckFolderRedirecti.Name = 'formCheckFolderRedirecti' | |
$formCheckFolderRedirecti.StartPosition = 'CenterScreen' | |
$formCheckFolderRedirecti.Text = 'Check Folder Redirection Paths' | |
$formCheckFolderRedirecti.add_Load($formCheckFolderRedirecti_Load) | |
# | |
# richtextbox1 | |
# | |
$richtextbox1.Anchor = 'Top, Bottom, Left, Right' | |
$richtextbox1.BackColor = 'Window' | |
$richtextbox1.Font = 'Courier New, 8.25pt' | |
$richtextbox1.HideSelection = $False | |
$richtextbox1.Location = '12, 12' | |
$richtextbox1.Name = 'richtextbox1' | |
$richtextbox1.ReadOnly = $True | |
$richtextbox1.Size = '559, 305' | |
$richtextbox1.TabIndex = 6 | |
$richtextbox1.Text = '' | |
$richtextbox1.WordWrap = $False | |
$richtextbox1.add_TextChanged($richtextbox1_TextChanged) | |
# | |
# buttonCopy | |
# | |
$buttonCopy.Anchor = 'Bottom' | |
$buttonCopy.Location = '255, 327' | |
$buttonCopy.Name = 'buttonCopy' | |
$buttonCopy.Size = '75, 23' | |
$buttonCopy.TabIndex = 3 | |
$buttonCopy.Text = '&Copy' | |
$buttonCopy.UseVisualStyleBackColor = $True | |
$buttonCopy.add_Click($buttonCopy_Click) | |
# | |
# buttonExit | |
# | |
$buttonExit.Anchor = 'Bottom, Right' | |
$buttonExit.DialogResult = 'Cancel' | |
$buttonExit.Location = '497, 327' | |
$buttonExit.Name = 'buttonExit' | |
$buttonExit.Size = '75, 23' | |
$buttonExit.TabIndex = 2 | |
$buttonExit.Text = 'E&xit' | |
$buttonExit.UseVisualStyleBackColor = $True | |
$buttonExit.add_Click($buttonExit_Click) | |
# | |
# buttonLoad | |
# | |
$buttonLoad.Anchor = 'Bottom, Left' | |
$buttonLoad.Location = '12, 327' | |
$buttonLoad.Name = 'buttonLoad' | |
$buttonLoad.Size = '75, 23' | |
$buttonLoad.TabIndex = 1 | |
$buttonLoad.Text = '&Load' | |
$buttonLoad.UseVisualStyleBackColor = $True | |
$buttonLoad.add_Click($buttonLoad_Click) | |
$formCheckFolderRedirecti.ResumeLayout() | |
#endregion Generated Form Code | |
#---------------------------------------------- | |
#Save the initial state of the form | |
$InitialFormWindowState = $formCheckFolderRedirecti.WindowState | |
#Init the OnLoad event to correct the initial state of the form | |
$formCheckFolderRedirecti.add_Load($Form_StateCorrection_Load) | |
#Clean up the control events | |
$formCheckFolderRedirecti.add_FormClosed($Form_Cleanup_FormClosed) | |
#Show the Form | |
return $formCheckFolderRedirecti.ShowDialog() | |
} #End Function | |
#Call the form | |
Call-CheckFolderRedirection_psf | Out-Null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment