Renaming files, folders, registry keys, and named values
When you are working with PowerShell scripts, you may have instances where you need to rename files, folders, and registry keys. The rename-item
cmdlet can be used to perform renaming operations on a system. The syntax for this cmdlet is rename-item
and specifying the –path
argument with path to the original object, and then you call the –newname
argument with a full path to what you want the item to be renamed to. The rename-item
has a –force
argument to force the rename in instances where the file or folder is hidden or restricted by UAC or to avoid prompting for the rename action.
To copy and rename files and folders, do the following action:
New-item –path "c:\Program Files\MyCustomSoftware\OldConfigFiles\" –ItemType Directory | out-null Rename-item –path "c:\Program Files\MyCustomSoftware\OldConfigFiles" –newname "c:\Program Files\MyCustomSoftware\ConfigArchive" -force copy-item –path "c:\Program Files\MyCustomSoftware\ConfigFile...