PowerShell Interview Questions & Answers

  1. Question 1. What Powershell Scripting Is?

    Answer :

    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. Question 2. What Is The Function Of $input Variable?

    Answer :

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

  3. ASP.NET Interview Questions

  4. Question 3. How You Can Rename A Variable?

    Answer :

    To rename a variable,

    Rename-Item- Path Env: MyVariable –NewName MyRenamedVar

  5. Question 4. How You Can Convert The Object Into Html?

    Answer :

    To convert the object into HTML

    Get-Process l Sort-object – property CPU –descending l convert to – HTML l Out-file “process.html”

  6. ASP.NET Tutorial

  7. Question 5. What Is The Difference, In Powershell, Between A Function And An “advanced Function” ?

    Answer :

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

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

  8. Active Directory Interview Questions

  9. Question 6. You Have A Script Which Uses Read-host To Prompt The User For An Ip Address. You Need To Make Sure The User Inputs A Valid Ip Address. How Would You Do That ?

    Answer :

    A good candidate would probably use one of 2 ways :

    • Splitting the address in 4 elements and try to cast them to a [byte]
    • A regular expression

    A great candidate would use the much simpler and more robust method : let the .NET Framework do the hard work and just try to cast the input string to the [System.Net.IPAddress] class.

    By the way, the candidate should know that what we get from Read-Host is a [string].

  10. Question 7. How Would You Set A Registry Value With Powershell?

    Answer :

    Yeah, we start easy, but it is not that intuitive. This requires to know that there is no registry-specific cmdlets, so we have to use the registry provider and Set-ItemProperty.

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

  11. Microsoft Azure Tutorial
    Advanced Dot Net Interview Questions

  12. Question 8. What Argument Can Be Used To Convert An Object Into A String Or Convert The Property Of An Object Into The String?

    Answer :

    expand is the argument that should be used with the property name to convert an object property simply into a string.

    e.g Get-ADcomputer –filter * | select-Object –expand name

  13. Question 9. What Are Two Ways Of Extending Powershell?

    Answer :

    • PSSnapins
    • Modules
  14. SCCM Interview Questions

  15. Question 10. What Are The 4 Types Of Format Commands That Can Be Used To Format Data?

    Answer :

    • Format-Wide
    • Format-List
    • Format-Table
    • Format-Custom
  16. Windows 10 Tutorial

  17. Question 11. How Will You Check What Commands Have Been Added After Adding The New Snapin To Powershell ?

    Answer :

    Get-Command -pssnapin –> Lists all commands that got added when the snapin was added to the shell

  18. ActiveX Interview Questions

  19. Question 12. How Will You Check The Default Path For Powershell Modules ?

    Answer :

    Get-Content env:psmodulepath

  20. ASP.NET Interview Questions

  21. Question 13. What Is The Difference Between Convertto-csv And Export-csv Commands?

    Answer :

    ConvertTo-CSV is a one step process that only converts data into csv format and let it remain inside the shell Export-CSV is a 2 step process that not only converts data into CSV and also writes the output to a CSV format file.

  22. XML DOM Tutorial

  23. Question 14. How Would You Ping A Remote Computer With 5 Packets Using Powershell ?

    Answer :

    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.

  24. Question 15. What Are Cmdlet’s?

    Answer :

    Windows PowerShell introduces the concept of a cmdlet which are simple build in commands, written in a .net language like C# or VB.

  25. Microsoft Azure Interview Questions

  26. Question 16. Where Is Powershell Located In Sharepoint ?

    Answer :

    On the Start menu, click All Programs -> Click Microsoft SharePoint 2010 Products -> Click SharePoint 2010 Management Shell.

  27. Unix/Linux Tutorial

  28. Question 17. What Is Windows Powershell ?

    Answer :

    Windows PowerShell is a new Windows command-line shell designed especially for system administrators. In the SharePoint administration context, Windows PowerShell is another administration tool that supersedes the existing Stsadm.exe.

  29. Advanced C# Interview Questions

  30. Question 18. How Do You Comment Out Code In Powershell?

    Answer :

    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

           #>

  31. Active Directory Interview Questions