I'm Trying to use Powershell to make a choices to Enable/Disable Net Adapter "Ethernet" I Coded This
$caption = "Choose Action";
$message = "What do you want to do?";
$enab = start-process powershell -verb runas -argument D:\ena.ps1
$disa = start-process powershell -verb runas -argument D:\dis.ps1
$choices = [System.Management.Automation.Host.ChoiceDescription[]]($enab,$disa);
$answer = $host.ui.PromptForChoice($caption,$message,$choices,0)
switch ($answer){
0 {"You entered Enable"; break}
1 {"You entered Disable"; break}
}
Error :
Object cannot be stored in an array of this type. At D:\Untitled4.ps1:5 char:1 + $choices = System.Management.Automation.Host.ChoiceDescription[]; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OperationStopped: (:) [], InvalidCastException + FullyQualifiedErrorId : System.InvalidCastException
Exception calling "PromptForChoice" with "4" argument(s): "Value cannot be null. Parameter name: choices" At D:\Untitled4.ps1:6 char:1 + $answer = $host.ui.PromptForChoice($caption,$message,$choices,0) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : ArgumentNullException
I have failed before this to do On/Off script using powershell (if the net adapter is enable then disable it and vice versa. is there any way to do this?