# Define the path to the file
$filePath = "D:\file.txt"
# Get the current date and time
$currentDateTime = Get-Date -Format "yyyyMMdd-HHmmss"
# Get the base name of the file (without extension)
$baseName = [System.IO.Path]::GetFileNameWithoutExtension($filePath)
# Get the file extension
$fileExtension = [System.IO.Path]::GetExtension($filePath)
# Create the new file name with date and time
$newFileName = "{0}_{1}{2}" -f $baseName, $currentDateTime, $fileExtension
# Combine the new file name with the original file's directory
$newFilePath = [System.IO.Path]::Combine((Get-Item $filePath).DirectoryName, $newFileName)
# Rename the file
Rename-Item -Path $filePath -NewName $newFileName
Write-Host "File renamed to: $newFileName"