Works in PowerShell not in PSStudio

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 7 years and 2 months 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
obrienc
Posts: 59
Last visit: Wed Apr 20, 2022 5:43 am

Works in PowerShell not in PSStudio

Post by obrienc »

This works in PowerShell when I add the IP addresses as strings directly but when I try to call them from a Textbox it fails. I've tried changing the syntax without success.
  1. Invoke-VMScript -VM $vm.Name -ScriptText "netsh interface ipv4 set address ""Ethernet"" static 10.0.99.249 255.255.255.0 10.0.99.1" -HostUser root -HostPassword '12345678' -GuestUser xxxx -GuestPassword xxxx
  1. Invoke-VMScript -VM $vm.Name -ScriptText "netsh interface ipv4 set address ""Ethernet"" static $textbox13.Text $textbox22.Text $textbox21.Text" -HostUser root -HostPassword '12345678' -GuestUser xxxx -GuestPassword xxxx
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Works in PowerShell not in PSStudio

Post by jvierra »

What is "Invoke-VMScript". Did you write it or is it for VMWare?
User avatar
obrienc
Posts: 59
Last visit: Wed Apr 20, 2022 5:43 am

Re: Works in PowerShell not in PSStudio

Post by obrienc »

It's a vmware script that allows you to change names, ips, etc..
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Works in PowerShell not in PSStudio

Post by jvierra »

Is it a multiline textbox?

Why would you use netsh commands when you can use WMI?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Works in PowerShell not in PSStudio

Post by jvierra »

This will fix at least one obvious issue.
  1. "netsh interface ipv4 set address ""Ethernet"" static $($textbox13.Text) $($textbox22.Text) $($textbox21.Text)"
User avatar
obrienc
Posts: 59
Last visit: Wed Apr 20, 2022 5:43 am

Re: Works in PowerShell not in PSStudio

Post by obrienc »

I actually just bought WMI Explorer and am looking for How To's. No clue how to get values but that's for another post, thread.

Thanks for the carrot.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Works in PowerShell not in PSStudio

Post by jvierra »

  1. $adapt = Get-WmiObject Win32_NetworkAdapterConfiguration -Filter "Caption LIKE '%Ethernet%'"
  2. $adapt.EnableStatic($IPAddess,$SubnetMask)
help Get-WmiObject -Full
DevinL
Posts: 1098
Last visit: Tue Jun 06, 2017 9:15 am

Re: Works in PowerShell not in PSStudio

Post by DevinL »

With WMI Explorer, you can select a Namespace, a class, and then some properties and use the Query button in the ribbon to get the values on that machine and you can also use the keyboard shortcut of Ctrl + Q if you'd like.

If you look in the ribbon under Tools you'll see the button to launch the manual which has an example of how to use it with some screenshots:
View_Manual.png
View_Manual.png (18.66 KiB) Viewed 2580 times
DevinL
SAPIEN Technologies, Inc.
This topic is 7 years and 2 months 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