PowerShell Interview Questions and Answers

PowerShell Interview Questions and Answers

Last updated on 19th Oct 2020, Blog, Interview Question

About author

Sivaraman ((Associate Manager - Powershell ) )

High level Domain Expert in TOP MNCs with 8+ Years of Experience. Also, Handled Around 20+ Projects and Shared his Knowledge by Writing these Blogs for us.

(5.0) | 12547 Ratings 2323

Ready to face interview for PowerShell? Do not worry, we are here to help you with job interview preparation. If you are preparing PowerShell interview and not sure which questions are likely asked in interview, we suggest you to go through ACTE Wisdomjobs interview questions and answers page to crack your job interview. PowerShell is task-based command-line shell and scripting language built on the .NET Framework. PowerShell is mainly used for management, administration and automation. It helps to rapidly automate tasks that manage operating systems (Linux, macOS, and Windows) and processes. Strong technical skills are needed as there is huge competition. Below is the list of frequently asked PowerShell interview questions and answers which gets you ready to face the interviews.

1. What is PowerShell?

Ans:

PowerShell is an extendable command-line shell which is designed especially for the system administrators and power-users for managing the operating system and processors.

It is a scripting environment which is built on the .NET Framework.

It is platform-independent and open-source.

2. What are the features of PowerShell?

Ans:

Following are the different features or characteristics of PowerShell:

  • The main feature of PowerShell is that it is based on an object, not on text.
  • The PowerShell commands are customizable.
  • PowerShell remoting is the feature which enables the execution of cmdlets on a remote system that helps the developers for managing the set of remote computers from one single machine.
  • Scripting debugging is also an essential feature of PowerShell, which is used to examine the commands, scripts, functions, and expressions at the time of PowerShell execution.

3. How to launch the PowerShell in the Windows operating system?

Ans:

PowerShell is already installed in all the latest versions of Windows. We need to start PowerShell by the following given steps:

  • Search for the Windows PowerShell. Select and Click.
  • PowerShell Window will open.

4. What is a pipeline in PowerShell?

Ans:

A PowerShell pipeline is the series of statements which are connected by the pipe ‘|’ operator. In a command, each pipeline operator is used to send the output or result of the preceding command to the next command.

5.What is the Execution policy in PowerShell?

Ans:

Execution policy in PowerShell is a concept which controls the conditions under which PowerShell loads the configuration files and execute scripts.

6. Explain the types of Execution policy?

Ans:

Followings are the six types of execution policy in PowerShell:

  • AllSigned
  • RemoteSigned
  • Restricted
  • Undefined
  • Bypass
  • Unrestricted

AllSigned

It is an execution policy which executes only those scripts that are signed by a trusted publisher with a digital signature.

RemoteSigned

PowerShell will execute any script which is written on a local computer. But the script which is downloaded from the internet must require the digital signature from the trusted publisher.

Restricted

This type of execution policy does not allow to execute any script but permits the individual commands. This policy is available for the Windows client computer by default.

Undefined

No execution policy is set or defined in the current scope.

Bypass

It is mainly designed for those configurations in which a PowerShell script is built into a larger application. In this type of policy, no warnings and no prompts are provided.

Unrestricted

This policy is the default for Non-Window computers. This policy executes those scripts which are unsigned.

7.What is Try, Catch, and finally in PowerShell?

Ans:

  • Try: It is a part of a script where we want the PowerShell to monitor the errors. If an error occurs in this block, the automatic variable $Error stores the error. And then, the PowerShell searches the Catch block to handle the error.
  • Catch: In a PowerShell script, it is a part which handles the errors generated by the Try block.
  • Finally: In a PowerShell script, it is a part which releases the resource that no longer needed by a script.

8.What are the differences between CIM and WMI?

Ans:

Following table describes the difference between CIM and WMI:

CMIWMI
CIM stands for Common Information Model.WMI stands for Windows Management Instrumentation.
It was developed by a company Called DMTF.It was developed by Microsoft as well.
It can work on any platform.It works only for windows.

9. What is the function of the $input variable?

Ans:

The function of the $input variable enables the PowerShell functions for accessing the data which is coming from the pipeline.

Subscribe For Free Demo

Error: Contact form not found.

10. What is the difference between PowerShell and CMD?

Ans:

Following are the differences between PowerShell and CMD:

PowerShellCommand Prompt (CMD)
1. It is a task-based command-line shell and associated scripting language which is based on the .NET framework.1. It is the default command-line interpreter for the Microsoft Windows Operating System.
2. It can interpret both the commands of a batch and PowerShell.2. It can interpret only the commands of a batch.
3. It controls and automates the Windows operating system and applications on a Windows server.3. It executes the commands which are specified on the console to debug the problem.
4. The output generated by the PowerShell is not just a stream of characters (text) but a collection of objects.4. The output generated by the command prompt is just a stream of characters (text).
5. It is both a shell and scripting environment which supports the creation of large files for managing the windows operating system.5. It is just a shell environment, which allows a user to do only easy and basic scripts for the execution of the batch file.

11. How to use comments in PowerShell?

Ans:

Like other scripting languages, PowerShell also supports single or multi-line comments.

Single-Line comments: “Those comments which use the (hash) # symbol at the beginning of each line”.

Syntax of single-line comment:

  • <Any Command or statement> # <Any comment>  

Multi-line comments: “Those comments which use the # (hash) symbol at the end of last line and beginning of the first line”.

Syntax of Multi-line comment:

  • <# Multiple-line Comment…………………….  
  • ………………..  
  • …………………………………………#>  
  • Statement-1  
  • Statement-2  
  • Statement-N  

12. Explain the significance of PowerShell brackets?

Ans:

  • Braces Brackets {}: These types of brackets are used in the blocked statements.
  • Parenthesis Brackets (): These brackets are used for required arguments.
  • Square Brackets []: These types of brackets used to define the optional items.

13. What is the variable in PowerShell?

Ans:

A PowerShell variable is a unit of memory which is used to store the data. You can easily store all the types of values in the variable of PowerShell. In the variables, PowerShell contains integers, strings, and objects.

14.How to declare and create a variable in PowerShell?

Ans:

Declaration: In PowerShell, you can declare a variable by using the $ (dollar) sign at the beginning of the variable name. Following syntax describes how to declare the variable:

  • $ <variable_name>

For example:

  • $var

Creation or Initialization: In PowerShell, you can create a variable by assigning the value to a variable using the assignment operator. Following syntax describes how to declare the variable:

  • $ <variable_name> = <value>  

15. Enlist the two ways of extending PowerShell?

Ans:

  • PSSnapins
  • Modules

16.What do you think is Microsoft PowerShell?

Ans:

Microsoft PowerShell is a command-line shell and scripting language built on .NET. It helps system admins and power-users to quickly manage OS. (Windows, MacOS and Linux) and processes.

17. Define the key features of PowerShell?

Ans:

The prime characteristics of Microsoft PowerShell can be summed up as follows –

  • PowerShell is a scripting environment
  • PowerShell commands are customizable
  • The programming language isn’t text-based. It’s object-based.

18.What makes up the variables in PowerShell?

Ans:

Variables contain objects, integers, and strings.

19.In PowerShell, what according to you is the implication of brackets?

Ans:

We use () Parentheses Brackets in compulsory arguments.

We use {} Braces Brackets for blocked statements

We do not normally use [] Square Brackets. These brackets specify optional items.

20. What is your understanding of cmdlet?

Ans:

Cmdlet are commands scripted in languages such as PowerShell VB or C#.

21.Are you aware of PowerShell Loop?

Ans:

When repetitive tasks are automated using PowerShell, it is called PowerShell Loop.

22. Can PowerShell scripts be created for the deployment of SharePoint components?

Ans:

If the web part is created employing VS2010, SharePoint components can be deployed with the help of ctrl+f5. Features of web part can be activated through PowerShell script.

23. What is your idea about comparison operators in PowerShell?

Ans:

Comparison operators in PowerShell compare values. Comparison operators can be classified into four types –  Match, Equality, Replace, and Containment. To declare variables, –eq  comparison is used. Similarly, –lt is used for ‘less than’, -gt for ‘greater than’, and ‘not equal’ is denoted by –ne.

24. What is the use of the PowerShell pipeline?

Ans:

When we have to join two statements, we use the PowerShell pipeline. In this case,  one statement’s output emerges as the second statement’s input.

25.What do you understand by get-command in PowerShell?

Ans:

PowerShell’s get-command is applied to fetch cmdlets. For instance, if anyone is searching cmdlet between E and K, then the get-command would look like –

  • get-command [ E–K ]*

26. Can you explain how network drive is mapped in PowerShell? 

Ans:

For mapping network drive, the following PowerShell commands have to be executed –

# PowerShell Map Network Drive

  • $Net = $( New-Object – ComObject Wscript.Network )$Net.MapNetworkDrive( “S:”, expertmyTectra )

27. Do you know the methods to ‘Select’ in PowerShell?

Ans:

The simplest way is WQL (WMI Query Language) statement. This technique uses the ‘-query’ in order to introduce ‘Select * from’.

Select-String is the next method to ‘Select’ in PowerShell. In this scenario, matching pattern, phrase, and word is checked by the cmdlet.

The last way is through Select-Object.

Course Curriculum

Get Hands-on PowerShell Training from Industry Experts

  • Instructor-led Sessions
  • Real-life Case Studies
  • Assignments
Explore Curriculum

28.  What is PowerShell’s Get-ServiceStatus function?

Ans:

The functions of Get-ServiceStatus enable filtering of window services.  PowerShell lists the services that are ‘Running’, also, the services that are ‘Stopped’ through scripting.

29. Since you mentioned scripting, define what Scripting in PowerShell is?

Ans:

PowerShell files contain an array of commands, where each command appears in separate lines. When using text file, the filename will have the .PS1 extension. PowerShell script can be run by –

  • Typing commands in text editor
  • Saving file with the .ps1 extension
  • Executing the file

30.  Can you explain the hash table functions in PowerShell?

Ans:

PowerShell’s hash table can be referred as a dictionary. Basically, it is a series that enables users in storing data with a pair association known as “key-value”. Here, both “key”, as well as “value”, might comprise of any length and data. In order to declare hash table users will have to apply @ in front of curly braces.

31.Can you explain the uses of PowerShell Array?

Ans:

PowerShell Array is used to run scripts on remote computers.  To create PowerShell Array, users will need to create variable, as well as they will have to assign the PowerShell Array.  PowerShell Arrays are expressed with a “@”symbol, and illustrated as hashtable.

For instance, it would be like

  • $arrmachine = @ ( “machine1” , “machine2” , “machine3”)

32. Define what commands to use in order to get child folders into a specified folder?

Ans:

We will have to apply parameter recurse to get child folders into a specified folder. It will be –

  • Get-ChildItem C:Scripts –recurse

33. Can you explain the ways to convert the object to HTML?

Ans:

In order to convert the object to HTML, we will have to execute –

  • Get-Process l Sort-object – property CPU –descending l convert to – HTML l Out-file “process.html”

34.Can you define how you will assign a different name to a variable?

Ans:

A variable can be renamed by using –

  • Rename-Item- Path Env: MyVariable –NewName MyRenamedVar

35.  Are you aware of $input variable? What are its functions?

Ans:

$input variable activates a function that enables pipeline data access.

36. Enlist the two methods by which input of pipeline works?

Ans:

  • ByValue
  • ByPropertyName

37.Name the Different types of variables in PowerShell?

Ans:

Following are the three types of variables in PowerShell:

  • User-Created variables
  • Automatic variables
  • Preference variables

38. What is the Automatic variable in PowerShell and enlist the common automatic variables?

Ans:

There are so many predefined variables in PowerShell, which are known as the automatic variables. These variables mainly store the information about the PowerShell, and created and maintained by the PowerShell. Any user can’t change or update the value of these variables.

Following are some common automatic variables:

  • $$
  • $?
  • $^
  • $_
  • $args
  • $Error
  • $foreach
  • $Home
  • $input
  • $null
  • $PSHome
  • $PWD

39. Explain the array in PowerShell?

Ans:

An array in a PowerShell is a type of data structure which stores the collection of values in the single variable.

40. What is a hash table in PowerShell?

Ans:

The hash table in PowerShell is also called as a dictionary or an associative array. It is a compact data structure which is used to store each value by using a key. For every hash table, there is an object of a hash table in the PowerShell.

Following box describes the syntax of hash table:

  • $variable_name = @{ <key1> = <value1> ; < key2> = <value2> ; ….. ; < keyN> = <valueN>;}    

41.  Explain with an example how you can map a network drive in PowerShell?

Ans:

To map a network drive in PowerShell you have to use the command like

# PowerShell Map Network Drive

  • $Net = $( New – Object – ComObject Wscript.Network )
  • $Net.MapNetworkDrive( “S:”, \\expert\guru99 )

In here the drive letter is “S:” and the Network share is called ‘expert’ on a computer called ‘guru99.’

42.  Mention what are the three ways that PowerShell uses to ‘Select’?

Ans:

  • The most common way is in a WMI Query Language (WQL) statement. In this technique Wmiobject uses ‘-query’ to introduce a classic ‘Select * from’ a phrase
  • The second context for ‘Select’ in PowerShell is Select-String. This cmdlet checks for a word, phrase or any pattern match
  • Another way is Select Object

43. What is the function of Get-ServiceStatus in PowerShell?

Ans:

The cmdlets of windows enable you to filter the window services.  PowerShell can list which services are ‘Running’ and which are ‘Stopped’ by scripting with windows.

44.  Explain what PowerShell Scripting is?

Ans:

PowerShell file contains a series of PowerShell commands with each command appearing on a separate line. To use a text file as a PowerShell script, its filename should have.PS1 extension. To run a script you need

  • Type the commands in a text editor
  • Save the file with .ps1 extension
  • Execute the file in PowerShell

45.   What is the use of hash table in PowerShell?

Ans:

A hash table is also referred as dictionary. It is an array that allows you to store data in a “key-value” pair association. The “key” and “value” can be of any data and length.  To declare a hash table you have to use @ followed by curly braces.

46. Explain what is the use of Array in PowerShell?

Ans:

The use of Array in PowerShell is to run a script against remote computers.  In order to create an array, you have to create a variable and assign the array.  Arrays are represented by “@”symbol, they are represented as hashtable but not followed by curly braces.

For example,

  • $arrmachine = @ ( “machine1” , “machine2” , “machine3”)

47.   Mention what is the command that can be used to get all child folders in a specific folder?

Ans:

To get all child folders in a specific folder, you have to use parameter recurse in the code.

  • Get-ChildItem C:\Scripts –recurse

48. Explain how you can convert the object into HTML?

Ans:

To convert the object into HTML

  • Get-Process l Sort-object – property CPU –descending l convert to – HTML l Out-file “process.html”

49.  Explain how you can rename a variable?

Ans:

To rename a variable,

  • Rename-Item- Path Env: MyVariable –NewName MyRenamedVar

50.   Explain what is the function of $input variable?

Ans:

The $input variable enables a function to access data coming from the pipeline

51.What is Windows Powershell ?

Ans:

Windows PowerShell is a new Windows command-line shell designed especially for system administrators. In the SharePoint training Hyderabad administration context, Windows PowerShell is another administration tool that supersedes the existing Stsadm.exe.

52.Where is Powershell located in sharePoint ?

Ans:

On the Start menu, click All Programs -> Click Microsoft SharePoint 2010 Products -> Click SharePoint 2010 Management Shell.

53.What are cmdlets?

Ans:

Windows PowerShell introduces the concept of a cmdlet which are simple build in commands, written in a .net language like C# or VB.

54.Can you tell me two major differences between $Other_Language and PowerShell ?

Ans:

This question is an fantastic opportunity get an insight into the candidate understanding of PowerShell core concepts and his/her favourite PowerShell features.

For example, one of the most fundamental difference between bash and PowerShell is that bash is text-oriented whereas PowerShell is object-oriented.

A good candidate should be able to tell that. A great candidate, would most likely go on and on about the benefits of the object-oriented nature of PowerShell.

Also, if a candidate cites 2 valid differences between the two languages, but not a major one, the candidate might have a partial knowledge of PowerShell.

55.How would you ping a remote computer with 5 packets using PowerShell ?

Ans:

Again, this is basic stuff. I wouldn’t get caught up in ideology, the good old ping.exeis perfectly valid, as long as the candidate knows the option to specify 5 packets.

If you really want the more PowerShelly Test-Connection, then ask : I just want the command to return $True if the ping is successful and $False if it is not.

56.What is the difference between ConvertTo-CSV and Export-CSV commands?

Ans:

  • ConvertTo-CSV is a one step process that only converts data into csv format and let it remain inside the shell
  • Export-CSV is a 2 step process that not only converts data into CSV and also writes the output to a CSV format file.
Course Curriculum

Get Advanced Practical Oriented PowerShell Course

Weekday / Weekend BatchesSee Batch Details

57.How will you check the default path for PowerShell Modules ?

Ans:

  • Get-Content env:psmodulepath

58.How will you check what commands have been added after adding the new snapin to powershell ?

Ans:

  • Get-Command -pssnapin <snapin name> –>

Lists all commands that got added when the snapin was added to the shell

59.What are the 4 types of FORMAT commands that can be used to format data?

Ans:

  • Format-Wide
  • Format-List
  • Format-Table
  • Format-Custom

60.What are two ways of extending PowerShell?

Ans:

  • PSSnapins
  • Modules

61.What is the function of Get-Service Status in PowerShell?

Ans:

The cmdlets of windows enable you to filter the window services. PowerShell can list which services are ‘Running’ and which are ‘Stopped’ by scripting with windows.

62. What is the code to find the name of the installed application on the current computer?

Ans:

Format-wide-column1

63. Explain how you can find in PowerShell that all the sql services are on one server?

Ans:

There are two ways to do this

  • get-wmiobject win32_service l where-object {$_name-like “*sql*”}
  • get-service sql*

64. Can you illustrate the code used to locate names of installed applications on a current computer?

Ans:

We will have to employ the following code – 

  • Get-WmiObject-Class Win32_Product

– ComputerName. l Format-wide-column1

65.How do you think you will find that sql services in PowerShell are in one server?

Ans:

We can do this in two ways –

  • get-wmiobject win32_service l where-object {$_name-like “*sql*”} get-service sql*

66. What according to you is an efficient way to locate all sql services in one server?

Ans:

In this case also, we can do it in two ways –

  • get-wmiobject win32_service | where-object {$_.name -like “*sql*”}get-service sql*

67. Are you aware of the class that can enable us to identify if mc is 64 bit or 32 bit?

Ans:

  • win32_computersystem.

We can use this as follows –

  • PS C:> $server = gwmi -cl win32_computersystemPS C:> $server.SystemType X86-based PC

68.What is your idea about Variable Interpolation?

Ans:

When a variable is added to double-quoted strings, then PowerShell changes the name of that variable through its value. Typically, this feature in PowerShell is known as variable interpolation.

69. Explain about the PowerShell’s comparison operators?

Ans:

Comparison Operators compares value in PowerShell.  Four types of comparison operators are used equality, match, containment and replace.  In PowerShell, one of the key comparison operators is –eq that is used instead of “=” sign for declaring variables.  Likewise, there are other operators like –ne for “not equal” , -gt ( greater than ) or –lt (less than).

Powershell Sample Resumes! Download & Edit, Get Noticed by Top Employers! Download

70. In PowerShell what does variables holds?

Ans:

In variables PowerShell contains strings, integers and objects. It does not have special variables as it is pre-defined with PowerShell

71. Explain what is the significance of brackets in PowerShell?

Ans:

  • Parenthesis Brackets (): Curved parenthesis style brackets are used for compulsory arguments.
  • Braces Brackets {} : Curly brackets are employed in blocked statements
  • Square Brackets []: They define optional items, and they are not frequently used

72.What does it mean cmdlet’s?

Ans:

Cmdlet’s are simple build in commands written in .net language like C# or VB introduced by Windows PowerShell

73. Explain what is PowerShell Loop?

Ans:

Automating repetitive task with the help of PowerShell loop is known as PowerShell Loop. Through PowerShell, you can execute For each loop, While loop and Do While loop.

74. Explain can you create PowerShell scripts for deploying components in SharePoint?

Ans:

If you have created a web part using VS 2010 then, you can deploy it using cntrl+f5. However to activate the web part feature you can write a PowerShell script (.ps1) and execute it after deployment

Are you looking training with Right Jobs?

Contact Us

Popular Courses