question

PowerShelly-7438 avatar image
0 Votes"
PowerShelly-7438 asked RichMatheisen-8856 commented

execute powershell script from powershell cript

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered

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?

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

PowerShelly-7438 avatar image
0 Votes"
PowerShelly-7438 answered RichMatheisen-8856 commented

[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.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

You didn't provide code for AddName.ps1, so I made a little stub to test with:

 param(
     $Name,
     $middlename,
     $LastName,
     $age
 )
 Write-Host "ADDNAME.PS1 -Name $Name -MiddleName $middlename -LastName $lastname -Age $age" -ForegroundColor Yellow

It worked as expected.

0 Votes 0 ·