System Tray Icon One-Liners

It does not pull scripts from the system, you have to use one-line code in the box.

Is there a way to use the Import-SyncroModule function to use from a scheduled-task like for example - at startup?

I tried that - I am getting errors that look like more variables have changed.
PS C:\Users\ianem> Log-Activity -EventName ‘TestEvent’ -Message ‘TestMessage’
System.TypeLoadException: Could not load type ‘System.Web.UI.WebResourceAttribute’ from assembly ‘System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’.
Stack:
at ConvertTo-Json20, C:\ProgramData\Syncro\bin\module.psm1: line 314
at Call-Api, C:\ProgramData\Syncro\bin\module.psm1: line 266
at Call-SyncroApi, C:\ProgramData\Syncro\bin\module.psm1: line 249
at Log-Activity-Impl, C:\ProgramData\Syncro\bin\module.psm1: line 63
at Log-Activity, C:\ProgramData\Syncro\bin\module.psm1: line 54
at , : line 1
Call-SyncroApi: failure

@jordanritz any ideas? i took a look at module.psm1 but I’m not seeing anything obvious

ianm, I’m guessing your using Powershell 7. Syncro’s module unfortunately is not compatible with Powershell 7 so you have to run it under Powershell 5.
Pwsh 7:

Powershell 5:

@isaacg thanks for the tag.

Well, I feel dumb. I could have sworn I tested in 5.1 also. My only excuse is that maybe it was a very late night and I should have tried after a good night’s sleep. I have tested it properly in 5.1 and it does work.

Thats good to hear. I wish the module worked with v7 as I’d use it but I haven’t wanted it bad enough to bother trying to port their module

I do most everything I can in v7+. Wish everyone would also do so (including MS by installing it on Windows automatically).

1 Like

I am trying to get it to run from a scheduled task - tried both as user and as system and not getting it to actually do a command from the module. Mainly trying to do a Log-Activity from a scheduled task. It runs fine when I run it via the C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy ByPass -Command option.

I’ve definitely used it from scheduled tasks. You could try using start-transcript at the beginning to write everything to a file so you can see what the errors are. If the Scheduled task exits right away before the Powershell script can run its possible you have AV or some security product getting in your way.

Apologies - I seem to have sidetracked the reason for this post. Let me get it back on track.

Any new or updated ideas or code for one-liners for system tray out there? I love what I have seen so far.

I just came across this thread and it’s awesome, I’m currently incorporating some commands into my organizations tray icon. I’m adding this comment in case anybody is new to PowerShell and wants a little more of a breakdown.

$script = @'
# delete this comment text and insert the actual script HERE
'@

$encodedCommand = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($script))

Write-Output $encodedCommand

Then copy and paste the output that PowerShell gives you from running that encoding script and put it behind the command

powershell.exe -EncodedCommand


For example, running this script

$script = @'
$serialNumber = (Get-WmiObject -Class Win32_BIOS).SerialNumber
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
[System.Windows.Forms.MessageBox]::Show("The computer's serial number is: $serialNumber", "Computer Serial Number")
'@

$encodedCommand = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($script))

Write-Output $encodedCommand

Will spit out the following output:

JABzAGUAcgBpAGEAbABOAHUAbQBiAGUAcgAgAD0AIAAoAEcAZQB0AC0AVwBtAGkATwBiAGoAZQBjAHQAIAAtAEMAbABhAHMAcwAgAFcAaQBuADMAMgBfAEIASQBPAFMAKQAuAFMAZQByAGkAYQBsAE4AdQBtAGIAZQByAA0ACgBbAFMAeQBzAHQAZQBtAC4AUgBlAGYAbABlAGMAdABpAG8AbgAuAEEAcwBzAGUAbQBiAGwAeQBdADoAOgBMAG8AYQBkAFcAaQB0AGgAUABhAHIAdABpAGEAbABOAGEAbQBlACgAIgBTAHkAcwB0AGUAbQAuAFcAaQBuAGQAbwB3AHMALgBGAG8AcgBtAHMAIgApACAAfAAgAE8AdQB0AC0ATgB1AGwAbAANAAoAWwBTAHkAcwB0AGUAbQAuAFcAaQBuAGQAbwB3AHMALgBGAG8AcgBtAHMALgBNAGUAcwBzAGEAZwBlAEIAbwB4AF0AOgA6AFMAaABvAHcAKAAiAFQAaABlACAAYwBvAG0AcAB1AHQAZQByACcAcwAgAHMAZQByAGkAYQBsACAAbgB1AG0AYgBlAHIAIABpAHMAOgAgACQAcwBlAHIAaQBhAGwATgB1AG0AYgBlAHIAIgAsACAAIgBDAG8AbQBwAHUAdABlAHIAIABTAGUAcgBpAGEAbAAgAE4AdQBtAGIAZQByACIAKQA=

So if I copy that and paste it as the following really long one-liner command

powershell.exe -EncodedCommand JABzAGUAcgBpAGEAbABOAHUAbQBiAGUAcgAgAD0AIAAoAEcAZQB0AC0AVwBtAGkATwBiAGoAZQBjAHQAIAAtAEMAbABhAHMAcwAgAFcAaQBuADMAMgBfAEIASQBPAFMAKQAuAFMAZQByAGkAYQBsAE4AdQBtAGIAZQByAA0ACgBbAFMAeQBzAHQAZQBtAC4AUgBlAGYAbABlAGMAdABpAG8AbgAuAEEAcwBzAGUAbQBiAGwAeQBdADoAOgBMAG8AYQBkAFcAaQB0AGgAUABhAHIAdABpAGEAbABOAGEAbQBlACgAIgBTAHkAcwB0AGUAbQAuAFcAaQBuAGQAbwB3AHMALgBGAG8AcgBtAHMAIgApACAAfAAgAE8AdQB0AC0ATgB1AGwAbAANAAoAWwBTAHkAcwB0AGUAbQAuAFcAaQBuAGQAbwB3AHMALgBGAG8AcgBtAHMALgBNAGUAcwBzAGEAZwBlAEIAbwB4AF0AOgA6AFMAaABvAHcAKAAiAFQAaABlACAAYwBvAG0AcAB1AHQAZQByACcAcwAgAHMAZQByAGkAYQBsACAAbgB1AG0AYgBlAHIAIABpAHMAOgAgACQAcwBlAHIAaQBhAGwATgB1AG0AYgBlAHIAIgAsACAAIgBDAG8AbQBwAHUAdABlAHIAIABTAGUAcgBpAGEAbAAgAE4AdQBtAGIAZQByACIAKQA=

It’ll pop up your computer serial number.

2 Likes