Skip to content

Instantly share code, notes, and snippets.

@ayoubzulfiqar
Last active June 10, 2023 10:44
Show Gist options
  • Select an option

  • Save ayoubzulfiqar/46ffaea0935dd89d98170abf8e50c7f9 to your computer and use it in GitHub Desktop.

Select an option

Save ayoubzulfiqar/46ffaea0935dd89d98170abf8e50c7f9 to your computer and use it in GitHub Desktop.
This Script create a new file and turn all the all the words into LowerCase and replace the space with underscore(_)
Param(
[Parameter(Mandatory=$true)]
[string]$FileName
)
# Convert the file name to lowercase
$NewFileName = $FileName.ToLower()
# Replace spaces with underscores
$NewFileName = $NewFileName -replace '\s', '_'
# Check if the file already exists
if (Test-Path -Path $NewFileName -PathType Leaf) {
Write-Output "File '$NewFileName' already exists."
# You can choose to skip the creation of the new file or rename the existing file here.
}
else {
# Create a new file with the modified name
$NewFile = New-Item -ItemType File -Path $NewFileName -ErrorAction Stop
# Output the new file name
Write-Output "New file created: $NewFileName"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment