locked
Rename Folder Using Filter Function RRS feed

  • Question

  • I want my script to be built similarly to this;

    Get-ChildItem C:\Users\$ENV:UserName\AppData\Roaming\Microsoft\Signatures\ -Recurse -Filter *_fi
    les* | Rename-Item -NewName { $_.name -replace '_files', 'signature_files'}

    My issue is that, I need to change a line of text inside of about 1000 users signature on Outlook. I have made a script to do this, however when I save that Signature.htm file, the signature_files inside of that directory above does not match and Outlook freaks out so I have to match the _files folder to match the signature.htm file. 

    Issue with the script above is that, when I "Rename" that item it does not replace the entire directory name, only "_files" because this name is not static it could be "signature_files, sig_files, 1_files" just depends on what the user saves their signature as. Is there a way to specify after searching for the desired directory using "filter" to change the entire name?

    I can't change the name of a directory that I don't know the name of. I want to search for the static name of "_files" select that directory, and edit the name of that directory.

    Pls help :[ 

    Monday, November 5, 2018 8:20 PM

All replies

  • Renaming the files will remove the signature form the users settings.


    \_(ツ)_/

    Monday, November 5, 2018 9:42 PM
  • It works for me.  Maybe you can demo your problem with an example and error message.  Even though the containing folder foo2 gets renamed, the file inside heyo gets renamed successfully.  The top folder foo is not processed.

    PS C:\users\admin> ls -r foo -filter *o* | rename-item -NewName { $_.name -replace 'o','0' } -whatif

    What if: Performing the operation "Rename Directory" on target "Item: C:\users\admin\foo\foo2 Destination: C:\users\admin\foo\foo2".
    What if: Performing the operation "Rename File" on target "Item: C:\users\admin\foo\foo2\heyo Destination: C:\users\admin\foo\foo2\heyo".
    Tuesday, November 6, 2018 5:24 PM
  • If you are updating the existing .htm files I don't see why you need to rename the existing directories.  Are you saving the updated .htm file as a different name?
    Tuesday, November 6, 2018 6:36 PM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Lee


    Just do it.

    Friday, November 9, 2018 9:19 AM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Lee


    Just do it.

    Tuesday, November 27, 2018 2:07 AM