Powershell Interview Questions and Answers

Powershell Interview Questions and Answers from Codingcompiler – In this article we have prepared the most frequently asked Powershell Interview Questions and Answers for beginners and experienced by covering all the core areas by professionals.

Powershell Interview Questions

  1. What is Powershell Scripting?
  2. Explain what do you understand by PowerShell?
  3. Explain Execution Policies and types of Execution Policy?
  4. What Is The Function Of $input Variable?
  5. What are the key characteristics of PowerShell?
  6. In PowerShell what does variables holds?
  7. What does it mean cmdlet’s?
  8. What’s the significance of brackets in PowerShell?
  9. What is a hash table in PowerShell?
  10. How do I enable execution policy in PowerShell?

Powershell Interview Questions and Answers

1. What is Powershell Scripting?

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

2. Explain what do you understand by PowerShell?

PowerShell is a shell designed keeping in mind the need of system administrators. It is open Source and Platform Independent i.e. works for Windows/Linux/Mac. It is object-oriented and not text-based. It is built on a .NET framework. It has an Interactive prompt and also a scripting environment.

3. Explain Execution Policies and types of Execution Policy?

This is the common PowerShell Interview Questions asked in an interview. There are 6 types of execution policies in PowerShell. These are:-

  • Restricted: This is the default type. Under this, PowerShell will not run any script including PowerShell profiles too.
  • RemoteSigned: PowerShell will only run any script that is created locally. Any script that has been coming from the Internet should be digitally signed with a signing certificate code and is trusted by the computer.
  • AllSigned: PowerShell will only run any script that has been digitally signed using a trusted code signing certificate.
  • Unrestricted: PowerShell will run any script. If the script comes from an untrusted source, users are prompted once to execute it.
  • Bypass: This policy will run any script without any question or prompt.
  • Undefined: There is no execution policy set for this in the current scope.

4. What Is The Function Of $input Variable?
The $input variable enables a function to access data coming from the pipeline

5. What are the key characteristics of PowerShell?

 The key characteristics of PowerShell are

  • PowerShell is object-based and not text based
  • Commands in PowerShell are customizable
  • It is a command line interpreter and scripting environment.

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

7. What does it mean cmdlet’s?
Cmdlet’s are simple build in commands written in .net language like C# or VB introduced by Windows PowerShell.

8. What’s the significance of brackets in PowerShell?
Due to the object-oriented language, bracket plays an important role in PowerShell. The PowerShell employs four types of brackets namely parenthesis, braces, square and angular brackets. All these brackets come under control structure therefore in order to control the flow of the code brackets are required.

9. What is a hash table in PowerShell?

Hash table is a data structure which used the mechanism of value/key pair. The professionals who create PowerShell scripts use variables to store data. For the storage of data in a highly secure environment hash table is used.

10. How do I enable execution policy in PowerShell?

In order to enable the execution of PowerShell following steps are required to perform-

  • Start Windows PowerShell
  • Run as an Administrator
  • Enable running script by using the command: Set-execution policy redesigned

Frequently Asked Powershell Interview Questions and Answers

11. How do you declare a variable in PowerShell?

Dollar Sign “$” is used to declare a variable in Power Shell for example- $varible1= 23

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

Use parameter recurse in the code to get all child folders in a specific folder.

Get-ChildItem C:\Scripts –recurse

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

To convert the object into HTML

Get-Process

Sort-object– property CPU –descending.

Convert to – HTML.

Out-file “process.html”.

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

The function of $input variable is to access data coming from the pipeline.

15. What is the best way to find all the sql services on one server?

 There are two ways to do this. 

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

2. get-service sql*

16. How do you manage not to take any action for errors while executing powershell?

 -ErrorAction Silentlycontinue

17. Are you aware of PowerShell Loop?

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

18. What is your understanding of cmdlet?

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

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

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

Get-ChildItem C:Scripts –recurse

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

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

Advanced Powershell Interview Questions and Answers

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

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.

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

Format-Wide

Format-List

Format-Table

Format-Custom

23. Explain what is PowerShell get-command?

Get command in PowerShell is used to fetch other cmdlets, for example you are looking for cmdlet between letter L and R then your PowerShell get-command will be like

# PowerShell Get – Command Range

Clear-Host Get-Command [ L-R ]*

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

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.

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

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

26. Find the largest (by rows or size) 3 tables in the AdventureWorks2012 database

# Size by row count

$svr.databases[‘AdventureWorks2012’].tables | select name, rowcount | Sort-Object -Property RowCount -desc | select -First 3

# Size by table storage

$svr.databases[‘AdventureWorks2012′].tables | select schema, name, @{name=’size’; e={$_.dataspaceused+$_.indexspaceused }} | 

Sort-Object -Property size -desc | select -First 3;

27. How is Windows Powershell different from Stsadm ?

Unlike stsadm, which accept and return text, Windows PowerShell is built on the Microsoft .NET Framework and accepts and returns .NET Framework objects. In addition to that it also gives you access to the file system on the computer so that you can access registry,digital signature certificate etc.

28. What is scaleout stream serve?

The scaleout streamserver can easily perform stateful stream processing on incoming events for deeper introspection & real-time feedback. It is also used as the integrated in-memory data-grid/stream processing engine for the building of digital twins of data sources.

29. How to form credentials objects in PowerShell?

$UserName = ‘Prateek’

$Password = ‘[email protected]’ | ConvertTo-SecureString -AsPlainText -Force

# method 1

[pscredential]::new($Username,$Password)

# method 2

New-Object System.Management.Automation.PSCredential($UserName,$Password)

30. How Do You Comment Out Code In Powershell?

Like other languages powershell also supports single/Inline comments line and multi line comments.

Starting with PowerShell V1 there’s only # to make the text after it a comment.

In PowerShell V2 “<# #>” can be used for block comments (multi-line) and more specifically for SYNOPSIS, DESCRIPTION, NOTES, LINK help comments.

Example: Sinlgle/Inline comments

 # This is a single or inline comment starts with hash in Powershell

Example: Block comments (multi-line)
<# this is a first line of comment
 this is a second line of comment
this is a third line of comment
.
.
this is a last line of comment
#>

Related Articles

  1. Apigee Interview Questions
  2. Cloud Foundry Interview Questions And Answers
  3. Actimize Interview Questions
  4. Kibana Interview Questions
  5. Nagios Interview Questions
  6. Jenkins Interview Questions
  7. Chef Interview Questions
  8. Puppet Interview Questions
  9. DB2 Interview Questions
  10. AnthillPro Interview Questions
  11. Angular 2 Interview Questions
  12. Hibernate Interview Questions
  13. ASP.NET Interview Questions
  14. PHP Interview Questions
  15. Kubernetes Interview Questions
  16. Docker Interview Questions
  17. CEH Interview Questions
  18. CyberArk Interview Questions
  19. Appian Interview Questions
  20. Drools Interview Questions
  21. Talend Interview Question

LEAVE A REPLY

Please enter your comment!
Please enter your name here