PowerShell Notebook

PS C:\> Get-AzContext | FL
Name               : AD09 (bbf658dc-12dd-4f6a-b2bc-7c379632c9b7) - 615dc844-35d3-40c2-9db4-0439991ec82e
Account            : 
Environment        : AzureCloud
Subscription       : bbf658dc-12dd-4f6a-b2bc-7c379632c9b7
Tenant             : 615dc844-35d3-40c2-9db4-0439991ec82e

PS C:\> $Sub = "$($(Get-AzContext).Subscription)"
PS C:\> $Sub
bbf658dc-12dd-4f6a-b2bc-7c379632c9b7
irm bonguides.com/pw/nerdfonts | iex
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
irm https://bonguides.com/wsb/winget | iex
irm https://bonguides.com/choco | iex

#Set-ExecutionPolicy Bypass -Scope Process -Force
#irm https://community.chocolatey.org/install.ps1 | iex

Write-Host

Show value in array with Write-Host

$Mailboxes = Get-Mailbox -ResultSize Unlimited -RecipientTypeDetails UserMailbox | Select-Object UserPrincipalName
$Report=@()
ForEach($Mailbox in $Mailboxes) {
$llt = Get-MailboxStatistics -Identity $Mailbox.UserPrincipalName | Select-Object DisplayName,LastLogonTime
Write-Host "Processing the mailbox: $($Mailbox.UserPrincipalName)"

Write-Progress

$Mailboxes = Get-Mailbox -ResultSize 10 -RecipientTypeDetails UserMailbox | Select-Object UserPrincipalName
$Report=@()
$i = 1
ForEach($Mailbox in $Mailboxes) {
$llt = Get-MailboxStatistics -Identity $Mailbox.UserPrincipalName | Select-Object DisplayName,LastLogonTime | Sort-Object LastLogonTime

$Obj = New-Object -TypeName PSObject -Property $([ordered]@{
        "DisplayName" = $llt.DisplayName
        "EmailAddress" = $Mailbox.UserPrincipalName
        "LastLogonTime" = $llt.LastLogonTime
    })

Write-Progress `
    -Activity "Scanning mailboxes . . ." `
    -Status "Scanned: $i of $($Mailboxes.Count)" `
    -PercentComplete (($i / $Mailboxes.Count)  * 100)
    
Start-Sleep -Milliseconds 300
$Report+=$Obj
$i++  
}
$Report

Building a report

$Mailboxes = Get-Mailbox -ResultSize Unlimited -RecipientTypeDetails UserMailbox | Select-Object UserPrincipalName
$Report=@()

ForEach($Mailbox in $Mailboxes) {
$llt = Get-MailboxStatistics -Identity $Mailbox.UserPrincipalName | Select-Object DisplayName,LastLogonTime | Sort-Object LastLogonTime
Write-Host "Scanning the mailbox: $($Mailbox.UserPrincipalName)" -ForegroundColor Yellow
#Creating the report
$Obj = New-Object -TypeName PSObject -Property $([ordered]@{
        "DisplayName" = $llt.DisplayName
        "EmailAddress" = $Mailbox.UserPrincipalName
        "LastLogonTime" = $llt.LastLogonTime
    })

$Report+=$Obj
}
$Report

Navigate to the current user desktop folder.

PS C:\> cd ~/Desktop\
PS C:\Users\Administrator\Desktop>

Variable in the middle of string

$fileName = "Microsoft.WindowsTerminal_Win10_$($version)_8wekyb3d8bbwe.msixbundle"
$fileName
Microsoft.WindowsTerminal_Win10_1.16.10261.0_8wekyb3d8bbwe.msixbundle

Array

$packages = @("Microsoft.VCLibs","DesktopAppInstaller","UI.Xaml")
ForEach ($package in $packages){Get-AppxPackage -Name *$package* | select Name,Version,Status }

Name                               Version        Status
----                               -------        ------
Microsoft.VCLibs.140.00.UWPDesktop 14.0.30704.0       Ok
Microsoft.DesktopAppInstaller      1.19.10173.0       Ok
Microsoft.UI.Xaml.2.7              7.2109.13004.0     Ok

How to Assign Multiple Values To A Variable In PowerShell

PS C:\> $list = Get-ChildItem -Name C:\dir1
PS C:\> $list += Get-ChildItem -Name C:\dir2
PS C:\> $list
file1.txt
file2.txt
file3.txt
file4.txt
PS C:\> Write-Host "Your Windows edition: $((Get-ComputerInfo).WindowsProductName)"
Your Windows edition: Windows 10 Pro
Get-AppXPackage *Microsoft.DesktopAppInstaller* -AllUsers | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"}
PS C:\Users\admin\Downloads\LTSC-Add-MicrosoftStore-2019\microsoftstore-win-ltsc> Get-ChildItem | Where-Object { $_.Name -match '^*Microsoft.NET.Native*|^*VCLibs*' }


    Directory: C:\Users\admin\Downloads\LTSC-Add-MicrosoftStore-2019\microsoftstore-win-ltsc


Mode                 LastWriteTime         Length Name                                                                                                                                                         
----                 -------------         ------ ----                                                                                                                                                         
-a----         2/25/2023   7:07 AM        2887365 Microsoft.NET.Native.Framework.1.6_1.6.24903.0_x64__8wekyb3d8bbwe.Appx                                                                                       
-a----         2/25/2023   7:07 AM        2615886 Microsoft.NET.Native.Framework.1.6_1.6.24903.0_x86__8wekyb3d8bbwe.Appx                                                                                       
-a----         2/25/2023   7:07 AM         248709 Microsoft.NET.Native.Runtime.1.6_1.6.24903.0_x64__8wekyb3d8bbwe.Appx                                                                                         
-a----         2/25/2023   7:07 AM         204546 Microsoft.NET.Native.Runtime.1.6_1.6.24903.0_x86__8wekyb3d8bbwe.Appx                                                                                         
-a----         2/25/2023   7:07 AM         848261 Microsoft.VCLibs.140.00_14.0.26706.0_x64__8wekyb3d8bbwe.Appx                                                                                                 
-a----         2/25/2023   7:07 AM         698980 Microsoft.VCLibs.140.00_14.0.26706.0_x86__8wekyb3d8bbwe.Appx    
PS C:\Users\admin\Downloads\LTSC-Add-MicrosoftStore-2019\microsoftstore-win-ltsc> Get-ChildItem | Where-Object { ($_.Name -like '*WindowsStore*') -and ($_.Name -like '*AppxBundle*') }


    Directory: C:\Users\admin\Downloads\LTSC-Add-MicrosoftStore-2019\microsoftstore-win-ltsc


Mode                 LastWriteTime         Length Name                                                                                                                                                         
----                 -------------         ------ ----                                                                                                                                                         
-a----         2/25/2023   7:07 AM       50262573 Microsoft.WindowsStore_11809.1001.713.0_neutral_~_8wekyb3d8bbwe.AppxBundle  
$SecurePass = ConvertTo-SecureString -String "1PassWord@" -AsPlainText -Force