Hi, I have a powershell script, that I created in word, which opens O365 and gets mailbox sizes etc automatically, then closes. To run it, I normally copy the text into powershell straight from Notepad, and it all works as expected. I thought I’d change it to a .ps1 extension, and just pull it directly into powershell, but I’m getting 403 event errors, and the powershell window opens and closes so rapidly I can’t get a handle on the error?
I don’t actually get to see the error, the window closes too quickly…but I have the following from EventViewer:
[pre]
Log Name: Windows PowerShell
Source: PowerShell
Date: 12/11/2018 13:17:54
Event ID: 403
Task Category: Engine Lifecycle
Level: Information
Keywords: Classic
User: N/A
Computer: Jason-XXXX
Description:
Engine state is changed from Available to Stopped.
hi, it’s all from the same computer (my laptop) with access to the same pwd files etc. even adding a pause doesn’t stop the windows closing fairly rapidly! so hard to diagnose.
Thanks for all your help - I’ll try ISE and see if that works!
I’ve opened the notepad script, then saved it as a .ps1. After that I just dragged it into Powershell’s shell. I have also right clicked and ‘run with powershell’…both do not run. But if I drag it into ISE, it works as expected!
No hidden code, this is a script that I created from scratch, and as stated earlier, if I just copy from notepad, works fine, also in ISE. reall head scratching on this…wanted to just drag drop and run!
I think you’ll probably find that Notepad usually saves txt files in ANSI encoding, whereas PowerShell will expect UTF8 of some form… this usually isn’t a problem, but it can occasionally cause oddities like this.
This will probably get off topic, but I’ve taken an interest in encoding.
Powershell 5.1:
I believe the default encoding is “ansi” (Windows-1251), definitely not ascii.
Except out-file (including “>” and “>>”) and tee encode by default in “unicode” (utf16).
Cannot decode utf8 no bom (“no signature”) (at least special characters)
Can decode utf8 with bom
Powershell 6:
Default encoding is utf8 no bom (there’s a way to reliably identify it)