I was designing my own function which renames the .ps1 file to .psm1 with the same name of .ps1 file.
Example: Add-UdfUser.ps1
will become Add-UdfUser.psm1
.
It works completely fine. It changes the name with same name of .ps1 file.
Only problem is that when you echo $PSFileName renamed to $NewName or echo the file $PSFileName does not exist it doesn't gets printed on the screen unless you use break statement.
Can somebody tell me why is this happening and any alternative method to fix this?
Here is the code for the reference -
Function Rename-UdfFunction{
[cmdletbinding()]
Param(
[Parameter(Mandatory)]
[String]$PSFileName,
[Parameter(Mandatory)]
[String]$UdfModulePath
)
[String]$SplitName = $PSFileName -split '.ps1' | ForEach-Object {
if ((get-childitem -name -path $UdfModulePath) -match $PSFileName ){
[String]$NewName = $_.TrimEnd()+'.psm1'
Rename-Item -Path $UdfModulePath\$PSFileName -NewName $NewName
echo "$PSFileName renamed to $NewName"
#break
}else{
echo "The file $PSFileName doesnot exist"
#break
}
}
}