PowerShell Interview Questions for Experienced/PowerShell Interview Questions and Answers for Freshers & Experienced

Name the type of format commands which are used to format the data.

1. Format-List
2. Format-Table
3. Format-Wide
4. Format-Custom

Name the command which is used to copy a file, registry key, or folder?

Copy-Item is a command which is used to copy the files or folders in a file system drive and the registry keys in the registry drive.

Explain the Comparison operator in PowerShell?

Comparison Operators are used in PowerShell for comparing the values. Following are four types of comparison operators:

1. Equality Comparison Operator
2. Match Comparison Operator
3. Containment Comparison Operator
4. Replace Comparison Operator

How to query data with a hash table from Application log?

The query gets data from the Application log to build the hash table one key-value pair at a time. The query gets data from the Application log. The hash table is equivalent to <Get-WinEvent –LogName Application>.

To begin, create the <Get-WinEvent> query. Use the FilterHashtable parameter’s key-value pair with the key, LogName, and the value, Application.

Example:

>Get-WinEvent -FilterHashtable @{

LogName=’Application’

}

–complete–

How do you listing Local Users and Owner in PowerShell?

Local general user information — number of licensed users, current no. of users, and the owner name — can be found with a selection of “Win32_OperatingSystem” class properties. You can select the properties to display like this:

Example:

>Get-CimInstance -ClassName Win32_OperatingSystem |

Select-Object -Property NumberOfLicensedUsers,NumberOfUsers,RegisteredUser

How do you listing all installed hotfixes in PowerShell?

To list all installed hotfixes by using Win32_QuickFixEngineering:

Example:

Get-CimInstance -ClassName Win32_QuickFixEngineering

How to listing desktop settings on a local computer?

The following command collects information about the desktops on the local computer:

Example:

>Get-CimInstance -ClassName Win32_Desktop

How can Enum support arithmetic operation?

Enums support arithmetic operations, as shown in the following example.

Example:

>enum SomeEnum { Max = 42 }

>enum OtherEnum { Max = [SomeEnum]::Max + 1 }

How do you remove all registry keys under a specific key?

If attempt to delete the <HKCU:CurrentVersion subkey> :

Example:

>Remove-Item -Path HKCU:CurrentVersion

(To delete contained items without prompting, specify the Recurse parameter )

>Remove-Item -Path HKCU:CurrentVersion –Recurse

If you wanted to remove all items within HKCU:CurrentVersion but not <HKCU:CurrentVersion> itself, you could instead use:

>Remove-Item -Path HKCU:CurrentVersion* -Recurse

How to deleting registry Keys?

Deleting items is essentially the same for all providers. The following commands will silently remove items:

Example:

>Remove-Item -Path HKCU:Software_custom

>Remove-Item -Path ‘HKCU:key with spaces in the name’

How to creating registry keys?

Creating new keys in the registry is simpler than creating a new item in a file system. Because all registry keys are containers, you do not need to specify the item type; you simply supply an explicit path, such as:

Example:

>New-Item -Path HKCU:Software_custompath

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

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

How to declare and create a variable in PowerShell?

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>

How to get a single registry entry?

The example given finds the value of DevicePath in <HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersion>.

Using <Get-ItemProperty>, use the Path parameter to specify the name of the key, and Name parameter to specify the name of the DevicePath entry.

Example:

>Get-ItemProperty -Path HKLM:SoftwareMicrosoftWindowsCurrentVersion -Name DevicePath

What is the use of “Get-ItemProperty” in listing registry entries?

To view the registry entries in a more readable form, use “Get-ItemProperty”:

Example:

>Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersion

How to listing registry entries?

To see the names of the entries in the registry key <HKEY_LOCAL_MACHINESoftwareMicrosoftWindowsCurrentVersion>, use <Get-Item>. Registry keys have property with the generic name of “Property” which is a list of registry entries in the key. The command given below selects the Property property and expands the items so that they are displayed in a list:

Example:

>Get-Item -Path Registry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersion |

>Select-Object -ExpandProperty Property

How to read a text file into an array?

The Get-Content cmdlet command can be used to read an entire file in one step and one element per line of the file content. You can confirm it by checking the length of the content returned :

Example :

PS> Get-Content -Path C:sampledata.txt

PS> (Get-Content -Path C: sampledata.txt).Length

6

How do you Mapping a Local Folder as a drive?

Using the <”New-PSDrive”> command. The following command will create a local drive P: rooted in the local Program Files directory which is visible only from the PowerShell session:

Example:

>New-PSDrive -Name P -Root $env:ProgramFiles -PSProvider FileSystem

How do you avoid recursive prompt for each contained item?

If you don’t want to be prompted for each and every contained item, specify the Recurse parameter:

Example:

>Remove-Item -Path C: empNewFolder –Recurse

What are the drawbacks of PowerShell?

* PowerShell which requires DotNet framework which is cost-effective.
* Security-Risks.
* It depends on the webserver to execute. Which may not right thing for any client. This leads to additional space on a server so custom software Development Company does not allow to afford resources for this.

How do you implements multiple conditions?

This following examle shows how to create a <Where-Object> command with multiple-conditions.

This command gets non-core modules which support the Updatable <Help> features. It uses the <ListAvailable> parameter of the Get-Module> command to get every modules on the system. A pipeline operator (|) sends the modules to the <Where-Object> command , that gets modules whose names do not start with Microsoft or PS, and have a value for the <HelpInfoURI> property, that tells the powerShell where to find updated help files for the module. The compare-statements are connected by the <And> logical operator.

Example:

>Get-Module -ListAvailable | where {($_.Name -notlike “custom*” -and $_.Name -notlike “PS*”) -and $_.HelpInfoUri}.

How to get processes based on process name using where-object?

The command processes that have a <ProcessName> property value that begins with the letter-p. The Match-operator use the regular expression matches. The scriptblock and statement syntax are same and used interchangeably.

Example:

>Get-Process | Where-Object {$_.ProcessName -Match “^p.*”}

>Get-Process | Where-Object ProcessName -Match “^p.*”

What is Try, Catch, and finally in PowerShell?

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.

How to get sessions connected to the local computer?

The <PSSessions> command that are connected to the local system. To specify the local system, type the system name, <localhost>, or a dot (.)

The command returns all of the sessions on the local system, even if they were created in different sessions or on different systems.

How to get owershell session in local/remote system?

The <Get-PSSession> command gets the user-managed sessions (PSSessions) from powershell on local and remote computers.

Example:

>Get-PSSession

How to get jobs that have not been started?

This “Get-Job” command gets only those jobs that are created but haven’t yet been started. It includes the jobs that are scheduled the jobs to run in the future slots and those not yet scheduled.

Example:

>Get-Job -State NotStarted

How to Export history entries up to a specific ID?

Example to save the history in Historysave.csv file as below:

This example iterate the five most recent history entries. The pipeline passes the entire result to the <Export-Csv> command, which formats the history as comma-separated text and saves it in the Historysave.csv file. The file contains the data that is showed when you format the history as a list. This includes the status and begin/start and end times of the command.

>Get-History -ID 3 -Count 5 | Export-Csv Historysave.csv

How do you get a list of the commands entered during the current session?

The <Get-History> command gets the session’s history, (i.e.) the list of commands entered during the present session.

The PowerShell routinely preserves a history of each session. The number of command entries within the session history is decided by the worth of the <$MaximumHistoryCount> preference variable. At start in Windows PowerShell 3.0, the default value is <4096>. By default-, history of files are saved within the home directory, but you’ll save the entire file in any location.

Example:

>Get-History

Can you explain how to Display selected parts of a cmdlet by using parameters?

These following examples display the selected portions of the Format-Table command help.

>Get-Help Format-Table -Examples

>Get-Help Format-Table -Parameter *

>Get-Help Format-Table -Parameter GroupBy

The examples parameter displays the the assistance file’s NAME and SYNOPSIS sections, and every one the examples. You can’t identify an example number because the examples parameter is a switch parameter.

The Parameter shows only the content description of the parameters. If you specify only the asterisk-(*) wildcard character, it shows the descriptions of every/all parameters. When Param specifies a parameter name such as <GroupBy>, info (information) about that parameter is shown.

Can you explain about Get-Help?

The command “Get-Help” displays the information about PowerShell concepts and commands functionality, together with <cmdlets>, functions, Common Information Model-(CIM) commands, -workflows, -providers, -aliases, and the scripts.

To get the help content for a given PowerShell cmdlet, type Get-Help follow by the _cmdlet_ name, such as: <“Get-Help”>, <“Get-Process”>.

Example:

>Get-Help Format-Table

>Get-Help -Name Format-Table

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*

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.

Explain what is the function of $input variable?

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

Explain how you can rename a variable?

To rename a variable,

Rename-Item- Path Env: MyVariable –NewName MyRenamedVar

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”

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

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”)

Could you explain about ping a remote computer with 5 packets using PowerShell?

Again, this is basic stuff. I would not get caught up in ideology, the good old ping. Exe is seamlessly valid, as long as the candidate knows the option to specify 5 packets.

If you really want the more “PowerShell” <Test-Connection>, then just want the command to return <$True> if the ping is successful connected and <$False> if it is not connected.

Could you explain the difference between “convertto-csv” and “export-csv” commands?

The command “ConvertTo-CSV” is a one stage process that changes data into csv format and let it persist inside the shell “Export-CSV” is a 2 step process that not only changes data into “CSV” and also writes the output to a “CSV” format file.

How do you check the default path for PowerShell modules?

The command is as follows:

Get-Content env:psmodulepath

Search
R4R Team
R4R provides PowerShell Freshers questions and answers (PowerShell Interview Questions and Answers) .The questions on R4R.in website is done by expert team! Mock Tests and Practice Papers for prepare yourself.. Mock Tests, Practice Papers,PowerShell Interview Questions for Experienced,PowerShell Freshers & Experienced Interview Questions and Answers,PowerShell Objetive choice questions and answers,PowerShell Multiple choice questions and answers,PowerShell objective, PowerShell questions , PowerShell answers,PowerShell MCQs questions and answers Java, C ,C++, ASP, ASP.net C# ,Struts ,Questions & Answer, Struts2, Ajax, Hibernate, Swing ,JSP , Servlet, J2EE ,Core Java ,Stping, VC++, HTML, DHTML, JAVASCRIPT, VB ,CSS, interview ,questions, and answers, for,experienced, and fresher R4r provides Python,General knowledge(GK),Computer,PHP,SQL,Java,JSP,Android,CSS,Hibernate,Servlets,Spring etc Interview tips for Freshers and Experienced for PowerShell fresher interview questions ,PowerShell Experienced interview questions,PowerShell fresher interview questions and answers ,PowerShell Experienced interview questions and answers,tricky PowerShell queries for interview pdf,complex PowerShell for practice with answers,PowerShell for practice with answers You can search job and get offer latters by studing r4r.in .learn in easy ways .