PowerShell Interview Questions and Answers
by Bharathkumar, on Sep 11, 2022 4:32:57 PM
1) Explain what is PowerShell?
Power shell is an extendable command shell and a scripting language for Windows.
2) 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
3) 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
4) Explain what is the significance of brackets in PowerShell?
- 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
5) 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
6) Explain what is PowerShell Loop?
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.
7) Explain can you create PowerShell scripts for deploying components in SharePoint?
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
8) Explain about the PowerShell’s comparison operators?
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).
9) Explain what is PowerShell pipeline is used for?
PowerShell pipeline is used for joining two statements such that the output of one statement becomes the input of the second.
10) 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
11) Explain with an example how you can map a network drive in PowerShell?
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\myTectra )
In here the drive letter is “S:” and the Network share is called ‘expert’ on a computer called ‘myTectra.’
12) Mention what are the three ways that PowerShell uses to ‘Select’?
- 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
13) 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.
14) Explain what PowerShell Scripting is?
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
15) What is the use of hash table in PowerShell?
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.
16) Explain what is the use of Array in PowerShell?
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”)
17) Mention what is the command that can be used to get all child folders in a specific folder?
To get all child folders in a specific folder, you have to use parameter recurse in the code.
Get-ChildItem C:\Scripts –recurse
18) Explain how you can convert the object into HTML?
To convert the object into HTML
Get-Process l Sort-object – property CPU –descending l convert to – HTML l Out-file “process.html”
19) Explain how you can rename a variable?
To rename a variable,
Rename-Item- Path Env: MyVariable –NewName MyRenamedVar
20) Explain what is the function of $input variable?
The $input variable enables a function to access data coming from the pipeline
21) What is the code to find the name of the installed application on the current computer?
Get-WmiObject-Class Win32_Product- ComputerName . l Format-wide-column1
22) Explain how you can find in PowerShell that all the sql services are on one server?
There are two ways to do this
- get-wmiobject win32_service l where-object {$_name-like “*sql*”}
- get-service sql*
23) What is the best way to find all the sql services on one server?
There are two ways to do this.
- get-wmiobject win32_service | where-object {$_.name -like “*sql*”}
- get-service sql*
24) Which class can help us identify whether the m\c is 32 bit or 64?
win32_computersystem. This can be used as follows:
PS C:\> $server = gwmi -cl win32_computersystem
PS C:\> $server.SystemType X86-based PC
25) What is Variable Interpolation?
When you add a variable to a double-quoted string, PowerShell replaces the variable name by its value. This feature is called variable interpolation.