Converting .Text to System.Byte

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 6 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
TechGy
Posts: 3
Last visit: Wed Jun 20, 2018 11:07 am

Converting .Text to System.Byte

Post by TechGy »

I'm new to PSStudio and hoping that someone can help me with a problem. I have a GUI designed and one of the things it does it use masked textboxes to gather IP Address and Subnet Mask to set an IP using the Set-NetIPAddress module.

When I get use the code below I get the error:
  1. ERROR: Set-NetIPAddress : Cannot process argument transformation on parameter 'PrefixLength'. Cannot convert value "Subnet
  2. ERROR: Mask:" to type "System.Byte". Error: "Input string was not in a correct format."

My code that runs on button click event:
  1. Set-NetIPAddress -InterfaceAlias $comboboxNetworkInterface.SelectedItem -IPv4Address $maskedtextboxIPAddress.Text -PrefixLength $labelSubnetMask.Text -DefaultGateway $maskedtextboxDefaultGateway.Text

Can someone help me get the Subnet Mask into the System.Byte format the command wants?
User avatar
TechGy
Posts: 3
Last visit: Wed Jun 20, 2018 11:07 am

Re: Converting .Text to System.Byte

Post by TechGy »

Completely overlooked that I was using $labelSubnetMask.Text instead of $maskedtextboxSubnetMask.Text. Problem solved!
cody m

Re: Converting .Text to System.Byte

Post by cody m »

Fantastic! Glad to hear it.
This topic is 6 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked