execute powershell script from powershell cript

PowerShelly 61 Reputation points
2022-05-03T16:40:55.36+00:00

So I have Questionair.PS1 to run Addname.PS1 at the end. Help accomplish this please.

add-lastname -AssemblyName microsoft.visualbasic
$name = [Microsoft.VisualBasic.Interaction]::InputBox('Your first name','Your first name')
$middlename = [Microsoft.VisualBasic.Interaction]::InputBox('Your middle name','Your middle name')
$lastname = [Microsoft.VisualBasic.Interaction]::InputBox('Your last name','Your last name')
$age = [Microsoft.VisualBasic.Interaction]::InputBox('Your age','Your age')

$confirm = [System.Windows.Forms.MessageBox]::Show("d:\members\Addname.ps1 –Name $name –middlename $middlename  –LastName $lastname -age $age",'Command to run')
if($confirm -eq 'OK')
{
i have tried adding several different lines here but doesn't work.
i want to run this line from above:
d:\members\Addname.ps1 –Name $name –middlename $middlename  –LastName $lastname -age $age",'Command to run')
 }
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,364 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Rich Matheisen 44,776 Reputation points
    2022-05-03T18:32:12.763+00:00

    The diagnostic "but doesn't work" is not at all helpful! What does it do? What doesn't it do? Are there errors displayed? What are they?

    I've edited your script to correct the "add-lastname' to 'Add-Type', replaced the multiple occurrences of the Unicode "en-dash" where a hyphen was expected, and to properly terminate the line that should run the other script.

    #add-lastname -AssemblyName microsoft.visualbasic   # What the heck is "add-lastname"????
    Add-Type -AssemblyName microsoft.visualbasic
    $name = [Microsoft.VisualBasic.Interaction]::InputBox('Your first name', 'Your first name')
    $middlename = [Microsoft.VisualBasic.Interaction]::InputBox('Your middle name', 'Your middle name')
    $lastname = [Microsoft.VisualBasic.Interaction]::InputBox('Your last name', 'Your last name')
    $age = [Microsoft.VisualBasic.Interaction]::InputBox('Your age', 'Your age')
    
    $confirm = [System.Windows.Forms.MessageBox]::Show("d:\members\Addname.ps1 -Name $name -middlename $middlename  -LastName $lastname -age $age", 'Command to run')
    if ($confirm -eq 'OK') {
        #i have tried adding several different lines here but doesn't work.
        #i want to run this line from above:
        d:\members\Addname.ps1 -Name $name -middlename $middlename -LastName $lastname -age $age    # Command to run
    }
    

    Does this work? If not, HOW does it fail?

    0 comments No comments

  2. PowerShelly 61 Reputation points
    2022-05-03T18:54:13.453+00:00

    [what the heck is that?] lol, i was asking the same thing. I accidently delete -type and added -lastname, wrong spot at the wrong time for cursor.

    My issue was line 12. You had what i had except the #command to run, not sure how that got in there also.
    it didn't work but wil provide on the next failure.