Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| -Name | [string] | Optional | Name used in the greeting message. Defaults to M365 Lab. |
How It Works
Two steps: the script first writes a green greeting to the console with
Write-Host, then returns a PSCustomObject built from [Environment] and $PSVersionTable. It uses no modules and makes no changes, so it is safe to run anywhere — Windows PowerShell 5.1 or PowerShell 7 on Windows, macOS or Linux.
Execution policy: if PowerShell says running scripts is disabled, allow locally created and signed scripts for your user once with
Set-ExecutionPolicy -Scope CurrentUser RemoteSigned. Scripts downloaded from the internet may also need Unblock-File .\test-script.ps1.
Output — PSCustomObject
ComputerName[string]
UserName[string]
PowerShellVersion[string]
Edition[string]
OS[string]
Timestamp[string] yyyy-MM-dd HH:mm:ss
Examples
Example 1 — Run with defaults
PowerShell
.\test-script.ps1
Prints Hello, M365 Lab! Test script ran successfully. followed by the environment details.
Example 2 — Custom greeting
PowerShell
.\test-script.ps1 -Name "Saif"
Greets the given name: Hello, Saif! Test script ran successfully.
Example 3 — Sample output
Console
Hello, Saif! Test script ran successfully. ComputerName : LAB-WS01 UserName : saif PowerShellVersion : 7.4.6 Edition : Core OS : Microsoft Windows NT 10.0.22631.0 Timestamp : 2026-09-27 10:15:42
Illustrative output — values reflect the machine the script runs on.
Full Source
PowerShell · test-script.ps1
<# .SYNOPSIS Simple test script for Saif M365 Lab. .DESCRIPTION Prints basic environment details to confirm PowerShell scripts in the /scripts folder run and publish correctly. .EXAMPLE .\test-script.ps1 .\test-script.ps1 -Name "Saif" #> [CmdletBinding()] param ( [Parameter(Mandatory = $false)] [string]$Name = 'M365 Lab' ) Write-Host "Hello, $Name! Test script ran successfully." -ForegroundColor Green [PSCustomObject]@{ ComputerName = [Environment]::MachineName UserName = [Environment]::UserName PowerShellVersion = $PSVersionTable.PSVersion.ToString() Edition = $PSVersionTable.PSEdition OS = [Environment]::OSVersion.VersionString Timestamp = (Get-Date).ToString('yyyy-MM-dd HH:mm:ss') }