Runs in Powershell ISE not Powershell

Good afternoon,

I am very new to Powershell scripting and the below script is running in ISE, but not Powershell. I run both programs “As Administrator” and get the results I am looking for. When run in Powershell, it never finishes. Any assistance would be greatly appreciated!

 

$AccountLockOutEvent = Get-EventLog -LogName “Security” -InstanceID 4740 -Newest 1
$LockedAccount = $($AccountLockOutEvent.ReplacementStrings[0])
$AccountLockOutEventTime = $AccountLockOutEvent.TimeGenerated
$AccountLockOutEventMessage = $AccountLockOutEvent.Message
$messageParameters = @{
Subject = “Account Locked Out: $LockedAccount”
Body = “Account $LockedAccount was locked out on $AccountLockOutEventTime.`n`nEvent Details:`n`n$AccountLockOutEventMessage”
From = “test@test.com
To = “test@test.com
SmtpServer = “mail.test.com
}
Send-MailMessage @messageParameters

I removed my email addresses and SmtpServer address.

 

Thanks in advance for all of your help!!

Bill

From first look, I can’t see anything wrong here. Can you execute it line by line pasting it into console ?

Yes sir, I just did it again. Runs without error

How do you run this in ISE?

I mean by calling a script or with the script pane?

Can you please try to call the same script as for the PowerShell console?

You could try adding -Verbose to the Send-MailMessage command in the ISE and from the PowerShell host, see if there are any differences.