Powershell help

Associate
Joined
28 Oct 2002
Posts
1,819
Location
SE London
Heyas, I'm working on a script to do some checking for leavers in AD - all working fine apart from I can't get checking on a mail message that I am trying to get it to do where it'll notify me of the status of the job...

I want it to check through a variable, and see if it contains the word "bytes" and if it does, then send an email to my team, if not, do nothing. I've been testing with other words which appear in the variable but no dice. :/

Running this,

[PS] C:\Windows\system32>If ($disabledpeople -contains "*EV*") {
>> Write-Host "yay."
>> }
>>

Over this variable,

Code:
[PS] C:\Windows\system32>
[PS] C:\Windows\system32>
[PS] C:\Windows\system32>
[PS] C:\Windows\system32>$disabledpeople
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style>BODY{background-color:white;}BODY{font-size: 11px; font-family: tahoma;font-color:#041F92}TABLE{border-width: 0p
x;border-style: solid;border-color: black;border-collapse: collapse;}TH{border-width: 0px;padding: 1px;border-style: so
lid;border-color: black;Font-color: white;background-color: Black;}TD{border-width: 0px;padding: 1px;border-style: soli
d;border-color: black;background-color: LightBlue}</style>
</head><body>
<b>Check that they are zero'd out and EV is doing it's job, else manually run a pass over them</b><br />
<table>
</table>
</body></html>

Should have written to the console, "yay."

But it doesn't... any ideas why I can't parse for text inside this variable?
 
I prefer match to contains, this works for me:

Code:
$DisabledPeople = @"
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style>BODY{background-color:white;}BODY{font-size: 11px; font-family: tahoma;font-color:#041F92}TABLE{border-width: 0p
x;border-style: solid;border-color: black;border-collapse: collapse;}TH{border-width: 0px;padding: 1px;border-style: so
lid;border-color: black;Font-color: white;background-color: Black;}TD{border-width: 0px;padding: 1px;border-style: soli
d;border-color: black;background-color: LightBlue}</style>
</head><body>
<b>Check that they are zero'd out and EV is doing it's job, else manually run a pass over them</b><br />
<table>
</table>
</body></html>
"@

if ($DisabledPeople -match "EV")
{
	Write-Host "yay"
}
else
{
	Write-Host "neigh"
}
 
... any ideas why I can't parse for text inside this variable?

I'm guessing it is because your variable is not a string, how are you populating that variable?

Do...

$DisabledPeople.GetType()

and see what it returns.

edit: If it is a string then this should work...

$DisabledPeople.Contains('EV')
 
Last edited:
Back
Top Bottom