Category Archives: PS Function

PS Function – Close open directory of a specific name

#region FUNCTION close temp123 window
function clsdir(){
$shell = New-Object -ComObject Shell.Application
$window = $shell.Windows() | Where-Object { $_.LocationURL -like “$(([uri]”c:\temp123″).AbsoluteUri)*” }
$window | ForEach-Object { $_.Quit() }
#endregion FUNCTION close grittemp window


PS Function – Copy contents of form textbox to clipboard

#region FUNCTION #3 Copy to clipboard
Function ClipMe() {
#endregion FUNCTION Copy to clipboard

NB: In this example my form has a textbox called $ST – The function captures the text content and trims it to remove any unwanted white space.

$ST = New-Object System.Windows.Forms.Textbox
$ST.Size = New-Object System.Drawing.Size(135,100)
$ST.ReadOnly = $true
$ST.Font = “Segoe UI,16”
$ST.Location = “150,120”
$ST.TextAlign = “Center”