Test-WithCulture
SYNOPSIS
Test your PowerShell code using a different culture.
SYNTAX
scriptblock (Default)
Test-WithCulture [-Culture] <CultureInfo> [-Scriptblock] <ScriptBlock> [-ArgumentList <Object[]>]
[<CommonParameters>]
file
Test-WithCulture [-Culture] <CultureInfo> -FilePath <ScriptBlock> [-ArgumentList <Object[]>]
[<CommonParameters>]
DESCRIPTION
When writing PowerShell commands, sometimes the culture you are running under becomes critical. For example, European countries use a different datetime format than North Americans which might present a problem with your script or command. Unless you have a separate computer running under the foreign culture, it is difficult to test. This command will allow you to test a scriptblock or even a file under a different culture, such as DE-DE for German.
Note that this command is not an absolute test. There may be commands that fail to produce the alternate culture results you expect.
EXAMPLES
Example 1
PS C:\> Test-WithCulture de-de -Scriptblock {(Get-Date).addDays(90)}
Montag, 14. Oktober 2020 08:59:01
Example2
PS C\> Test-WithCulture fr-fr -Scriptblock {
Get-winEvent -log system -max 500 |
Select-Object -Property TimeCreated,ID,OpCodeDisplayname,Message |
Sort-Object -property TimeCreated |
Group-Object {$_.timecreated.toshortdatestring()} -noelement
}
Count Name
----- ----
165 10/07/2020
249 11/07/2020
17 12/07/2020
16 13/07/2020
20 14/07/2020
26 15/07/2020
7 16/07/2020
PARAMETERS
-ArgumentList
Specify an array of positional arguments to pass to the scriptblock for file.
Type: System.Object[]
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-Culture
Enter a new culture like de-de
Type: System.Globalization.CultureInfo
Parameter Sets: (All)
Aliases:
Required: True
Position: 0
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-FilePath
Enter the path to a PowerShell script file to execute using the specified culture.
Type: System.Management.Automation.ScriptBlock
Parameter Sets: file
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-Scriptblock
Enter a scriptblock to execute using the specified culture. Be aware that long or complex pipelined expressions might not give you the culture-specific results you expect.
Type: System.Management.Automation.ScriptBlock
Parameter Sets: scriptblock
Aliases:
Required: True
Position: 1
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
INPUTS
None
OUTPUTS
System.Object
NOTES
Learn more about PowerShell: http://jdhitsolutions.com/blog/essential-powershell-resources/