Browse by Domains

Top 80+ Power Shell Interview Question & Answers

Table of contents

Powershell is getting more popular these days. Every DevOps professional and system admins have listed PowerShell scripting as one of the criteria in the job description. Catch up on the top 80+ PowerShell interview questions and answers you must be aware of before your next DevOps interview.

1.What is PowerShell?

Power shell is an extendable/scalable command shell and a scripting language for Windows machine/computer. It is platform-independent and open-source.

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 acts as a command-line interpreter and scripting environment

3.What is the use of the pipeline in PowerShell scripting?

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

4.What do you mean by get-command in PowerShell?

PowerShell’s get-command is applied to fetch cmdlets. For single instance, if anybody is searching cmdlet between G and L, then the “get-command” would look like –

>get-command [ G–L ]*

5.How is the command in the n/w-network drive mapped in PowerShell? 

The following commands have to be executed –

# Mapping Network Drive

>$Net = $( New-Object – ComObject Wscript.Network )

>$Net.MapNetworkDrive( “S:”, expertmyTectra )

6.How do you know about the methods to ‘Select’ query in PowerShell?

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

Select-String is also the next technics to ‘Select’ in the PowerShell command. In this scenario/scope, the matching pattern, idiom, and word is checked by the cmdlet.

The last way is through Select-Object.

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

The methods of “Get-ServiceStatus” enable filtering of window services.  PowerShell lists the services that are ‘Running’ and ‘Stopped’ through scripting.

8.Define scripting in PowerShell?

PowerShell programming files contain a sequence/an array of commands, where each command shows in sequences of separate lines. When using a text/script file, the filename has the.ps1 extension. 

PowerShell script can be run by –

  • Typing commands in a text editor
  • Saving a file with the .ps1 extension and executing the file

9.What is the hash table in PowerShell?

Hash the table can be defined as a dictionary. Because it is a series that enables to store data with a pair association is called “key-value” pair. Both “key” and “value” of any length and data. In order to the declaration of hash table developers has to add @ in front of curly braces.

10.What are the types of PowerShell operators?

There are 9 types of operators:

  1. Arithmetic Operators 
  2. Assignment Operators
  3. Logical Operators
  4. Comparison Operators
  5. Redirection Operators
  6. Split and Join Operators
  7. Type Operators
  8. Unary Operators
  9. Special Operators

11.What are Arithmetic Operators?

There are :

  1. (+ )Addition
  2. (-)Subtraction
  3. (*)Multiplication
  4. (/)Division
  5. (%)Modulus

 12. What are Assignment operators?

The given assignment operators are used to assigning, changing, or appending the values in a variable.

  1. =

(It assigns the values from the right side operands to the left side operands.)

  1. – =

(To subtract right-side operand from the left side operand and assigns the result to left side operand.)

  1. +-

(To add the right side operand to the left side operand and assigns the result to the left side operand.)

 13. Why do you use Logical Operators?

The logical conditional operators are used to connect the expression statements collectively to form a single expression. The command expressions which contains the logical operators usually result in shows in the Boolean values True (1) or False (0).

  1. AND
  2. OR
  3. NOT

 14. What are Comparison Operators?

It’s used to compare the values for equality, matching, containment, and replacement. 

CommandDescription
-eqUsed to check two values to be equal or not.
-neUsed to check the two values to be not equal.
-gtUsed to check the first value to be greater than the second one.
-geUsed to check the first value to be greater than or equals to the second one.
-ltUsed to check the first value to be less than the second one
-leUsed to check first value to be less than or equals to second one.

 15. How do you list “SQL” services from PowerShell prompt?

 16. How do you write a warning message to the PowerShell host?

 17. How to show the execution policies (ExecutionPolicy) for each scope in the order of precedence?

18. How do you set an execution policy for the local computer?

19. How do you compare two text file contents?

If “test1.txt” file has content:

apple

mongo 

and “test2.txt” file has content:

apple

mango

shown as:

20.How many types of execution policy in PowerShell?

There are 6 types:

  1. AllSigned
  2. RemoteSigned
  3. Restricted
  4. Undefined
  5. Bypass
  6. Unrestricted

Also Read: Top 40+ System Administration Interview questions and answers

21. How do you call policy and assign Restricted?

22. How to call the execution policy from a remote machine/computer to a local machine/computer?

This PowerShell command line execute the policy from a remote machine / computer and sets the policy on the local computer/ machine.

23. How do you get windows instrumentation management details in PowerShell?

Using the command “Get-WmiObject”

24. How do you get the process running list in machine/computer using PowerShell?

Using the command line: < Get-WmiObject -Class Win32_Process >

 25. How do you stop a service on a remote computer?

Using the command : (Get-WmiObject -Class Win32_Service -Filter “name=’WinRM'” -ComputerName Servername).StopService()

26. How do you get BIOS information in a local machine/computer using the PowerShell command?

Using the command line – <Get-WmiObject -Class Win32_Bios | Format-List -Property *>

27. How do you test server is in connection from local machine/computer using PowerShell like echo request?

Using the command line : <Test-Connection -ComputerName devserver>

 28. What do you mean by “try/catch” in PowerShell?

The error handling works in PowerShell (like many other languages) first “try” a block of code and then if it error throws then “catch” block can catch it.

 29. What do you mean by “try/finally” in PowerShell?

When no need handle error but need to execute some code execution at the time of error then “finally” is required.

30. Explain the functionality of brackets in PowerShell?

(): Curved parenthesis brackets are used for compulsory arguments.

{}: Curly brackets are employed in blocked statements

[]: Square brackets are they define optional items, and they are not frequently used.

31. What does in PowerShell Loop?

Looping/Repetitive task with the help of looping in PowerShell is known as PowerShell Loop.  Using PowerShell, you can execute “For each” loop,  “While” loop  and “Do While” loop.

32. Could you explain how do you convert the object into HTML?

The following command statement is to convert the object into HTML:

Command :>Get-ProcesslSort-object – property CPU –descendingl convert to – HTML l Out-file “custom.html”.

33. Do you explain renaming a variable?

To rename a variable,

Rename-Item- Path Env: <MyVariable> –NewName <MyRenamedVar>

34. Can you explain about PSScriptAnalyzer?

The tool named as “PSScriptAnalyzer” is a free static code analysis tool that works on PowerShell code. The “PSScriptAnalyzer” will find the most common issue seen in the powershell script , and often a recommendation for how to fix the issue. This is easy to implement and classifies the issues as Errors (severe, must be highlighted), Warning (need to be revised and should be highlighed), and Information (checking out for best practices). Every packages published to the PowerShell Gallery will be scanned using the tool “<PSScriptAnalyzer>”, and any errors will be reported back to the holder and must be highlighted.

The best practice is to run command “Invoke-ScriptAnalyzer” with -Recurse and -Severity Warning.

Review the results, and ensure that:

All the Errors are corrected or addressed in your script documentation.

All the Warnings are reviewed and addressed where applicable.


35. What is Manage Dependencies?

The Manage dependencies is important to specify the modules that your module is dependent on in the Module Manifest. This manage dependencies allows the user to not have to worry about installing the proper versions of the modules that yours take a dependency on. To specify the modules which dependent, you should use required module field in the module manifest. This will help to load any listed modules into the global environment prior to importing your module unless they’ve already been loaded. 

For example, some modules may be loaded by a different module. It is possible to identify the specific version to load using “RequiredVersion” field rather than “ModuleVersion” field. When using the “ModuleVersion”, it will load newest version available with lowest of the ver specified. When not using the “.<RequiredVersion>” field, to identify a specific version it is important to monitor the version updates to the required module. It is significant to be aware of any breach changes that could affect the user experience with the module.

Example: >RequirdModules = @(@{ModuleName=”myDependentedModule”; ModuleVersion=”2.0″; Guid=”dfc45206-1e49-459d-a8ad-5b571ef94859″})

Example: RequirdModules = @(@{ModuleName=”myDependentedModule”; RequiredVersion=”1.5″; Guid=”dfc45206-1e49-459d-a8ad-5b571ef94859″})

36. Can you tell me the difference, In PowerShell, between a function and an “advanced Function”?

This little bit be a tricky question for an average candidate, but normally, the good candidate should know that the only one thing that makes a function advanced and unlocks the tooling which comes with it is : [ CmdletBinding() ].

A candidate would be enthusiastic about all the powerful tools enabled by the advanced functions. Any scripter who strives to build professional – grade tools should be the thankful for all the work PowerShell is doing for us.

37.Could you explain about set a registry value with PowerShell?

I have to use the registry provider and <Set-ItemProperty>.

The registry is an integral part of Windows, so it is hardly area-specific knowledge. It is actual likely that any scripter has already performed this task at least once, maybe even on almost-daily basis.

38. Do you tell me, whether argument can be used to convert an <object> to a <string> or convert the property of an <object> into <string>?

Expand is the argument that needs to be used with the property name to convert an object property easily into a string.

Example:

Command :>Get-ADcomputer –filter * | select-Object –expand name

39.What Are Two Ways Of Extending Powershell?

There are two ways:

  1. PSSnapins
  2. Modules

40.What are the type of format command and what are they?

There are four types of format command.

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

41.How will you cross-check what commands have been added after adding the new Snapin to PowerShell?

The following commands with example:

Command :>Get-Command -pssnapin<snapin name>

Lists every commands that have added when the snapin was added to the shell.

42.How do you check the default path for PowerShell modules?

The command is as follows:

 Get-Content env:psmodulepath

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

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

45. Can you do and explain about comment out code in PowerShell?

Like other programming languages PowerShell also supports single/Inline comments line and multi-line comments.

Starting with PowerShell-V1 there is only <#> to make the text after it a comment.

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

Example: one line/Inline comments

 # This is an one line or inline comment starts with hash in PowerShell

Example: Block comments (multi-line)

    <# this is a 1 line of comment

       this is a 2 line of comment

       this is a 3 line of comment

       .

       .

       .

       this is a last line of comment

       #>

46. What’s the code to seek out the name of the installed application on the present computer?

>Get-WmiObject-Class Win32_Product- ComputerName . l Format-wide-column1

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

>Format-Table -?

48. Can you explain how to display more detailed help information about the Format-Table cmdlet.

Example:

>Get-Help Format-Table -Detailed

>Get-Help Format-Table –Full

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

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

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

52. How to get all background jobs in the current session?

The Get-Job command gets objects that represent the background jobs that were started within the current session. We can use <Get-Job> to get jobs that were started by using the <Start-Job> command, or by using the <AsJob> parameter of any command.

Example:

>Get-Job

53. How to stop a job by using an instance ID?

Example:

$j = Get-Job -Name Jobs1

$ID = $j.InstanceID

$ID

Stop-Job -InstanceId $ID

Guid

—-

03c3232e-1d23-453b-a6f4-ed73c9e29d56

54. How to investigate a failed job?

This command shows the way to use the “job” object that Get-Job returns to research why a “job” failed. It also shows the way to get the child/sub jobs of every job.

The first command line uses the “<Start-Job>” _cmdlet_ to start a job on local computer. The job object returned by the <Start-Job> shows that the job failed. The value of State property is “<Failed>”.

The second-command uses the “<Get-Job>” command to get the job. The command uses the dot method to urge the worth of the “.<JobStateInfo>” property of the (object). It uses a pipeline operator to send the (object) in the “.<JobStateInfo>” property to the “Format-List” _cmdlet_, it formats every properties of the (object) (*) in a list. The result of the <Format-List> command shows as that the value of the Reason property of the job is blank.

The third-command investigates more. It uses a “<Get-Job>” command to urge the job and then uses a <pipeline> (|) operator to send the entire job object to the <Format-List> _cmdlet_, it displays every properties of the job in a list. The display every properties within the job object shows that the job contains a child job named Job2_.

The fourth-command uses Get-Job to urge the job (object) that represents the Job2_ child job. This is the job in where the command really ran. It uses the dot method to urge the Reason property of the “.JobStateInfo” property. The result shows that the job failed due to an Access Denied error. In this case, the programmer/user forgot to use the <Run as administrator> option when starting Windows PowerShell. Because backend jobs use the remoting functionality of PowerShell, the system must be configured for remoting to execute a job, even when the job execute on the local system.

Example:

>Start-Job -ScriptBlock {Get-Process}

Id     Name       

.

.

>(Get-Job).JobStateInfo | Format-List -Property *

State  : Failed

Reason :

>Get-Job | Format-List -Property *

HasMoreData   : False

.

.

>(Get-Job -Name Job2_).JobStateInfo.Reason

-Connecting to remote server using WSManCreateShellEx api failed. The async callback gave the

-following error message: Access is denied.

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

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

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

58. How to get sessions connected to a computer?

Example:

>Get-PSSession -ComputerName “Servername”

The command <PSSessions> that are connected to the <”Servername”> system.

The command returns every sessions on <“Servername”>, even if they were created in different sessions or on different computers.

59. 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.*”

60. 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}

61. What are the benefits of PowerShell?

  • PowerShell is an <Object-Oriented> scripting language so reusability possible for all time.
  • PowerShell which serves more functions compared to <cmd.exe> and <VBScript>.
  • It supports fully Automation of tasks, so it is saving time.
  • It supports all .NET Objects and Forms
  • It supports all Background Jobs.

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

63. How to create new folder using PowerShell?

This syntax creates a new-folder C:\temp\NewFolder:

Example:

>New-Item -Path ‘C:\temp\NewFolder’ -ItemType Directory

64. How to create a file in powershell command?

This syntax creates a new-empty file C:\temp\NewFolder\file1.txt

Example:

>New-Item -Path ‘C:\temp\NewFolder\file1.txt’ -ItemType File

65. How do you removing All Files and Folders within a Folder?

This syntax removed every files and folders as below:

Example:

>Remove-Item -Path C:\temp\NewFolder

Confirm

The item at <C:\temp\NewFolder> has children and the Recurse parameter wasn’t specified. If you continue, all the children will be removed with the item. Are you sure if you want to continue?

[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is “Y”): N

66. 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:\temp\NewFolder –Recurse

67. How do you Mapping a Local Folder as a drive?

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

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

69. How to listing registry entries?

To see the names of the entries in the registry key <HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion>, 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_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion |

>Select-Object -ExpandProperty Property

70. 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_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion

71. How to get a single registry entry?

The example given finds the value of DevicePath in <HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion>.

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:\Software\Microsoft\Windows\CurrentVersion -Name DevicePath

72. How to set a single registry entry?

If you want to change a specific entry in a registry key, you can use one of several possible approaches. This example modifies the Path entry under HKEY_CURRENT_USER\Environment. The Path entry specifies where to find executable files.

  1. Retrieve the current value of the Path entry using Get-ItemProperty.
  2. Add the new value, separating it with a “;”.
  3. Use Set-ItemProperty with the specified key, entry name, and value to modify the registry entry.

Example:

>$value = Get-ItemProperty -Path HKCU:\Environment -Name Path

>$newpath = $value.Path += “;C:\source\bin\”

>Set-ItemProperty -Path HKCU:\Environment -Name Path -Value $newpath

73. How to listing all sub keys of a registry Key?

To show all items directly in a registry key by using Get-ChildItem. Add the optional Force parameter to display hidden or system items. 

Example:

>Get-ChildItem -Path HKCU:\ | Select-Object Name

74. How to Copying registry Keys?

Copying is done with <Copy-Item>. The following example copies CurrentVersion subkey of <HKLM:\SOFTWARE\Microsoft\Windows\. and all of its properties to HKCU:\.

Example:

>Copy-Item -Path ‘HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion’ -Destination HKCU:

If you examine the above new key in the registry editor or by using <Get-ChildItem>, you will notice that you do not have copies of contained subkeys in the new location. To copy all the contents of a container, you have to specify the Recurse parameter. For making the preceding copy command recursive, you will use the following command:

Example:

>Copy-Item -Path ‘HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion’ -Destination HKCU: -Recurse

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

76. 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’

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

78.  How do you create a custom, graphical input box using PowerShell ?

The script begins by loading two .NET Framework classes: System.Drawing and System.Windows.Forms. You then start a new instance of the .NET Framework class System.Windows.Forms.Form; that provides a blank form or window to which you can start adding controls.

Example:

>$form = New-Object System.Windows.Forms.Form

After you create an instance of the Form class, assign values to three properties of this class.

  • Text. This becomes the title of the window.
  • Size. This is the size of the form, in pixels. The preceding script creates a form that’s 300 pixels wide by 200 pixels tall.
  • StartingPosition. This optional property is set to CenterScreen in the preceding script. If you don’t add this property, Windows selects a location when the form is opened. By setting the StartingPosition to CenterScreen, you’re automatically displaying the form in the middle of the screen each time it loads.

>$form.Text = ‘Data Entry Form’

>$form.Size = New-Object System.Drawing.Size(300,200)

>$form.StartPosition = ‘CenterScreen’

Next, create an OK button for your form. Specify the size and behavior of the OK button. In this example, the button position is 120 pixels from the form’s top edge, and 75 pixels from the left edge. The button height is 23 pixels, while the button length is 75 pixels. The script uses predefined Windows Forms types to determine the button behaviors.

>$okButton = New-Object System.Windows.Forms.Button

>$okButton.Location = New-Object System.Drawing.Point(75,120)

>$okButton.Size = New-Object System.Drawing.Size(75,23)

>$okButton.Text = ‘OK’

>$okButton.DialogResult = [System.Windows.Forms.DialogResult]::OK

>$form.AcceptButton = $OKButton

>$form.Controls.Add($OKButton)

79. What are the new language features in PowerShell 5.0?

The New features are:

  • Class keyword

The class keyword defines a new class. This is a true .NET Framework type. Class members are public, but only public within the module scope.

class MyClass

{

    …

}

  • Enum keyword and enumerations

An enumerator value must be a parse time constant. You cannot set it to the result of an invoked command.

enum Color2

{

    Yellow = [Color]::Blue

}

enum MyEnum

{

    Enum1

    Enum2

    Enum3 = 42

    Enum4 = [int]::MaxValue

}

80. 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 }

81. How to Start Windows PowerShell on Earlier Versions of Windows?

The following steps shows:

  • From the Start Menu
  • Click Start, type PowerShell, and then click Windows PowerShell.
  • From the Start menu, click Start, click All Programs, click Accessories, click the Windows PowerShell folder, and then click Windows PowerShell.

At the Command Prompt

In cmd.exe, Windows PowerShell, or Windows PowerShell ISE, to start Windows PowerShell, type:

Example:

C:\>PowerShell

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

83. How to listing processor information?

To view general processor information by using WMI’s <Win32_Processor> class, although you will likely want to filter the information:

Example:

>Get-CimInstance -ClassName Win32_Processor | Select-Object -ExcludeProperty “CIM*”

84. How do you listing all installed hotfixes in PowerShell?

To list all installed hotfixes by using Win32_QuickFixEngineering:

Example:

Get-CimInstance -ClassName Win32_QuickFixEngineering

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

86. 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–

Conclusion

We hope this Powershell interview question helps you to crack the interview. Also, take up a free scripting course from a great learning academy and enhance your skill.

Also Read: DevOps Career Prospects

All The Best!

Avatar photo
Great Learning Team
Great Learning's Blog covers the latest developments and innovations in technology that can be leveraged to build rewarding careers. You'll find career guides, tech tutorials and industry news to keep yourself updated with the fast-changing world of tech and business.

Leave a Comment

Your email address will not be published. Required fields are marked *

Great Learning Free Online Courses
Scroll to Top