Bonnes pratiques PowerShell
En cours ...
Function Convert-RegistryFile { | |
<# | |
.SYNOPSIS | |
Convert a registry file (.reg) to a list of PSCustomObject. | |
.DESCRIPTION | |
Convert a registry file (.reg) to a list of PSCustomObject. | |
This function helps parsing registry files using the rules described in the following page: | |
https://support.microsoft.com/en-us/topic/how-to-add-modify-or-delete-registry-subkeys-and-values-by-using-a-reg-file-9c7f37cf-a5e9-e1cd-c4fa-2a26218a1a23 |
Function Test-RegistryPolCorruption { | |
[CmdletBinding()] | |
Param ( | |
[uint32]$Days = 25 | |
) | |
$Date = (Get-Date).AddDays(-$days) | |
$RegistryPol = 'C:\Windows\System32\GroupPolicy\Machine\registry.pol' | |
$RegistryPolFile = Get-Item -Path $RegistryPol -Force -EA Ignore | |
$Result = $false |
Function Get-MarkOfTheWeb { | |
<# | |
.SYNOPSIS | |
List the files that have a "Zone.Identifier" stream. | |
.DESCRIPTION | |
List the files that have a "Zone.Identifier" stream. | |
.PARAMETER Path | |
File or folder where to look for the stream. |
Function Write-ScriptSignature { | |
[CmdletBinding()] | |
[Alias('signs')] | |
Param ( | |
# Script(s) path or folder containing the PowerShell scripts to be signed | |
[Parameter(Mandatory, Position = 0, ValueFromPipeline,ValueFromPipelineByPropertyName)] | |
[Alias('FullName','LiteralPath')] | |
[String[]]$Path, | |
# Certificate issuer name |
[CmdletBinding()] | |
Param( | |
[Parameter(Mandatory, Position = 0)] | |
[String[]]$Path, | |
[Parameter(Position = 1)] | |
[ValidateSet('ascii','bigendianunicode','default','oem','string','unicode','unknown','utf7','utf8','utf8bom','utf32')] | |
[String]$Encoding = 'utf8bom', | |
[Switch]$Recurse |
[Environment+SpecialFolder]::GetNames([Environment+SpecialFolder]) | | |
Sort-Object | | |
Select-Object -Property @{Label = 'Name'; Expression = {$_}}, | |
@{Label = 'Path'; Expression = {[Environment]::GetFolderPath("$_")}} |
$Error.Clear() | |
$VerbosePreference = 'Continue' | |
#[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseCompatibleSyntax","", Scope = "Script", Target = "*")] | |
$wshell = New-Object -ComObject Wscript.Shell | |
#region logging | |
$InvocationScriptPath = $MyInvocation.PSCommandPath | |
if ([String]::IsNullOrEmpty($InvocationScriptPath)) { $InvocationScriptPath = $PSCommandPath } |
Function Write-Log { | |
<# | |
.SYNOPSIS | |
Fonction d'écriture de fichier de log. | |
.DESCRIPTION | |
Fonction d'écriture de fichier de log. | |
Cette fonction se sert de plusieurs variables publiques du script : | |
- $Error : Variable automatique PowerShell |
Bonnes pratiques PowerShell
En cours ...