Created
December 2, 2025 05:36
-
-
Save Rapidhands/381b31b4e0034f2e343fc2fbd617cdd8 to your computer and use it in GitHub Desktop.
My Profile (version 2025/12/02) commented
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Write-Host 'Loading Profil' -ForegroundColor Yellow | |
| Write-Host 'Profil Loading Time : ' (Measure-Command { | |
| #region Settings to use TLS1.2 to update modules from PowershellGallery since 01 May 2020 | |
| Write-Host 'Setting : Use TLS1.2 to update modules from PowershellGallery since 01 May 2020' -ForegroundColor 'DarkGray' | |
| # ref : https://devblogs.microsoft.com/powershell/powershell-gallery-tls-support/ | |
| [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 | |
| #endregion Settings to use TLS1.2 to update modules from PowershellGallery since 01 May 2020 | |
| #region Location Settings | |
| Write-Host 'Setting : Location' -ForegroundColor 'DarkGray' | |
| $Profile_ScriptFolder = 'C:\Temp' | |
| if (Test-Path $Profile_ScriptFolder) | |
| { | |
| Set-Location -Path $Profile_ScriptFolder | |
| } | |
| #endregion Location Settings | |
| #region Default settings for some cmdlets | |
| #$PSDefaultParameterValues["CmdletName:ParameterName"]="DefaultValue" | |
| # ref : https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_parameters_default_values?view=powershell-5.1 | |
| Write-Host "Setting : Encoding using UTF8 for all cmdlets *:Encoding' = 'UTF8'" -ForegroundColor 'DarkGray' | |
| Write-Host 'Setting : Default Module installation with -Scope CurrentUser' -ForegroundColor 'DarkGray' | |
| Write-Host 'Setting : Test-NetConnection with -InformationLevel Detailed' -ForegroundColor 'DarkGray' | |
| Write-Host 'Setting : Test-Connection with -Count 1' -ForegroundColor 'DarkGray' | |
| Write-Host 'Setting : Export-Csv with -NoTypeInformation' -ForegroundColor 'DarkGray' | |
| Write-Host 'Setting : Export-Csv with -Delimiter ;' -ForegroundColor 'DarkGray' | |
| Write-Host 'Setting : EZlog with -LogFile' -ForegroundColor 'DarkGray' | |
| Write-Host 'Setting : EZlog with -Delimiter ; ' -ForegroundColor 'DarkGray' | |
| Write-Host 'Setting : EZlog with -ToScreen ' -ForegroundColor 'DarkGray' | |
| $PSDefaultParameterValues = @{ | |
| '*:Encoding' = 'UTF8' # PS5.1 defaults to ASCII | |
| 'Test-NetConnection:InformationLevel' = 'detailed' | |
| 'Test-Connection:Count' = '1' | |
| 'Export-Csv:delimiter' = ';' # ";" is the default delimiter for the .csv file in Fr culture | |
| 'Write-EZlog:LogFile' = $LogFile # Lazy config for PS Module EZLog | |
| 'Write-EZLog:Delimiter' = ';' # Lazy config for PS Module EZLog | |
| 'Write-EZLog:ToScreen' = $true # Lazy config for PS Module EZLog | |
| 'Get-WinEvent:LogName' = 'System' | |
| 'Out-Default:OutVariable' = 'LastResult' # Save output to $LastResult | |
| 'Export-Csv:NoTypeInformation' = $true # PS5.1 defaults to $false | |
| 'ConvertTo-Csv:NoTypeInformation' = $true # PS5.1 defaults to $false | |
| 'Receive-Job:Keep' = $true # Prevents accidental loss of output | |
| 'Install-Module:Scope' = 'CurrentUser' | |
| 'Install-Module:AllowClobber' = $true # Default behavior in Install-PSResource | |
| 'Install-Module:Force' = $true # Default behavior in Install-PSResource | |
| 'Install-Module:SkipPublisherCheck' = $true # Default behavior in Install-PSResource | |
| 'Group-Object:NoElement' = $true # Minimize noise in output | |
| '*-Module:Repository' = 'PSGallery' # Useful if you have private test repos with FInd-Module, Install-Module, FIn-PSResource, Install-PSResource | |
| } | |
| #endregion Default settings for some cmdlets | |
| #region "Settings to look/install modules from an Internal repository | |
| <# | |
| Write-Host "Setting to look for modules in an Internal repository" -ForegroundColor 'DarkGray' | |
| $PSDefaultParameterValues["Find-Module:Repository"] = 'MyRepository' | |
| Write-Host "Setting to install modules from the Internal Repository" -ForegroundColor 'DarkGray' | |
| $PSDefaultParameterValues["Install-Module:Repository"] = 'MyRepository' | |
| #> | |
| #endregion Settings to look/install modules from an Internal repository | |
| #region Prompt setting | |
| Write-Host 'Setting : Prompt' -ForegroundColor 'DarkGray' | |
| function Get-Time | |
| { | |
| return (Get-Date).ToLongTimeString() | |
| } | |
| function prompt | |
| { | |
| # Write the time | |
| Write-Host '[' -NoNewline | |
| Write-Host $(Get-Time) -foreground yellow -NoNewline | |
| Write-Host '] ' -NoNewline | |
| # Write the path | |
| Write-Host $($(Get-Location).Path.replace($home, '~').replace('\', '/')) -foreground green -NoNewline | |
| Write-Host $(if ($nestedpromptlevel -ge 1) | |
| { | |
| '>>' | |
| }) -NoNewline | |
| return '> ' | |
| } | |
| prompt | |
| #endregion Prompt Setting | |
| #region Custom Windows Setting | |
| Write-Host 'Setting : Windows Title' -ForegroundColor 'DarkGray' | |
| [System.Security.Principal.WindowsPrincipal]$CurrentUser = New-Object System.Security.Principal.WindowsPrincipal([System.Security.Principal.WindowsIdentity]::GetCurrent()) | |
| if ( $CurrentUser.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator) ) # S-1-5-32-544 is the Well-Known SID for Administrators (builtin) group | |
| { | |
| # Admin mode | |
| $User = '(RunAsAdmin) - ' + $CurrentUser.Identities.Name | |
| } | |
| else | |
| { | |
| # User mode | |
| $user = '(NotRunAsAdmin) - ' + $CurrentUser.Identities.Name | |
| } | |
| (Get-Host).UI.RawUI.WindowTitle = $user + ' on ' + [System.Net.Dns]::GetHostName() + ' (PS version : ' + (Get-Host).Version + ')' | |
| #endregion Custom Windows Setting | |
| #region Setting Alias for NP and NPP | |
| Write-Host 'Setting : Alias for Notepad, Notepad++, and Test-Connection' -ForegroundColor 'DarkGray' | |
| Set-Alias -Name npp -Value 'C:\Program Files\Notepad++\notepad++.exe' # 'C:\Program Files (x86)\Notepad++\notepad++.exe' | |
| Set-Alias -Name np -Value 'C:\Windows\system32\notepad.exe' | |
| Set-Alias -Name ping -Value Test-Connection | |
| #endregion Setting Alias for NP and NPP | |
| #region Show GUI | |
| $IPAddress = @(Get-CimInstance -ClassName Win32_NetworkAdapterConfiguration | Where-Object { $_.DefaultIpGateway })[0].IPAddress[0] | |
| Write-Host '# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++' -ForegroundColor Yellow | |
| Write-Host '# + ' -ForegroundColor Yellow -NoNewline; Write-Host '++++++++++' | |
| Write-Host '# + ' -ForegroundColor Yellow -NoNewline; Write-Host "++ ++++++`tHi $($env:UserName)!" | |
| Write-Host '# + ' -ForegroundColor Yellow -NoNewline; Write-Host '+++ +++++' | |
| Write-Host '# + ' -ForegroundColor Yellow -NoNewline; Write-Host "++++ ++++`tComputerName`t`t`t`t" -NoNewline; Write-Host $($env:COMPUTERNAME) -ForegroundColor Cyan | |
| Write-Host '# + ' -ForegroundColor Yellow -NoNewline; Write-Host "++++ ++++`tAdresse IP`t`t`t`t`t" -NoNewline; Write-Host $IPAddress -ForegroundColor Cyan | |
| Write-Host '# + ' -ForegroundColor Yellow -NoNewline; Write-Host "+++ +++++`tNom Utilisateur`t`t`t`t" -NoNewline; Write-Host $env:UserDomain\$env:UserName -ForegroundColor Cyan | |
| Write-Host '# + ' -ForegroundColor Yellow -NoNewline; Write-Host "++ ++`tVersion de PowerShell `t`t" -NoNewline; Write-Host $((Get-Host).Version) -ForegroundColor Cyan | |
| Write-Host '# + ' -ForegroundColor Yellow -NoNewline; Write-Host "++++++++++`tExecutionPolicy `t`t`t" -NoNewline; Write-Host $(Get-ExecutionPolicy) -ForegroundColor Cyan | |
| Write-Host '# + ' -ForegroundColor Yellow -NoNewline; Write-Host '++++++++++' | |
| Write-Host "# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++`n" -ForegroundColor Yellow | |
| #endregion Show GUI | |
| #region Udpate-Help every Friday | |
| $Date = Get-Date | |
| if ($Date.DayOfWeek -eq 'friday') | |
| { | |
| Write-Host 'Update-Help in a background job (Get-job to check)' -ForegroundColor 'DarkGray' | |
| Start-Job -Name 'UpdateHelp' -ScriptBlock { Update-Help } | Out-Null | |
| } | |
| #endregion Udpate-Help every Friday | |
| #region Udpate-Module every Friday | |
| $Date = Get-Date | |
| if ($Date.DayOfWeek -eq 'friday') | |
| { | |
| Write-Host 'Update-Module in a background job (Get-job to check)' -ForegroundColor 'DarkGray' | |
| Start-Job -Name 'UpdateModule' -ScriptBlock { | |
| function Update-MyModule | |
| { | |
| [CmdletBinding(SupportsShouldProcess)] | |
| [Alias()] | |
| [OutputType([String])] | |
| param | |
| ( | |
| # Description d’aide param1 | |
| [Parameter(Mandatory = $true)] | |
| [ValidateSet('CurrentUser', 'AllUsers')] | |
| $Scope | |
| ) | |
| begin | |
| { | |
| $InstalledModules = Get-InstalledPSResource -Scope $Scope | |
| } | |
| process | |
| { | |
| # initiating counter | |
| $counter = 0 | |
| foreach ($Item in $InstalledModules) | |
| { | |
| $LastVersion = (Find-PSResource -Name $item.Name).Version | |
| if ([Version]$LastVersion -gt [version]$Item.Version) | |
| { | |
| Write-Verbose "$LastVersion is greater than $($Item.Version) for $($item.name)" | |
| Find-PSResource -Name $($item.Name) | Update-PSResource -Scope $Scope -Force -SkipDependencyCheck | |
| Write-Color "$($Item.Name) ", 'has been updated from ', "$($Item.Version) ", 'to ', "$Lastversion" -Color Yellow, Green, Yellow, Green, Yellow | |
| $counter++ | |
| Write-Verbose "removing old version for $($item.Name)" | |
| Uninstall-PSResource -Name $($item.Name) -Version $($item.Version) -Scope $Scope -SkipDependencyCheck | |
| } | |
| } | |
| } | |
| end | |
| { | |
| Write-Color "$counter ", 'modules has been updated for ', "$Scope" -Color Yellow, Green, Yellow | |
| } | |
| } | |
| Update-MyModule -Scope CurrentUser | |
| Update-MyModule -Scope AllUsers | |
| } | Out-Null | |
| } | |
| #endregion Udpate-module every Friday | |
| #region Update SysternalsSuite 1st of the month | |
| if ($Date.Day -eq '1') | |
| { | |
| Write-Host 'Update Systernal Suite' -ForegroundColor DarkGray | |
| $SysternalSuite = Start-Job -Name SysternalSuite -ScriptBlock { . C:\Scripts\Install-SysInternalsSuite.ps1 } | |
| } | |
| #endregion Update SysternalsSuite 1st of the month | |
| #region Learn something today (show help about a ramdom cmdlet) | |
| <# | |
| Write-Host "Learn something today (show help about a ramdom cmdlet)" -ForegroundColor 'DarkGray' | |
| Get-Command -Module * | Get-Random | Get-Help -ShowWindow | |
| #> | |
| #endregion Learn something today (show help about a ramdom cmdlet) | |
| }).Milliseconds 'ms' -ForegroundColor Cyan | |
| Get-Job | |
| Write-Host 'Fully loaded profile' -ForegroundColor Yellow | |
| #region receive jobs when they are finished | |
| Get-Job | Wait-Job | Receive-Job | Remove-Job | |
| #endregion receive jobs when they are finished |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment