Link to home
Start Free TrialLog in
Avatar of Dead_Eyes
Dead_EyesFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Powershell Irish curse

Hi all, this may be a simple one to answer but it's eluding me at the moment. I have quite a few users on a network I have inherited with surnames like O'Brian and O'Sullivan. This is making the use of simple arrays a nightmare. So put simply if I have an array like this:
$Array = @('JoeBrown',
'TomO'Brian',
'MattO'Sullican'
'SallySmith'
)

How can I escape the Apostrophe? I have tried numerous combinations of quotes, double quotes and backticks all to no avail
Avatar of Jeremy Weisinger
Jeremy Weisinger

You can use single quotes inside of double quotes.

$Array = @("JoeBrown",
"TomO'Brian",
"MattO'Sullican"
"SallySmith"
)

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Wasim Shaikh
Wasim Shaikh
Flag of United Arab Emirates image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Dead_Eyes

ASKER

Thanks guys and doh!, think when I tried that before I must have had multiple Apostrophes to close together. That or the usual IT sleep deprivation lol. Anyways thanks that's made the rest of the day a lot easier.
Btw: another way to turn strings into arrays would be to use a here-string and split it; saves even more quotes and commas (note that the closing quote of the here-string may not be indented):
$Array = @"
	JoeBrown
	TomO'Brian
	MattO'Sullican
	SallySmith
"@.Split("`r`n`t", [StringSplitOptions]::RemoveEmptyEntries)

Open in new window