New-RandomFileName
July 25, 2026 ยท View on GitHub
SYNOPSIS
Create a random file name.
SYNTAX
none (Default)
New-RandomFileName [-Extension <String>] [<CommonParameters>]
temp
New-RandomFileName [-Extension <String>] [-UseTempFolder] [<CommonParameters>]
home
New-RandomFileName [-Extension <String>] [-UseHomeFolder] [<CommonParameters>]
DESCRIPTION
Create a new random file name. The default is a completely random name including the extension. But you can also create a filename that includes either the TEMP folder or the user's home folder. In the case of a Windows system, the home folder will be the documents folder.
This command does not create the file, it only generates a name for you to use.
EXAMPLES
Example 1
PS C:\> New-RandomFileName
fykxecvh.ipw
Example 2
PS C:\> New-RandomFileName -extension dat
emevgq3r.dat
Specify a file extension.
Example 3
PS C:\> New-RandomFileName -extension log -UseHomeFolder
C:\Users\Jeff\Documents\kbyw4fda.log
Create a random file name using the user's home folder. In Windows, this will be the Documents folder.
Example 4
PS /mnt/c/scripts> New-RandomFileMame -home -Extension tmp
/home/jhicks/oces0epq.tmp
Create a random file name using the user's home folder on a Linux installation.
PARAMETERS
-Extension
Use a specific extension. Do not include the period.
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-UseHomeFolder
Include the user's HOME folder.
Type: SwitchParameter
Parameter Sets: home
Aliases: home
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-UseTempFolder
Include the TEMP folder.
Type: SwitchParameter
Parameter Sets: temp
Aliases: temp
Required: False
Position: Named
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 (http://go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
None
OUTPUTS
System.String
NOTES
Learn more about PowerShell: https://jdhitsolutions.com/yourls/newsletter