is it possible to have a window to insert data mad

2020-03-26 07:41发布

when I announce my changes on a server i always use my xml file which is pretty big and I search for the right place of my content like servername , time , data and my name they are at a not so comfortable postion and I want to automate this a bit. Is it possible to have a "graphical interface" made by powershell like my paint work shows ? schema

And than I insert my data into the 4 colums which are then placed at the right position.

If it is possible, can someone give me the name of the cmdlet or whatever it is ? i will figure out how to use it then..

1条回答
我只想做你的唯一
2楼-- · 2020-03-26 08:11

TechNet has a useful guide to create a simple input box with powershell using Windows Forms. Essentially you use New-Object to create form objects of the System.Windows.Forms Namespace and set object properties to your liking before you make the form visible. The form object is your "base" object, and from there you can add labels, buttons, listboxes, and other handy form elements like so:

# The Base Form
$myForm = New-Object System.Windows.Forms.Form 
$myForm.Text = "My Form Title"
$myForm.Size = New-Object System.Drawing.Size($width, $height) 
$myForm.StartPosition = "CenterScreen"

# Add a Form Component
$myFormComponent = New-Object System.Windows.Forms.Button
... Set component properties ...
$myForm.Controls.Add($myFormComponent)

.. Add additional components to build a complete form ...

# Show Form
$myForm.Topmost = $True
$myForm.Add_Shown({$myForm.Activate()})
[void] $myForm.ShowDialog()

You'll want to do that once you've finished modifying those components. Following any similar online guide for creating a windows form via powershell should be enough to get you started accepting input.

Once you've accepted input, you can store each type "time, data, server, and name" in different variables and operate on your XML file as needed.


In response to the comment:

Each component you add should be isolated to itself and you can get/set whatever content you want there with variables. Use the text property of the TextBox component. So for example:

$myTextBox = New-Object System.Windows.Forms.TextBox 

// Assign content to a string.
$myTextBox.Text = "Text Goes Here"

// Assign content to an existing variable.
$myTextBox.Text = $myString

// Store content in a variable.
$myString = $myTextBox.Text

For two textfields, you just make another unique textbox as demonstrated above. Remember, your unique components are isolated in scope.

查看更多
登录 后发表回答