I am trying to run some code if a string does not start with a certain character, however I can not get it to work with multiple characters.
This is the code that works fine.
if (-Not $recdata.StartsWith("1"))
{
//mycode.
}
What I want is multiple checks like this:
if (-Not $recdata.StartsWith("1") -Or -Not $recdata.StartsWith("2"))
{
//mycode.
}
But this does not work: it breaks the whole function even though PowerShell does not throw any errors.
if( $recdata -match '^[^12]' ) { # your code if it does not start with 1 and 2 }