Forum Discussion
dmarquesgn
Mar 17, 2022Iron Contributor
Weird problem running simple script between Powershell ISE and Powershell
Hi, I'm new to powershell and I've been developing some simple scripts to check stuff in our internal network. Now I want to set a task to run a script every morning at 9am. So I got the script r...
- Mar 21, 2022
dmarquesgn You can use this at the start of the script to set TLS to 1.2
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Mar 17, 2022
Added a start-transcript c:\temp\log.txt to the script, this is the logging when running from a Scheduled Task:
Host Application: C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe c:\temp\test.ps1
Process ID: 25868
PSVersion: 5.1.22000.588
PSEdition: Desktop
PSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0, 5.1.22000.588
BuildVersion: 10.0.22000.588
CLRVersion: 4.0.30319.42000
WSManStackVersion: 3.0
PSRemotingProtocolVersion: 2.3
SerializationVersion: 1.1.0.1
**********************
Transcript started, output file is c:\temp\log.txt
GAC Version Location
--- ------- --------
True v4.0.30319 C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089...
Exception calling "Show" with "2" argument(s): "Showing a modal dialog box or form when the application is not running
in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to
display a notification from a service application."
At line:1 char:79
+ ... ws.Forms'); [System.Windows.Forms.MessageBox]::Show('Teste','WARNING' ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : InvalidOperationException
**********************
Windows PowerShell transcript end
End time: 20220317185229
**********************
Host Application: C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe c:\temp\test.ps1
Process ID: 25868
PSVersion: 5.1.22000.588
PSEdition: Desktop
PSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0, 5.1.22000.588
BuildVersion: 10.0.22000.588
CLRVersion: 4.0.30319.42000
WSManStackVersion: 3.0
PSRemotingProtocolVersion: 2.3
SerializationVersion: 1.1.0.1
**********************
Transcript started, output file is c:\temp\log.txt
GAC Version Location
--- ------- --------
True v4.0.30319 C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089...
Exception calling "Show" with "2" argument(s): "Showing a modal dialog box or form when the application is not running
in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to
display a notification from a service application."
At line:1 char:79
+ ... ws.Forms'); [System.Windows.Forms.MessageBox]::Show('Teste','WARNING' ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : InvalidOperationException
**********************
Windows PowerShell transcript end
End time: 20220317185229
**********************
- dmarquesgnMar 21, 2022Iron ContributorHi,
Thanks. I didn't knew the start-transcript command. Now I've added that into my real powershell script (not this test script), and I've got the following error on the log file.
"PS>TerminatingError(Send-MailMessage): "The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Unable to read data from the transport connection: net_io_connectionclosed."
Error: Could not send email to Email address removed via smtp.office365.com"
I've searched for this error and it's related to TLS. But can't find a solution to overcome it. Do you have any idea on how to fix this issue?
Thanks- Mar 21, 2022
dmarquesgn You can use this at the start of the script to set TLS to 1.2
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12- dmarquesgnMar 21, 2022Iron ContributorCool, now it works just as supposed.
Thanks for the guidance.