0

I want to run a PowerShell command inside itself, after opened the PowerShell console. For example as we create desktop shortcut by DOS command line by CMD. Similarly opened the PowerShell command line console, another PowerShell cmdlet would execute inside that.

Ex: PS C:> Test-Connection -ComputerName 8.8.8.8 -Count 1000

I want to run a PowerShell command inside itself, after opened the PowerShell console. For example as we create desktop shortcut by DOS command line by CMD. Similarly opened the PowerShell command line console, another PowerShell cmdlet would execute inside that.

Ex: C:> PowerShell && Test-Connection -ComputerName 8.8.8.8 -Count 1000

PS C:> Test-Connection -ComputerName 8.8.8.8 -Count 1000

2
  • Please format your post properly. Commented Nov 23, 2022 at 0:36
  • As an aside: DOS , with its command.com console shell (command processor), was the foundation of a long-obsolete line of Windows versions ending with Windows ME. The current line of Windows operating systems, dating back to Windows NT, uses cmd.exe as its console shell; while its batch language is compatible with command.com's, its technological foundation is different. In other words: DOS plays no part in modern Windows systems, and discussing the latter in terms of DOS is both incorrect and confusing. Commented Nov 23, 2022 at 3:25

1 Answer 1

1

powershell.exe, the Windows PowerShell CLI, allows you to:

  • pass a command to execute via the (positionally implied) -Command parameter.

  • keep the resulting session open with -NoExit.

Therefore:

PowerShell -NoExit -Command "Test-Connection -ComputerName 8.8.8.8 -Count 1000"
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you it is really working what I was expecting.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.