- Function names should use singular nouns (e.g.,
Get-Item, notGet-Items) unless the function always returns multiple items. This improves clarity and aligns with PowerShell naming conventions.
Example:
# Good| $frameWorkList = 'Microsoft.WindowsAppRuntime', 'Microsoft.UI.Xaml', 'Microsoft.VCLibs', 'Microsoft.NET.Native.Runtime', 'Microsoft.NET.Native.Framework', 'Microsoft.WindowsAppRuntime.CBS' | |
| foreach ($framework in $frameWorkList) { | |
| if($framework -eq 'Microsoft.WindowsAppRuntime') { | |
| $download = 'Microsoft.WindowsAppSDK' | |
| } | |
| else{ | |
| $download = $framework | |
| } |
| $shapeName = 'Rounded Rectangle 664' | |
| Add-type -AssemblyName office | |
| $Application = New-Object -ComObject powerpoint.application | |
| $application.visible = [Microsoft.Office.Core.MsoTriState]::msoTrue | |
| $powerpointFile = "D:\PoSHCode\GitLocal\PowerPoint\RandomLogoff3.pptx" | |
| $presentation = $application.Presentations.open($powerpointFile) |
| $Path = 'c:\myicon.png' | |
| $Bytes = get-content $Path -AsByteStream -Raw | |
| $inputFromBase64conv = [convert]::ToBase64String($Bytes) | |
| $out = [System.Convert]::FromBase64String($inputFromBase64conv) | |
| Write-Output $out |
| $stopwatch = [system.diagnostics.stopwatch]::StartNew() | |
| while ($true) { $stopwatch.Elapsed.ToString().SubString(0, 8); Start-Sleep 1; Clear-Host} |
| function Get-WpmRestApp { | |
| [CmdletBinding()] | |
| Param ( | |
| [Parameter( | |
| Position = 0, | |
| ValuefromPipelineByPropertyName = $true, | |
| ValuefromPipeline = $true, | |
| Mandatory = $true |
| $cmdletName -cmatch "^(?:[A-Z]{1,3}(?:[a-z0-9_])+)+[A-Z]{0,2}-(?:[A-Z]{1,3}(?:[a-z0-9_])+)+[A-Z]{0,2}$" | |
| $parameterName -cmatch '^(?:[A-Z]{1,3}(?:[a-z0-9_])+)+[A-Z]{0,2}$' |
| <# | |
| If the email is in the format below | |
| Jim Moyle <[email protected]> | |
| it will be cleaned up by the replace regex to this one: | |
| [email protected] | |
| #> |
| $diskCompactionEvents = Get-WinEvent -FilterHashtable @{ | |
| LogName = 'Microsoft-FSLogix-Apps/Operational' | |
| ID = 57 | |
| } | |
| foreach ($event in $diskCompactionEvents) { | |
| $out = [PSCustomObject]@{ | |
| ImagePath = $event.Properties[0].Value | |
| 'TimeTaken(ms)' = $event.Properties[7].Value | |
| 'InitialSize(MB)' = $event.Properties[4].Value |
| #Requires -RunAsAdministrator | |
| #Requires -Modules 'Hyper-V' | |
| # Once this has been run once, you will be able to use the Invokle-ShrinkFslDisk tool to get max shrink from all disks, without having to copy. | |
| # Required Services = 'defragsvc', 'vds', 'smphost' ! This script will fail if you don't have these services running ! | |
| # Change the source and target path as needed | |
| # Run from a VM with FSLogix installed | |
| # Does not need to be run on a FileServer | |