How can I uninstall Hotfix remotely with Powershell - powershell

This what I have so far it brings up a Syntax screen for wusa. I have confirmed that the Trim is working. If I leave out the remote computer name is works on the local computer. I will be adding this to a much larger script just trying to get this working before trying to add it.
<#
.NAME
Template
#>
$comp = "Remote Pc Name Goes Here"
$str = $Hotfix_TextBox.Text. Trim("K","B")
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()
$Form = New-Object system.Windows.Forms.Form
$Form.ClientSize = New-Object System.Drawing.Point(400,400)
$Form.text = "Form"
$Form.TopMost = $false
$gethotfix = New-Object system.Windows.Forms.Button
$gethotfix.text = "Get Hotfixes"
$gethotfix.width = 120
$gethotfix.height = 30
$gethotfix.location = New-Object System.Drawing.Point(100,81)
$gethotfix.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)
$removehotfix = New-Object system.Windows.Forms.Button
$removehotfix.text = "Remove Hotfix"
$removehotfix.width = 120
$removehotfix.height = 30
$removehotfix.location = New-Object System.Drawing.Point(100,120)
$removehotfix.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)
$Hotfix_TextBox = New-Object system.Windows.Forms.TextBox
$Hotfix_TextBox.Text = ""
$Hotfix_TextBox.multiline = $false
$Hotfix_TextBox.width = 174
$Hotfix_TextBox.height = 20
$Hotfix_TextBox.location = New-Object System.Drawing.Point(12,235)
$Hotfix_TextBox.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)
<#
$Trimmed_TextBox = New-Object system.Windows.Forms.TextBox
#$Trimmed_TextBox.Text = "$str"
$Trimmed_TextBox.multiline = $false
$Trimmed_TextBox.width = 174
$Trimmed_TextBox.height = 20
$Trimmed_TextBox.location = New-Object System.Drawing.Point(12,265)
$Trimmed_TextBox.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)
#>
$Form.controls.AddRange(#($gethotfix,$removehotfix,$Hotfix_TextBox))
$gethotfix.Add_Click({ GetHotfix })
$removehotfix.Add_Click({ RemoveHotfix })
#region Logic
function GetHotfix {$Hotfix_TextBox.Text = Get-Hotfix -Computername $comp |
Select-Object -ExpandProperty 'HotFixID'|
Out-GridView -Title 'Installed Hotfixes' -PassThru }
#$Hotfix_TextBox.Text. Trim("K","B")
#$Hotfix_TextBox.Text = "$str"
function RemoveHotfix{
#$Trimmed_TextBox.Text = "$str"
$comp = "dus-xtdfed9r386"
#Uninstall-HotFix -ComputerName $comp
wusa -computername /$comp | /uninstall | /kb:$str
}
#endregion
[void]$Form.ShowDialog()

This turned out to be a fiasco. Even when I could get it to work there are many KBs that cannot be removed, as well as we had policies that would not allow us to remove many others. Just not worth the effort. Perhaps someone with less strengent policies in place can do something with this. Have Fun.

Related

How to move a device in AD to a different OU in a GUI

We have all of our Autopilot deployed devices in 1 OU and the techs have to move them to their own site's OU I have written a GUI to do this. they enter the device name and the location name. The location name is tha final ou the device will reside in. My GUI gets the OUs for the site and lists them in a Out-Gridview you click on the ou you want and click ok. it sends that to a textbox. then you click move. thats where I ger the error that the device cannot be found. I am sure I have some silly syntax wrong. Thanks in advance.
Add-Type -Name Window -Namespace Console -MemberDefinition '
[DllImport("Kernel32.dll")]
public static extern IntPtr GetConsoleWindow();
[DllImport("user32.dll")]
public static extern bool ShowWindow(IntPtr hWnd, Int32 nCmdShow);'
[Console.Window]::ShowWindow([Console.Window]::GetConsoleWindow(), 0)
<#
.NAME
AP Device Move
#>
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()
$Form = New-Object system.Windows.Forms.Form
$Form.ClientSize = New-Object System.Drawing.Point(400,400)
$Form.text = "Form"
$Form.TopMost = $false
$LBL_APDEVICE = New-Object system.Windows.Forms.Label
$LBL_APDEVICE.text = "Computer Name"
$LBL_APDEVICE.AutoSize = $true
$LBL_APDEVICE.width = 25
$LBL_APDEVICE.height = 10
$LBL_APDEVICE.location = New-Object System.Drawing.Point(0,2)
$LBL_APDEVICE.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)
$TBX_APDEVICE = New-Object system.Windows.Forms.TextBox
$TBX_APDEVICE.Text = ""
$TBX_APDEVICE.multiline = $false
$TBX_APDEVICE.width = 100
$TBX_APDEVICE.height = 20
$TBX_APDEVICE.location = New-Object System.Drawing.Point(6,37)
$TBX_APDEVICE.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)
$LBL_SITE = New-Object system.Windows.Forms.Label
$LBL_SITE.text = "Site Name"
$LBL_SITE.AutoSize = $true
$LBL_SITE.width = 25
$LBL_SITE.height = 10
$LBL_SITE.location = New-Object System.Drawing.Point(4,71)
$LBL_SITE.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)
$LOCATION = New-Object system.Windows.Forms.TextBox
$LOCATION.multiline = $false
$LOCATION.width = 100
$LOCATION.height = 20
$LOCATION.location = New-Object System.Drawing.Point(3,101)
$LOCATION.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)
$DESTINATION_OU = New-Object system.Windows.Forms.TextBox
$DESTINATION_OU.text = ""
$DESTINATION_OU.multiline = $false
$DESTINATION_OU.width = 100
$DESTINATION_OU.height = 20
$DESTINATION_OU.location = New-Object System.Drawing.Point(14,194)
$DESTINATION_OU.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)
$TARGET_OU = New-Object system.Windows.Forms.Label
$TARGET_OU.text = "Target OU"
$TARGET_OU.AutoSize = $true
$TARGET_OU.width = 25
$TARGET_OU.height = 10
$TARGET_OU.location = New-Object System.Drawing.Point(12,139)
$TARGET_OU.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)
$Get_OU = New-Object system.Windows.Forms.Button
$Get_OU.text = "Get OUs for Site"
$Get_OU.width = 104
$Get_OU.height = 30
$Get_OU.location = New-Object System.Drawing.Point(133,54)
$Get_OU.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)
$BTN_MOVE = New-Object system.Windows.Forms.Button
$BTN_MOVE.text = "Move Device"
$BTN_MOVE.width = 91
$BTN_MOVE.height = 30
$BTN_MOVE.location = New-Object System.Drawing.Point(34,246)
$BTN_MOVE.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)
$Form.controls.AddRange(#($LBL_APDEVICE,$TBX_APDEVICE,$LBL_SITE,$LOCATION,$DESTINATION_OU,$TARGET_OU,$Get_OU,$BTN_MOVE))
$Get_OU.Add_Click({ GetSiteOUs })
$BTN_MOVE.Add_Click({ doit })
#region Logic
function GetSiteOUs {
$DESTINATION_OU.Text = Get-ADOrganizationalUnit -Filter "Name -Like '*$($LOCATION.Text.Trim())*'" |
Select-Object -ExpandProperty 'Distinguishedname' |
Out-GridView -PassThru -Title "Select the OU"
}
function doit{
$DEVICE = $TBX_APDEVICE.TEXT
$DestOU = "OU=$DESTINATION_OU.text,OU=Computers,OU=World,OU=Disney,OU=Goofy,OU=Duck,OU=Donald,DC=Mickey,DC=Mouse,"
Move-ADObject –Identity "CN=$Device,OU=Autopilot,OU=Lucy,OU=linus,OU=Brown,OU=charlie,DC=Mickey,DC=Mouse," -TargetPath $DestOU
}
#endregion
[void]$Form.ShowDialog()
The answer was to adjust the doit function
function doit{
$DEVICE = $TBX_APDEVICE.TEXT
$DestOU = $DESTINATION_OU.text
Move-ADObject –Identity "CN=$Device,OU=Autopilot,OU=Lucy,OU=linus,OU=Brown,OU=charlie,DC=Mickey,DC=Mouse," -TargetPath $DestOU-TargetPath $DestOU
}

GUI for my auto installer keeps going blank

I am currently working on an auto installer for newly configured computers where I work. It has a GUI which allows you to choose which programs will be installed. When the file paths are correct the GUI is blank but when I purposefully mess up the file paths the checkboxes will pop back up.
Sorry if this seems like a very dumb question. I am extremely new to this and have gotten a lot of help from various different websites. This is basically me working off of another auto installer script that I found on this website.
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()
$Form = New-Object System.Windows.Forms.Form
$Form.Size = New-Object System.Drawing.Size(600,700)
$Form.text ="Software Installer"
############################################## Start group boxes
$groupBox = New-Object System.Windows.Forms.GroupBox
$groupBox.Location = New-Object System.Drawing.Size (10,20)
$groupBox.text = "Available Software to Install:"
$Form.Controls.Add($groupBox)
$Checkboxes += New-Object System.Windows.Forms.CheckBox
$Checkboxes = New-Object System.Drawing.Size (10,20)
$Button1 = New-Object System.Windows.Forms.Button
$Button1.text = "Install"
$Button1.width = 100
$Button1.height = 30
$Button1.location = New-Object System.Drawing.Point(245,585)
$Button1.Font = 'Microsoft Sans Serif,10'
$apps = [PSCustomObject]#{
Name = ''
Path = ''
PreTransfer = ''
}
$apps = Import-Csv -Path C:\Users\Zach\Desktop\Installers\appslist.csv
$groupBox.Controls.Add($Button1)
$Checkboxes = #()
$y = 20
foreach ($a in $apps)
{
$Checkbox = New-Object System.Windows.Forms.CheckBox
$Checkbox.name = $a.Name
$Checkbox.Text = $a.Name
$Checkbox.Location = New-Object System.Drawing.Size(10,$y)
$y += 30
$groupBox.Controls.Add($Checkbox)
$Checkboxes += $Checkbox
}
$groupbox.size = New-Object System.Drawing.Size(564,(624*$checkboxes.Count))
#to look at each box
$Button1.Add_Click({
foreach ($i in $Checkboxes){
if ($i.checked -eq $true) {
Start-Process $i.AccessibleDescription
}
}
})
$form.ShowDialog()| Out-Null

Copy listview1 to listview2

I'm trying to copy the checked item in ListADGroup and copy to ListADGroup2. ListADGroup updates with all the groups but when I try adding them to ListADGroup2 it copies the right amount checkboxes but they are empty. Im not sure what is missing from the button command to copy the data properly.
Add-Type -AssemblyName "System.Windows.Forms"
Add-Type -AssemblyName "System.Drawing"
Add-Type -AssemblyName PresentationFramework
Clear-Host
#== Create a New Form ==#
$TSTAPP=New-Object System.Windows.Forms.Form
$TSTAPP.topmost=$true
$TSTAPP.Text="Test App"
$TSTAPP.Location.x=750
$TSTAPP.Location.Y=330
$TSTAPP.Size=New-Object System.Drawing.Size(750,330)
#== Now Lock the form so it cannot be re-sized ==#
$TSTAPP.MaximumSize=New-Object System.Drawing.Size(750,330)
$TSTAPP.MinimumSize=New-Object System.Drawing.Size(750,330)
#== Group List Label ==#
$GroupL = New-Object System.Windows.Forms.Label
$GroupL.Text = "Select Group:"
$GroupL.Location = New-Object System.Drawing.Point(4,5)
$GroupL.AutoSize = $true
$TSTAPP.Controls.Add($GroupL)
#== AD Users Listbox ==#
$ListADGroup = New-Object system.Windows.Forms.Listview
$ListADGroup.Width = 356
$ListADGroup.height = 220
$ListADGroup.location = New-Object System.Drawing.Point(4,22)
#$ListADGroup.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)
$ListADGroup.CheckBoxes = $true
$ListADGroup.Name = "Main"
$ListADGroup.AutoArrange = $true
$ListADGroup.GridLines = $true
$ListADGroup.MultiSelect = $false
$ListADGroup.View = "Details"
$ListADGroup.AutoSize = $true
#$ListADGroup.Columns[0].
$ListADGroup.Columns.Add("Groups")
$AllADGroups = Get-ADGroup -filter * -SearchBase 'OU=Accounts,DC=domain,DC=internal' -SearchScope subtree -Properties Name | Sort-Object Name | foreach{[void]$ListADGroup.Items.Add($_.name)}
$TSTAPP.controls.add($ListADGroup)
#== AD Users Listbox ==#
$ListADGroup2 = New-Object system.Windows.Forms.Listview
$ListADGroup2.Width = 356
$ListADGroup2.height = 220
$ListADGroup2.location = New-Object System.Drawing.Point(370,22)
#$ListADGroup2.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)
$ListADGroup2.CheckBoxes = $true
$ListADGroup2.Name = "Main"
$ListADGroup2.AutoArrange = $true
$ListADGroup2.GridLines = $true
$ListADGroup2.MultiSelect = $false
$ListADGroup2.View = "Details"
$ListADGroup2.AutoSize = $true
#$ListADGroup2.Columns.Width = 100
$ListADGroup2.Columns.Add("Groups2")
$TSTAPP.controls.add($ListADGroup2)
#== Add Button ==#
$AddGroup = New-Object system.Windows.Forms.Button
$AddGroup.text = "Add"
$AddGroup.width = 100
$AddGroup.height = 30
$AddGroup.location = New-Object System.Drawing.Point(265,249)
$AddGroup.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)
$TSTAPP.controls.add($AddGroup)
$AddGroup.Add_Click({
$itm = $ListADGroup.CheckedItems
foreach ($items in $itm){
$ListADGroup2.Items.Add($items.name)
}
})
$TSTAPP.ShowDialog()
If you try to debug using ISE or Visual Code you will see that the property containing the name is called Text
So replace :
$ListADGroup2.Items.Add($items.name)
by
$ListADGroup2.Items.Add($items.Text)

Run GUI powershell script by right clicking on a file

I have built a powershell script using the GUI .net framework that provides the user with a graphical interface to add alternate data streams (ADS) to files on a NTFS file system.
Below is the code I wrote for the powershell script:
<#
This script is a GUI featured way to add extended attributes to files
#>
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()
#region begin GUI{
$Form = New-Object system.Windows.Forms.Form
$Form.ClientSize = '600,600'
$Form.text = "Add Extended Attributes"
$Form.TopMost = $false
# Add Extended Attributes Label
$mainLabel = New-Object system.Windows.Forms.Label
$mainLabel.text = "Add Extended Attributes"
$mainLabel.AutoSize = $true
$mainLabel.width = 25
$mainLabel.height = 10
$mainLabel.location = New-Object System.Drawing.Point(180,10)
$mainLabel.Font = 'Microsoft Sans Serif,18'
# text box for entering file path
$filePath = New-Object system.Windows.Forms.TextBox
$filePath.multiline = $false
$filePath.width = 300
$filePath.height = 20
$filePath.location = New-Object System.Drawing.Point(200,80)
$filePath.Font = 'Microsoft Sans Serif,10'
# label for the file path text box "File Path: "
$FilePathLabel = New-Object system.Windows.Forms.Label
$FilePathLabel.text = "File Path: "
$FilePathLabel.AutoSize = $true
$FilePathLabel.width = 25
$FilePathLabel.height = 10
$FilePathLabel.location = New-Object System.Drawing.Point(80,85)
$FilePathLabel.Font = 'Microsoft Sans Serif,10'
# Attributes Label
$idLabel = New-Object system.Windows.Forms.Label
$idLabel.text = "Attributes"
$idLabel.AutoSize = $true
$idLabel.width = 25
$idLabel.height = 10
$idLabel.location = New-Object System.Drawing.Point(80,150)
$idLabel.Font = 'Microsoft Sans Serif,12'
# Values Label
$valueLabel = New-Object system.Windows.Forms.Label
$valueLabel.text = "Value"
$valueLabel.AutoSize = $true
$valueLabel.width = 25
$valueLabel.height = 10
$valueLabel.location = New-Object System.Drawing.Point(300,150)
$valueLabel.Font = 'Microsoft Sans Serif,12'
# Checkbox for ID attribute
$fileId = New-Object System.Windows.Forms.CheckBox
$fileId.text = "Id"
$fileId.AutoSize = $true
$fileId.width = 104
$fileId.height = 20
$fileId.location = New-Object System.Drawing.Point(100,200)
$fileId.Font = 'Microsoft Sans Serif,10'
# Label for the ID checkbox
$idValue = New-Object system.Windows.Forms.TextBox
$idValue.multiline = $false
$idValue.width = 300
$idValue.height = 20
$idValue.location = New-Object System.Drawing.Point(202,200)
$idValue.Font = 'Microsoft Sans Serif,10'
# Checkbox for Description attribute
$description = New-Object System.Windows.Forms.CheckBox
$description.text = "Description"
$description.AutoSize = $true
$description.width = 104
$description.height = 20
$description.location = New-Object System.Drawing.Point(100,250)
$description.Font = 'Microsoft Sans Serif,10'
# Label for the Description checkbox
$descriptionValue = New-Object system.Windows.Forms.TextBox
$descriptionValue.multiline = $false
$descriptionValue.width = 300
$descriptionValue.height = 20
$descriptionValue.location = New-Object System.Drawing.Point(202,250)
$descriptionValue.Font = 'Microsoft Sans Serif,10'
# Checkbox for Type attribute
$type = New-Object System.Windows.Forms.CheckBox
$type.text = "Type"
$type.AutoSize = $true
$type.width = 104
$type.height = 20
$type.location = New-Object System.Drawing.Point(100,300)
$type.Font = 'Microsoft Sans Serif,10'
# Label for the type checkbox
$typeValue = New-Object system.Windows.Forms.TextBox
$typeValue.multiline = $false
$typeValue.width = 300
$typeValue.height = 20
$typeValue.location = New-Object System.Drawing.Point(202,300)
$typeValue.Font = 'Microsoft Sans Serif,10'
# Checkbox for silo attribute
$silo = New-Object System.Windows.Forms.CheckBox
$silo.text = "Silo"
$silo.AutoSize = $true
$silo.width = 104
$silo.height = 20
$silo.location = New-Object System.Drawing.Point(100,350)
$silo.Font = 'Microsoft Sans Serif,10'
# Label for the silo checkbox
$siloValue = New-Object system.Windows.Forms.TextBox
$siloValue.multiline = $false
$siloValue.width = 300
$siloValue.height = 20
$siloValue.location = New-Object System.Drawing.Point(202,350)
$siloValue.Font = 'Microsoft Sans Serif,10'
# submitt button
$button = New-Object System.Windows.Forms.Button
$button.text = "Submit"
$button.AutoSize = $true
$button.location = New-Object System.Drawing.Point(250,500)
$button.Font = 'Microsoft Sans Serif,10'
$Form.controls.AddRange(#($mainLabel, $fileId,$filePath,$idLabel,$valueLabel,$FilePathLabel,$idValue,$descriptionValue,$description, $type, $typeValue, $silo, $siloValue, $button))
#region gui events {
function SubmitForm(){
if($fileId.checked -eq $true){
sc -path $filePath.Text -stream $fileId.text -value $idValue.Text
}
if($description.checked -eq $true){
sc -path $filePath.Text -stream $description.text -value $descriptionValue.text
}
if($type.checked -eq $true){
sc -path $filePath.Text -stream $type.text -value $typeValue.text
}
if($silo.checked -eq $true){
sc -path $filePath.Text -stream $silo.text -value $siloValue.text
}
[System.Windows.Forms.MessageBox]::Show("Successfully Added Attributes")
}
#Add Button event
$Button.Add_Click({SubmitForm})
#endregion events }
#endregion GUI }
# logic here
[void]$Form.ShowDialog()
Currently the user would have to actually run the powershell script from the root folder and then add the file path to the text input the GUI, along with the rest of the extended attributes. An example of what I currently have is below:
I would like the user to be able to right click on any file and have the form come up with the path of the file that was right clicked in windows explorer, instead of the path being manually entered by the individual making the updates to the alternate data streams. Something similar as how you would extract a file using zip7 (example below).
Can someone tell me if this is even possible? Should I be trying to tackle this problem in another language than using powershell?
You can do all this with Powershell.
First you want to create a script from your code and make input parameter for chosen folder. Like so:
param($FileName)
<#
This script is a GUI featured way to add extended attributes to files
#>
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()
#region begin GUI{
$Form = New-Object system.Windows.Forms.Form
$Form.ClientSize = '600,600'
$Form.text = "Add Extended Attributes"
$Form.TopMost = $false
# Add Extended Attributes Label
$mainLabel = New-Object system.Windows.Forms.Label
$mainLabel.text = "Add Extended Attributes"
$mainLabel.AutoSize = $true
$mainLabel.width = 25
$mainLabel.height = 10
$mainLabel.location = New-Object System.Drawing.Point(180,10)
$mainLabel.Font = 'Microsoft Sans Serif,18'
# text box for entering file path
$filePath = New-Object system.Windows.Forms.TextBox
$filePath.multiline = $false
$filePath.width = 300
$filePath.height = 20
$filePath.location = New-Object System.Drawing.Point(200,80)
$filePath.Font = 'Microsoft Sans Serif,10'
$filePath.Text = $FileName
# label for the file path text box "File Path: "
$FilePathLabel = New-Object system.Windows.Forms.Label
$FilePathLabel.text = "File Path: "
$FilePathLabel.AutoSize = $true
$FilePathLabel.width = 25
$FilePathLabel.height = 10
$FilePathLabel.location = New-Object System.Drawing.Point(80,85)
$FilePathLabel.Font = 'Microsoft Sans Serif,10'
# Attributes Label
$idLabel = New-Object system.Windows.Forms.Label
$idLabel.text = "Attributes"
$idLabel.AutoSize = $true
$idLabel.width = 25
$idLabel.height = 10
$idLabel.location = New-Object System.Drawing.Point(80,150)
$idLabel.Font = 'Microsoft Sans Serif,12'
# Values Label
$valueLabel = New-Object system.Windows.Forms.Label
$valueLabel.text = "Value"
$valueLabel.AutoSize = $true
$valueLabel.width = 25
$valueLabel.height = 10
$valueLabel.location = New-Object System.Drawing.Point(300,150)
$valueLabel.Font = 'Microsoft Sans Serif,12'
# Checkbox for ID attribute
$fileId = New-Object System.Windows.Forms.CheckBox
$fileId.text = "Id"
$fileId.AutoSize = $true
$fileId.width = 104
$fileId.height = 20
$fileId.location = New-Object System.Drawing.Point(100,200)
$fileId.Font = 'Microsoft Sans Serif,10'
# Label for the ID checkbox
$idValue = New-Object system.Windows.Forms.TextBox
$idValue.multiline = $false
$idValue.width = 300
$idValue.height = 20
$idValue.location = New-Object System.Drawing.Point(202,200)
$idValue.Font = 'Microsoft Sans Serif,10'
# Checkbox for Description attribute
$description = New-Object System.Windows.Forms.CheckBox
$description.text = "Description"
$description.AutoSize = $true
$description.width = 104
$description.height = 20
$description.location = New-Object System.Drawing.Point(100,250)
$description.Font = 'Microsoft Sans Serif,10'
# Label for the Description checkbox
$descriptionValue = New-Object system.Windows.Forms.TextBox
$descriptionValue.multiline = $false
$descriptionValue.width = 300
$descriptionValue.height = 20
$descriptionValue.location = New-Object System.Drawing.Point(202,250)
$descriptionValue.Font = 'Microsoft Sans Serif,10'
# Checkbox for Type attribute
$type = New-Object System.Windows.Forms.CheckBox
$type.text = "Type"
$type.AutoSize = $true
$type.width = 104
$type.height = 20
$type.location = New-Object System.Drawing.Point(100,300)
$type.Font = 'Microsoft Sans Serif,10'
# Label for the type checkbox
$typeValue = New-Object system.Windows.Forms.TextBox
$typeValue.multiline = $false
$typeValue.width = 300
$typeValue.height = 20
$typeValue.location = New-Object System.Drawing.Point(202,300)
$typeValue.Font = 'Microsoft Sans Serif,10'
# Checkbox for silo attribute
$silo = New-Object System.Windows.Forms.CheckBox
$silo.text = "Silo"
$silo.AutoSize = $true
$silo.width = 104
$silo.height = 20
$silo.location = New-Object System.Drawing.Point(100,350)
$silo.Font = 'Microsoft Sans Serif,10'
# Label for the silo checkbox
$siloValue = New-Object system.Windows.Forms.TextBox
$siloValue.multiline = $false
$siloValue.width = 300
$siloValue.height = 20
$siloValue.location = New-Object System.Drawing.Point(202,350)
$siloValue.Font = 'Microsoft Sans Serif,10'
# submitt button
$button = New-Object System.Windows.Forms.Button
$button.text = "Submit"
$button.AutoSize = $true
$button.location = New-Object System.Drawing.Point(250,500)
$button.Font = 'Microsoft Sans Serif,10'
$Form.controls.AddRange(#($mainLabel, $fileId,$filePath,$idLabel,$valueLabel,$FilePathLabel,$idValue,$descriptionValue,$description, $type, $typeValue, $silo, $siloValue, $button))
#region gui events {
function SubmitForm(){
if($fileId.checked -eq $true){
sc -path $filePath.Text -stream $fileId.text -value $idValue.Text
}
if($description.checked -eq $true){
sc -path $filePath.Text -stream $description.text -value $descriptionValue.text
}
if($type.checked -eq $true){
sc -path $filePath.Text -stream $type.text -value $typeValue.text
}
if($silo.checked -eq $true){
sc -path $filePath.Text -stream $silo.text -value $siloValue.text
}
[System.Windows.Forms.MessageBox]::Show("Successfully Added Attributes")
}
#Add Button event
$Button.Add_Click({SubmitForm})
#endregion events }
#endregion GUI }
# logic here
[void]$Form.ShowDialog()
Next you would need to create registry reference for context menu item and powershell script according to it. Like so:
New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT
New-Item HKCR:\directory\shell\PowerShellScript
New-Item HKCR:\directory\shell\PowerShellScript\command
Set-ItemProperty 'HKCR:\directory\shell\PowerShellScript\command' -Name '(default)' -Value 'Powershell -WindowStyle Hidden -ExecutionPolicy Bypass -NoExit -File "C:\Test.ps1" "%L"'
Context menu item:
Chosen directory passed to script's input parameter:

Below is the code where I am trying to get the operating system name for multiple system

If I give one system, it is working. If I give multiple systems it is showing RPC error. If I give my system twice, then it also is not working. Any idea?
Function Get_Systeminfo() {
$TxtBox.Visible = $false
$ColName = #{Expression={$_.CSNAME};Label="SERVER NAME"},
#{Expression={$_.Caption};Label="OS NAME"; width =25},
#{Expression={$_.OSArchitecture};Label="OS TYPE"}
$ResBox = New-Object System.Windows.Forms.RichTextBox
$ResBox.Location = New-Object System.Drawing.Size(50,50)
$ResBox.Size = New-Object System.Drawing.Size(480, 280)
$ResBox.Font = "lucida console"
$objForm.Controls.Add($ResBox)
$ResBox.Text = foreach ($list in $TxtBox.Text) {
Get-WmiObject Win32_OperatingSystem -ComputerName $list |
Format-Table $ColName -Auto | Out-String
}
}
$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = "SystemInfo"
$objForm.Size = New-Object System.Drawing.Size(600,400)
$objForm.StartPosition = "CenterScreen"
$TxtBox = New-Object System.Windows.Forms.TextBox
$TxtBox.Location = New-Object System.Drawing.Size(20, 20)
$TxtBox.Size = New-Object System.Drawing.Size(300,100)
$TxtBox.Multiline = $true
$objForm.Controls.Add($TxtBox)
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(20,340)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "OK"
$objForm.Controls.Add($OKButton)
$OKButton.Add_Click({Get_Systeminfo})
$objForm.ShowDialog()
Change
$ResBox.Text = foreach ($list in $TxtBox.Text){
to
$ResBox.Text = foreach ($list in $TxtBox.Lines){
and it will genereate output, IF you are giving a single name per line.