Executing a PowerShell Script | CompTIA A+ Core 2 Exam

Which File Types to Open for PowerShell Scripts

Question

Which of the following file types should be opened when executing a PowerShell script?

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D. E.

D.

The correct answer is D. .ps1.

PowerShell is a command-line shell and scripting language developed by Microsoft for task automation and configuration management. PowerShell scripts are written in a file with a .ps1 file extension. To run a PowerShell script, you need to open a PowerShell console and then run the script.

Let's go through each of the options and understand why they are incorrect:

A. .bat - .bat is the file extension for batch files used in Windows. Batch files are scripts written for the Windows command prompt and not for PowerShell.

B. .vbs - .vbs is the file extension for VBScript files. VBScript is a scripting language developed by Microsoft and is used for automation tasks in Windows. It is not used in PowerShell.

C. .sh - .sh is the file extension for shell scripts used in Unix and Unix-like operating systems. It is not used in PowerShell.

D. .ps1 - .ps1 is the correct file extension for PowerShell scripts. PowerShell scripts are written in a file with a .ps1 extension.

E. .psd - .psd is the file extension for Adobe Photoshop files. It is not used in PowerShell.

In conclusion, when executing a PowerShell script, you should open a PowerShell console and then run the script with the correct file extension, which is .ps1.