external help file | Module Name | online version | schema |
---|---|---|---|
PSScriptTools-help.xml |
PSScriptTools |
2.0.0 |
Test your PowerShell code using a different culture.
Test-WithCulture [-Culture] <CultureInfo> [-Scriptblock] <ScriptBlock>
[-ArgumentList <Object[]>] [<CommonParameters>]
Test-WithCulture [-Culture] <CultureInfo> -FilePath <ScriptBlock>
[-ArgumentList <Object[]>] [<CommonParameters>]
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.
PS C:\> Test-WithCulture de-de -Scriptblock {(Get-Date).addDays(90)}
Montag, 14. Oktober 2020 08:59:01
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
Specify an array of positional arguments to pass to the scriptblock for file.
Type: Object[]
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
Enter a new culture like de-de
Type: CultureInfo
Parameter Sets: (All)
Aliases:
Required: True
Position: 0
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
Enter the path to a PowerShell script file to execute using the specified culture.
Type: ScriptBlock
Parameter Sets: file
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
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: ScriptBlock
Parameter Sets: scriptblock
Aliases:
Required: True
Position: 1
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
Learn more about PowerShell: http://jdhitsolutions.com/blog/essential-powershell-resources/