SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Enumerations in PoSh prior to V5


Enumerations in PoSh prior to V5

Author
Message
schleep
schleep
SSCrazy Eights
SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)

Group: General Forum Members
Points: 8825 Visits: 1511
I'm trying to create an enum of our SQL Servers

Add-Type -TypeDefinition @"
public enum OurServers3
{
Srv1,
Srv1\Instance1
}
"@



The backslash in the instance name is giving me headaches! Any ideas? I've tried escaping with ` and \, surrounding with double-quotes...

Any ideas?



Sue_H
Sue_H
SSC-Forever
SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)

Group: General Forum Members
Points: 47629 Visits: 12324
schleep - Friday, September 29, 2017 11:58 AM
I'm trying to create an enum of our SQL Servers

Add-Type -TypeDefinition @"
public enum OurServers3
{
Srv1,
Srv1\Instance1
}
"@



The backslash in the instance name is giving me headaches! Any ideas? I've tried escaping with ` and \, surrounding with double-quotes...

Any ideas?


You could also try using -
Encode-SqlName -SQLName "Srv1\Instance1"

Sue



schleep
schleep
SSCrazy Eights
SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)

Group: General Forum Members
Points: 8825 Visits: 1511
Oddly, my editor recognizes that alias for ConvertTo-EncodedSQLName, but I get cmdlet or function not found, when I try to use it outside of the here-string.
Still getting the same errors when i put that inside the here-string.



Sue_H
Sue_H
SSC-Forever
SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)

Group: General Forum Members
Points: 47629 Visits: 12324
schleep - Monday, October 2, 2017 5:52 AM
Oddly, my editor recognizes that alias for ConvertTo-EncodedSQLName, but I get cmdlet or function not found, when I try to use it outside of the here-string.
Still getting the same errors when i put that inside the here-string.


That is weird - not sure when that cmdlet came out as I'm kind of sick of trying to track Powershell versions all the time.
I guess the error makes sense as that would be for Powershell and your creating a .Net type. So could be two different ways to escape it. You could try to hard code in the Powershell encoding - replace the backslash with %5C but I am guessing you already did.
I thought the escaping in .net would be the backslash you already tried so I'm out of ideas.

Sue



schleep
schleep
SSCrazy Eights
SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)SSCrazy Eights (8.8K reputation)

Group: General Forum Members
Points: 8825 Visits: 1511
[quote]
Sue_H - Tuesday, October 3, 2017 3:27 PM


"...I'm kind of sick of trying to track Powershell versions all the time."


+10

---------
I've given up on this: I can validate server names other ways.

Thanks for taking the time, Sue.




Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search