I inherited a system where the previous admin made a dollar sign part of the folder name for the users home drive. He was thinking this would hide the folder from other users viewing it. He was confusing that with adding the $ to the share name. So the path looks something like \servername\userid$
These folders are all on two 2003 servers. We are combining them down to one location and using DFS on 2012R2 servers. We want to get rid of the dollar signs after moving the folders to the new server.
I want to trim the $ sign off or rename the folder I have been trying to use a one line code that looks like this
Get-ChildItem _ | Rename-Item -NewName { $.Name -replace '‘,’ ’ }
In my testing if the folder in question has the underscore and I want to replace it with a space it works no problem.
But if I change my folder name to have the $ it fails. The code looks like below and the error is shown below.
Code:
Get-ChildItem $ | Rename-Item -NewName { $_.Name -replace ‘$’,’ ’ }
Error message:
Rename-Item : Source and destination path must be different.
At line:1 char:21
- Get-ChildItem $ | Rename-Item -NewName { $_.Name -replace ‘$’,’ ’ }
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : WriteError: (E:\div\its\its\kenr\test_new\newdir3$:String) [Rena
me-Item], IOException - FullyQualifiedErrorId : RenameItemIOError,Microsoft.PowerShell.Commands.RenameItemComman
d
- CategoryInfo : WriteError: (E:\div\its\its\kenr\test_new\newdir3$:String) [Rena
Any thoughts, suggestions, code snipets…. Would be greatly appreciated.