PowerShell – Interview preparation – 2

Hi All,

Greetings for the day!!!

On Microsoft 365 Junction I am sharing PowerShell questions to help us to prepare interviews.

This is second article in a list. Please check first set of interview questions – PowerShell – Interview preparation – 1 – https://knowledge-junction.in/2024/12/23/powershell-interview-preparation-1/

Q 1. How to declare array object in PowerShell?

  • An array is the Data Structure used to store the collection of items
  • Items in array can be of same type or of different types
  • Creating / Initializing an array
    • By assigning multiple values to variable

$Array = 22,5,10,8,12,9,80

  • We will declare empty array object in PowerShell like
           $ArrayObject = @() 

Q 2. How I will make sure “PnP.PowerShell” is installed?

  • We will use Get-Module CMDLET
Get-Module PnP.PowerShell
Making sure "PnP.PowerShell" module is installed
snap : Making sure “PnP.PowerShell” module is installed

Q 3. Which PnP CMDLET is used to connect the SharePoint site?

  • We will Connect-PnPOnline CMDLET
  • We have good detailed articles on Connect-PnPOnline PowerShell CMDLET. Please refer REFERENCE section.
#connect to the site
Connect-PnPOnline -Url $SiteURL

Q 4. Which CMDLET is used to read the items from the SharePoint list?

  • We will use Get-PnPListItem CMDLET

Get-PnPListItem -List <SharePoint list / library name>

#Get All Site Pages
$SitePages = Get-PnPListItem -List "Site Pages"

Q 5. What is New-Object ?

  • New-Object CMDLET is used to create new object
  • New-Object cmdlet was introduced in PowerShell v1.0
  • Creates an instance of a Microsoft .NET Framework or COM object
New-Object
   [-TypeName] <String>
   [[-ArgumentList] <Object[]>]
   [-Property <IDictionary>]
   [<CommonParameters>]


New-Object
   [-ComObject] <String>
   [-Strict]
   [-Property <IDictionary>]
   [<CommonParameters>]

Q 6. How to get all installed PowerShell modules in my system?

  • Using Get-Module with attribute – ListAvailable
PS C:\> Get-Module -ListAvailable

Q 7. How to view all commands from the module?

  • Get-Command PowerShell CMDLET is used to view all the commands from the given module.
  • Example: Lets see all the PowerShell CMDLET from the module – PnP.PowerShell

Command list output from the PowerShell module PnP.PowerShell, displaying command types, names, versions, and sources.
figure: Listing all the CMDLETs from the module “PnP.PowerShell” using Get-Command PowerShell CMDLET

Q 8. Which PowerShell module need to import for executing Exchange Online PowerShell CMDLETS?

  • ExchangeOnlineManagement PowerShell module

Q 9. How I see all blocked file types in Outlook using PowerShell?

  • We have PowerShell CMDLET – “Get-OwaMailboxPolicy ” from ExchangeOnlineManagement PowerShell module
  • Steps:
    • Make sure ExchangeOnlineManagement PowerShell module is installed
    • Import the ExchangeOnlineManagement PowerShell module
    • Connect to Exchange Online using PowerShell CMDLET – Connect-ExchangeOnline
    • Execute the PowerShell CMDLET – Get-OwaMailboxPolicy

PS C:\> $owamailboxpolicy = Get-OwaMailboxPolicy

PS C:\> $owamailboxpolicy.BlockedFileTypes

.settingcontent-ms
.printerexport
.appcontent-ms
.application
.appref-ms
.vsmacros
.website
.msh2xml
.msh1xml
.diagcab
.webpnp
.ps2xml
.ps1xml
.mshxml
.gadget
.theme
.psdm1
.mhtml
.cdxml
.xbap
.vhdx
.pyzw

Q 10. What is Error record in PowerShell?

  • In PowerShell, when exception / error occurs, it creates one error record
  • This error record contain error details like
    • Error message
    • Error stack trace
    • Error category
  • In catch block we could display / log error records with $_ as
    • $_.Exception.Message
    • $_.CategoryInfo
    • $_.FullyQualifiedErrorId
    • $_.ScriptStackTrace
  • By default error messages are stored in $Error array
  • Latest / most recent errors are is at index 0
  • When new error is occurred while executing our PowerShell CMDLET, it get stored at $Error [0] and index of other errors increases by 1

We have detailed article on PowerShell exception handling. PowerShell tutorial – exploring Error handlinghttps://knowledge-junction.in/2024/01/26/powershell-tutorial-exploring-error-handling/

REFERENCES

Thanks for reading!!!

HAVE A FANTASTIC TIME AHEAD !!! LIFE IS BEAUTIFUL 🙂

Prasham Sabadra

LIFE IS VERY BEAUTIFUL. ENJOY THE WHOLE JOURNEY :) Founder of Microsoft 365 Junction, Speaker, Author, Learner, Developer, Passionate Techie. Certified Professional Workshop Facilitator / Public Speaker. Believe in knowledge sharing. Around 20+ years of total IT experience and 17+ years of experience in SharePoint and Microsoft 365 services Please feel free me to contact for any SharePoint / Microsoft 365 queries. I am also very much interested in behavioral (life changing) sessions like motivational speeches, Success, Goal Setting, About Life, How to live Life etc. My book - Microsoft 365 Power Shell hand book for Administrators and Beginners and 100 Power Shell Interview Questions - https://www.amazon.in/Microsoft-Administrators-Beginners-Interview-Questions/dp/9394901639/ref=tmm_pap_swatch_0?_encoding=UTF8&qid=1679029081&sr=8-11

You may also like...

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Microsoft 365

Subscribe now to keep reading and get access to the full archive.

Continue reading