PowerShell – Interview preparation – 1
Hi All,
Greetings for the day!!!
On Microsoft 365 Junction, I am starting the series for PowerShell interview preparation. Today sharing first article in this series. I’ll keep updating this list.
Feel free to discuss any PowerShell related question or topic. Happy to write an article. Just mention your topic in comment section.
Q. What standard should be followed while naming PowerShell script CMDLETs?
- PowerShell uses a verb-and-noun name pair to name CMDLETs
- For example, the
Get-CommandCMDLET is included in PowerShell. It is used to get all the CMDLETs registered in the command shell. - The verb identifies the action that the CMDLET performs.
- The noun identifies the resource on which the CMDLET performs its action.
Q. What are PowerShell modules ?
- A PowerShell module can be defined as a set of PowerShell functions, CMDLETs.
- These are grouped to manage all the aspects of a particular feature.
- In more simple terms its package of PowerShell functions, CMDLETs, variables, providers, aliases, and workflows (basically PowerShell members).
- These modules then used as reference in other PowerShell scripts.
- We can share these PowerShell modules with others.
- Example: We see all installed module using – Get-Module CMDLET
For more details on PowerShell Modules, please have a look – PowerShell – Exploring Module CMDLETs – https://knowledge-junction.in/2022/12/12/__trashed-2/
Q. In PowerShell script, how to check if module is already imported or not?
- We can use “Get-Module” CMDLET to verify if given PowerShell module is imported or not.
- Next is sample code:
if ( -not (Get-Module -ListAvailable -Name PnP.PowerShell)) {
Write-Host "Module is not imported"
Import-Module PnP.PowerShell
} #if ( -not (Get-Module -ListAvailable -Name PnP.PowerShell))
else
{
Write-Host "Module is imported"
}
Q. How to add regions to PowerShell script ?
- In Windows PowerShell 3.0 one of the feature is added to Microsoft PowerShell ISE is region feature.
- Region feature allows us to mark the section in the script that will collapse and expand.
- We can start the region by using # sign and “region” keyword.
#region variable declarations
- Code which we want to include the region.
- end the region with “endregion” keyword
#endregion
Example:Below is the sample code for declaring variables in PowerShell script
#region Variable declarations
$adminUrl = "https://knowledgejunction1-admin.sharepoint.com"
$intranetUrl = "https://knowledgejunction1.sharepoint.com/"
$CSVFilePath = "C:\\csvfilepath.csv"
#endregion
Q. Which PowerShell CMDLET is used to write the data to the CSV file
- Export-CSV CMDLET is used to write the data / content to CSV file.
- The Export-CSV CMDLET is very simple and only has a few properties that are useful:
- Path – (Required) Location of the CSV file
- NoTypeInformation – Removes the type information header from the output. Not needed any more in PowerShell 6
- Delimiter – Default is comma, but we can change it
- Append – Append to an existing CSV file
- Force – Useful in combination with Append
- NoClobber – Don’t overwrite existing files
- UseQuotes – (PowerShell 7 only) wrap values in quotes or not
- For more details on Export-CSV CMDLET, please have a look our article. PowerShell tutorial – Write a CSV file with PowerShell using the Export-CSV – https://knowledge-junction.in/2022/10/31/write-a-csv-file-with-powershell-using-the-export-csv-function/
Q. How to know the current version of PowerShell on my system ?
- Using $PSVersionTable variable

REFERENCES
- PowerShell – Exploring Module CMDLETs – https://knowledge-junction.in/2022/12/12/__trashed-2/
- PowerShell tutorial – Write a CSV file with PowerShell using the Export-CSV – https://knowledge-junction.in/2022/10/31/write-a-csv-file-with-powershell-using-the-export-csv-function/
Thank you🙂 Life is Beautiful🙂
Have a nice day🙂🙂

1 Response
[…] This is second article in a list. Please check first set of interview questions – PowerShell – Interview preparation – 1 – https://microsoft365junction.com/2024/12/23/powershell-interview-preparation-1/ […]