{"id":1279,"date":"2024-02-23T17:33:37","date_gmt":"2024-02-23T17:33:37","guid":{"rendered":"https:\/\/ihni.uk\/?p=1279"},"modified":"2024-02-23T17:33:37","modified_gmt":"2024-02-23T17:33:37","slug":"vmware-paste-into-the-vsphere-console-finally","status":"publish","type":"post","link":"https:\/\/ihni.uk\/?p=1279","title":{"rendered":"VMWare &#8211; &#8216;Paste&#8217; into the VSphere Console, Finally!"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Getting frustrated with not being able to paste directly into the VMRC?<br>On your 400th attempt at typing that autogenerated password for the VM Template?<br>Chronic case of Sausage Fingers?<br>Or are you just a lazy sys admin? <\/p>\n\n\n\n<!--more-->\n\n\n\n<p class=\"wp-block-paragraph\">Look no further, with the powers of Chat GPT and imagination&#8230; <\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"220\" height=\"164\" src=\"http:\/\/ihni.uk\/wp-content\/uploads\/2024\/02\/image.png\" alt=\"\" class=\"wp-image-1280\" style=\"width:423px;height:auto\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">I have created the following dumb ass typing PowerShell form!<\/p>\n\n\n\n<div class=\"wp-block-cover\" style=\"min-height:647px;aspect-ratio:unset;\"><span aria-hidden=\"true\" class=\"wp-block-cover__background has-background-dim\"><\/span><img loading=\"lazy\" decoding=\"async\" width=\"490\" height=\"398\" class=\"wp-block-cover__image-background wp-image-1282\" alt=\"\" src=\"http:\/\/ihni.uk\/wp-content\/uploads\/2024\/02\/image-1.png\" data-object-fit=\"cover\" srcset=\"https:\/\/ihni.uk\/wp-content\/uploads\/2024\/02\/image-1.png 490w, https:\/\/ihni.uk\/wp-content\/uploads\/2024\/02\/image-1-300x244.png 300w\" sizes=\"auto, (max-width: 490px) 100vw, 490px\" \/><div class=\"wp-block-cover__inner-container is-layout-flow wp-block-cover-is-layout-flow\">\n<p class=\"has-text-align-center has-large-font-size wp-block-paragraph\">Its not pretty, but it is pretty simple!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-group\" style=\"font-size:12px\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<pre class=\"wp-block-code\"><code>Add-Type -AssemblyName System.Windows.Forms\n\n# Create a form\n$form = New-Object System.Windows.Forms.Form\n$form.Text = \"Clipboard Text Sender\"\n$form.Width = 500\n$form.Height = 400\n$form.StartPosition = \"CenterScreen\"\n\n# Create a label for validation status\n$validationLabel = New-Object System.Windows.Forms.Label\n$validationLabel.Location = New-Object System.Drawing.Point(20, 330)\n$validationLabel.AutoSize = $true\n$form.Controls.Add($validationLabel)\n\n# Create a frame for the textbox\n$textFrame = New-Object System.Windows.Forms.GroupBox\n$textFrame.Text = \"Enter Text:\"\n$textFrame.Location = New-Object System.Drawing.Point(20, 20)\n$textFrame.Width = 440\n$textFrame.Height = 250\n$form.Controls.Add($textFrame)\n\n# Create a multi-line text box for entering text\n$textBox = New-Object System.Windows.Forms.TextBox\n$textBox.Location = New-Object System.Drawing.Point(10, 20)\n$textBox.Width = 420\n$textBox.Height = 180\n$textBox.Multiline = $true\n$textFrame.Controls.Add($textBox)\n\n# Create a button to clear the text box\n$clearButton = New-Object System.Windows.Forms.Button\n$clearButton.Text = \"Clear\"\n$clearButton.Location = New-Object System.Drawing.Point(10, 210)\n$clearButton.Add_Click({\n    $textBox.Clear()\n    $validationLabel.Text = \"\"\n})\n$textFrame.Controls.Add($clearButton)\n\n# Create a button for triggering actions\n$typeButton = New-Object System.Windows.Forms.Button\n$typeButton.Text = \"Type Text\"\n$typeButton.Location = New-Object System.Drawing.Point(110, 210)\n$typeButton.Add_Click({\n    # Get the text from the text box\n    $clipboardText = $textBox.Text\n\n    # Check if the clipboard contains alphanumeric or text data\n    if ($clipboardText -match '^&#91;\\w\\s\\S]+$') {\n        Write-Host \"Clipboard does contain alphanumeric or text data.\"\n\n        $countdownSeconds = 5\n\n        # Countdown loop\n        for ($i = $countdownSeconds; $i -gt 0; $i--) {\n            # Update the validation label with the countdown\n            $validationLabel.Text = \"Countdown: $i seconds remaining\"\n            # Wait for 1 second\n            Start-Sleep -Seconds 1\n        }\n\n        # Type out the clipboard text\n        #$escapedText = $clipboardText -replace '(&#91;{}^%~])', '{$1}'\n        # Replace each special character with its escaped version\n        $escapedText = $clipboardText -replace '\\+', '{+}' `\n                                       -replace '\\^', '{^}' `\n                                       -replace '%', '{%}' `\n                                       -replace '~', '{~}' `\n                                       -replace '\\(', '{(}' `\n                                       -replace '\\)', '{)}' `\n                                       -replace '\\&#91;', '{&#91;}' `\n                                       -replace '\\]', '{]}'\n        \n        &#91;System.Windows.Forms.SendKeys]::SendWait($escapedText)\n\n        $validationLabel.Text = \"Validation: Success\"\n    } else {\n        # Display a message in the validation label with the error message and show the content that triggered the error\n        $validationLabel.Text = \"Validation: Error - Clipboard does not contain alphanumeric or text data.\"\n    }\n})\n\n$textFrame.Controls.Add($typeButton)\n\n# Show the form\n$form.ShowDialog()\n<\/code><\/pre>\n<\/div><\/div>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Getting frustrated with not being able to paste directly into the VMRC?On your 400th attempt&hellip;<\/p>\n","protected":false},"author":1,"featured_media":1318,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[19,14],"tags":[50,64,80],"class_list":["post-1279","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell","category-vmware","tag-lazy","tag-powershell","tag-vmware"],"jetpack_featured_media_url":"https:\/\/ihni.uk\/wp-content\/uploads\/2024\/08\/Screenshot_20240828-212411.png","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/ihni.uk\/index.php?rest_route=\/wp\/v2\/posts\/1279","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ihni.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ihni.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ihni.uk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ihni.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1279"}],"version-history":[{"count":0,"href":"https:\/\/ihni.uk\/index.php?rest_route=\/wp\/v2\/posts\/1279\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ihni.uk\/index.php?rest_route=\/wp\/v2\/media\/1318"}],"wp:attachment":[{"href":"https:\/\/ihni.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1279"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ihni.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1279"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ihni.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1279"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}