This is something I have been looking for, I had a similar experience when searching for solution. What I will do with this is first test this in my environment, but then once I know my environment doesn’t break it, I will modify it to be used with SCCM. this will overcome the inherent limitation` of targeting workstations with Invoke-command, because the user has shutdown their workstation. With SCCM the job will just wait for the user to come on line and optionally require a reboot. Great work!
This addendum to my previous post is for those with SCCM build 1610 or newer.
In SCCM 1610 and above Microsoft added a “Run Script” function, using the same scripts as you use for group policy with the location for your report hard coded in the script with modify rights for “Authenticated Users” as noted above you can deploy the script against a collection of machines and the result come back incredibly fast. And I mean”blazing faxt” 5 minutes for 1600 reports.
Now is this better than using group policy, that depends if you need complete and constant updates to the data, the answer is no, because the scripts function will only return results from on-line machines, while group policy will keep reporting every 2 hours or so.
To use the scripts function safely my scripts are very quick and read only, I then target a collection that reports only on-line machines, I refresh it just before activtivation. Then I deploy the script to the collection to 1500 machines and get results in 5 minutes, multiple location across the US!
So to summarize, use the script with Group policy for continuously updated results and use SCCM Script function for quick results against machines in an SCCM collection.
Remember this technique that has been shared here is very powerful and with GREAT POWER comes GREAT RESPONSIBILITY. Do it wrong and you may experience a CEV. (Career Ending Event)
I wanted to have a function with a hard coded value for testing.
I added the following to the top and bottom of the script.
At the top
At the bottom
Set-IconVisible nsload.exe 2 stop-process -name explorer
In this example I am making the Citrix NetScaler Gateway Plugin icon visible
The stop-process cmdlet has an interesting behavior when stopping the Windows shell (explorer.exe), that behavior is that it kills the task without letting it write the values in memory which would overwrite the changes made by the script, then Explorer.exe automatically restarts! And the icon becomes visible immediately!
The one caveat is I don’t believe a non-administrator can kill the Windows Shell so the GPO method is superior. But for testing by and administator this small modification seems to work.
To use this as an SCCM Package i would use the run a program first option under the user context to change the users tray setting, then use the stop-process -name explorer comand to make it take effect immediatly, should work, i will try to test this and report back.