-1

We are migrating data from one filer to another and we have home directories setup for a bunch of users under their Active Directory profile. Some users have \\\x.x.x.x\sharename\etc, some have \\\hostname\sharename\etc and some have \\\hostname.domain.global\sharename\etc.

I need to replace the first portion of x.x.x.x, hostname and hostname.domain.global with the new DFS name of domain.global\sharename\etc, leaving everything else the same.

How can I go about doing this?

Thank you.

marc_s
  • 675,133
  • 158
  • 1,253
  • 1,388
nfoman
  • 15
  • 4
  • One thing I should mention, every user is unique in that after the \sharename in the example, they have some other folder afterwards so i cannot just change them all to \\\domain.global\sharename\.. – nfoman Sep 19 '17 at 19:07
  • I assume you mean that the new Dfs name is `domain.global` and not `domain.global\sharename\etc`? Please update your question with an example. – Bill_Stewart Sep 19 '17 at 20:41
  • Hello, yes the new DFS name is domain.global, eg.. old: \\hostname\sharename\etc new \\domain.global\sharename\etc – nfoman Sep 20 '17 at 20:20
  • You can use a regular expression (see my answer). – Bill_Stewart Sep 20 '17 at 20:33

1 Answers1

0

You should be able to use regular expressions. Examples:

PS C:\> '\\1.2.3.4\sharename1\etc1' |
  Select-String '^\\\\[^\\]+\\(.+)' |
  ForEach-Object { "\\domain.global\{0}" -f $_.Matches[0].Groups[1].Value }
\\domain.global\sharename1\etc1

PS C:\> '\\hostname\sharename2\etc2' |
  Select-String '^\\\\[^\\]+\\(.+)' |
  ForEach-Object { "\\domain.global\{0}" -f $_.Matches[0].Groups[1].Value }
\\domain.global\sharename2\etc2

PS C:\> '\\hostname.domain.global\sharename3\etc3' |
  Select-String '^\\\\[^\\]+\\(.+)' |
  ForEach-Object { "\\domain.global\{0}" -f $_.Matches[0].Groups[1].Value }
\\domain.global\sharename3\etc3

The regular expression pattern is:

^\\\\[^\\]+\\(.+)

This translates to: Start with (^) two \ characters, get 1 or more characters that are not \, followed by a single \, and then one or more characters (.+). The ( ) capture the path portion and make it available in the string replacement (i.e., $_.Matches[0].Groups[1].Value).

Bill_Stewart
  • 18,984
  • 4
  • 42
  • 53