Powershell Interview Questions

Here are some sample PowerShell interview questions.
These are the kinds of questions that could be asked to gauge one's basic literacy and comfort level with PowerShell.

Basic literacy. Describe the following:
a. What is PowerShell? Why is it called a shell?
b. How does PowerShell differ previous Windows scripting techniques, such as CMD/batch files, VBScript, etc.?
c. What is a cmdlet?
d. What is meant when it's said that Powershell is "object-based"?
e. What is the pipeline? How is it useful?

Get the amount of free space on the C drive.
Ans:- Using WMI is an option

How to automate Internet Explorer to open a web site using PowerShell?

Please below three simple steps to open Internet Explorer a


$ie = New-Object -ComObject InternetExplorer.Application
$ie.Visible = $true

Copy and Try it

How to run a PowerShell script?
Launch PowerShell
Navigate to the directory where the script lives


 PS> cd C:\test\ (enter)

Copy and Try it

Execute the script:


 PS> .\test_script.ps1 (enter)

Copy and Try it

There is alternate way to run powershell script using "POWERSHELL_ISE".
Please see below option.

How to prepare window 7 bootable Disc using powershell?
Ans : Coming Soon..

Is PowerShell ready to replace my cygwin shell on Windows?
PowerShell is defiantly looks powerful tool for windows.
The person who worked in heterogeneous environments Linux, Solaris and Mac OS X and cygwin.
Can differentiate better way. It is nice and more powerful tool environment seems to have been thought out much more than Unix shells as it use of objects instead of text streams.
Powershell is more powerful than the standard built-ins of the Unix shells.
Note: - Using objects is a paradigm shift as compare to other environments and it avoids the whole re-parsing at each step where structured data is involved.

How to use powershell to download old version of package with nuget?
The powershell command Install-Package has a Version argument that can be used to specify a specific version.

Get-Package -ListAvailable -Filter Autofac -AllVersions
By pressing tab after the version option in the Install-Package command, you get a list of the latest available versions.
Install-Package Autofac -Version 1.2.0

How do you count the lines of code in a Visual Studio solution using powershell script?
Specify project folder path and below comments to measure the count lines of code


PS>cd D:\NineOptions\SSRSService\
PS>(dir -include *.cs,*.xaml,*.cpp,*.h,*.idl,*.asmx -recurse | select-string .).Count

Copy and Try it

PowerShell "execution of scripts is disabled on this system."
There two ways to solve the issue. As bydefault powershell -ExecutionPolicy is restricted.
You may change it to either of 4 available options
1. Restricted
2. Unrestricted
3. Signed
4. RemoteSigned
Set-ExecutionPolicy RemoteSigned
Or you can bypass the execution policy for particular ps1 file.
powershell -ExecutionPolicy ByPass -File script.ps1

PowerShell to build App.Config separately based on project.
You can get more detail about xmlpreprocess at below link.
Managing Properties
Create xml with each environment details.
A spreadsheet can be used to manage the properties for all of your environments in one place.
Command Line


    Usage: XmlPreprocess.exe [@argfile] [/input|i:] [/output|o:]
       [/settings|s:] [/define|d:] [/clean|c] [/quiet|q] [/validate|v]
       [/validateSettingsExist|vs] [/validateXmlWellFormed|vx] [/fixFalse|f]
       [/environment|e:] [/spreadsheet|x:] [/database|db:]
       [/custom|cx:] [/list|l] [/property|p:] [/delimiters|t:]
       [/environmentRow|er:] [/firstValueRow|vr:]
       [/settingNameCol|nc:] [/defaultValueCol|dc:]
       [/environmentFile|ef:] [/noDirectives|n] [/tokenStart|ts:]
       [/tokenEnd|te:] [/countReportFile|cr:] [/noLogo] [/help|?|h] [/version|v]

Copy and Try it

how to prepare xml setting please go to home page and find the more detail..

Powershell script for deploying configuration setting to actual web.config for each environment.


 foreach ($Env in $EnvList)
 XmlPreprocess.exe /v /f /nologo /i "web.config" /s "SettingConfigs.xml" /e $remoteserver /o "$OutputPath\web.config"

Copy and Try it

If you need more details please do reach us.
How to access argument list for scriptblock? ArgumentList is based on use with scriptblock commands, like:


 $xArgvalue= arg[0]
 $yArgvalue= arg[1]
} -ArgumentList $x,$y


Copy and Try it

  • Explain what is PowerShell?

    Power shell is an extendable command shell and a scripting language for Windows.

  • 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

  • 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

  • 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 PowerShell

  • 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

  • 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.

  • 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

  • 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).

  • 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.

  • 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 ]*

  • 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\admin )

    In here the drive letter is "S:" and the Network share is called ‘expert' on a computer called ‘admin.'

  • 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

  • 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.

  • 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

  • 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.

  • 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")

  • Mention what is the command that can be used to get all child folders in a specific folder? vTo get all child folders in a specific folder, you have to use parameter recurse in the code.

    Get-ChildItem C:\Scripts -recurse

  • 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"

  • Explain how you can rename a variable?

    To rename a variable,

    Rename-Item- Path Env: MyVariable -NewName MyRenamedVar

  • Explain what is the function of $input variable?

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

  • What is the code to find the name of the installed application on the current computer? vGet-WmiObject-Class Win32_Product- ComputerName . l Format-wide-column1
  • 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*