Hi @lupinlicious ,
I am not sure what is the content of variable $TBComputerName
. Is the content the computer name? Or is the computer name in $TBComputerName.text
...
Maybe you can check this and post the result here.
Please try this:
function Set-OSDComputerName {
$ErrorProvider.Clear()
$lastFour = $TBComputerName.text.substring($TBComputerName.text.length -4,4) # Get the last 4 characters of computer name
$badstring = select-string - path C:\deploymentshare$\bad_words.txt -pattern $lastfour
if ($badstring) {
$ErrorProvider.SetError($GBComputerName, "Computer name contains a bad word, not acceptable")
return
}
}
function Set-OSDComputerName {
if (Select-String -Path "C:\DeploymentShare$\bad_words.txt" -Pattern $TBComputerName.text.substring($TBComputerName.text.Length - 4, 4)) {
$ErrorProvider.SetError($GBComputerName, "Computer name contains a bad word, not acceptable")
return
}
}
----------
(If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)
Regards
Andreas Baumgarten