The escape character ()

In this context, is an escape character, but it is perhaps more accurate to say that changes the behavior of the character that follows. For example, finding a string that contains the normally reserved character, *, may be accomplished using , as follows:

'1 * 3' -match '*' 

In the following example, is used to escape the special meaning of , making it a literal character:

'domainuser' -match 'domain\user' 
'domainuser' -match '.*\.*' 

This technique may be used with -replace to change the domain prefix:

'domainuser' -replace 'domain', 'newdomain' 

Using alone will result in either an invalid expression or an unwanted expression. For example, the following expression is valid, but it doesn't act as you might expect. The . character is treated as a literal value because it is escaped. The following -match will return false:

'domainuser' -match 'domain.+' 

The following string will be matched by the previous expression, as the string contains a literal .:

'domain.user' -match 'domain.+' 

The -replace operator will allow access to parts of these strings as follows:

'DomainUser' -replace '.+'  # Everything up to and including  

Alternatively, it can -replace everything after a character:

'DomainUser' -replace '\.+' # Everything including and after  
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.219.63.90