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

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

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 handling – https://knowledge-junction.in/2024/01/26/powershell-tutorial-exploring-error-handling/
REFERENCES
- PowerShell – Interview preparation – 1 – https://knowledge-junction.in/2024/12/23/powershell-interview-preparation-1/
- Microsoft 365 : Detailed steps using Connect-PnPOnline with Client ID and X509 certificate – https://knowledge-junction.in/2024/11/19/m365-steps-for-connect-pnponline-clientid-n-x509-certificate/
- Microsoft 365 – Few approaches / options for Connecting to tenant using PnP PowerShell – Connect-PnPOnline – Part 1 – https://knowledge-junction.in/2021/12/16/microsoft-365-few-approaches-options-for-connecting-to-tenant-using-pnp-powershell-connect-pnponline-part-1/
- Microsoft 365 – Connecting to tenant using PnP PowerShell – Connect-PnPOnline – exploring DeviceLogIn (Device code flow) parameter- Part 2 – https://knowledge-junction.in/2021/12/18/microsoft-365-connecting-to-tenant-using-pnp-powershell-connect-pnponline-exploring-devicelogin-device-code-flow-parameter-part-2/
- PowerShell tutorial – exploring Error handling – https://knowledge-junction.in/2024/01/26/powershell-tutorial-exploring-error-handling/
- PowerShell tutorial – https://knowledge-junction.in/category/technology-articles/powershell-tutorial/
- https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_arrays?view=powershell-7.5
Thanks for reading!!!
HAVE A FANTASTIC TIME AHEAD !!! LIFE IS BEAUTIFUL 🙂

You must be logged in to post a comment.