How can Altiris software management run PowerShell script easily? Get the answer here

Today, I gotta share how I made a PowerShell script run using Altiris software management. It wasn’t as straightforward as I thought it’d be, so I figured I’d document the whole process, you know, for anyone else who might run into the same head-scratchers.

First off, I needed this script to do some basic stuff on our workstations, like checking some settings and cleaning up temp files. Nothing fancy, just regular maintenance tasks. I had the PowerShell script ready, and it worked fine when I ran it manually. You know, the usual right-click and “Run with PowerShell” routine. That part was a breeze. It starts a Windows PowerShell session, runs the script with an execution policy of Bypass, and then shuts down the session. Easy peasy.

How can Altiris software management run PowerShell script easily? Get the answer here

Getting Started with Altiris

Now, getting this to work through Altiris was a different story. I started by creating a new task in the Altiris console. I thought, “Okay, this should be simple. I’ll just point it to my script, and we’re good to go.” But nope, it wasn’t that easy. There were a few hoops to jump through.

Creating the Task

  • Creating the Script Task: I went into the Altiris console and created a new “Run Script” task.
  • Script Type: I chose PowerShell, obviously, since that’s what I was using.
  • Script Contents: Here’s where I pasted my PowerShell script. Just copied the whole thing from my text editor and dropped it in there.

Testing Woes

I ran a test on a couple of machines, and guess what? Nothing. Nada. The task showed as completed in Altiris, but when I checked the machines, it was like nothing ever happened. I was like, “What the heck?” I spent a good chunk of time double-checking the script, making sure there weren’t any typos or anything. I even added some logging to see where it might be failing, but the logs were as empty as my coffee cup after a long night.

The “Aha!” Moment

After a bit more digging, I stumbled upon a setting in Altiris for the execution context. Turns out, by default, it was running the script under the system account. I thought that would be fine, but for some reason, it just wasn’t playing nice with my script. So, I changed it to run under the logged-on user’s context. I mean, it’s usually better for a script to run with admin rights, but I figured it was worth a shot.

Running Again

I ran the task again, fingers crossed. And boom! It worked! I saw the changes on the test machines, and my logs were finally showing some activity. It was a facepalm moment, really. Something so simple, yet it tripped me up for hours.

Measuring Execution Time

I also wanted to see how long the script took to run. You know, just out of curiosity. I used the Measure-Command cmdlet for this. Wrapped my script inside it like so:

How can Altiris software management run PowerShell script easily? Get the answer here

$ExecutionTime = Measure-Command { # My script here }

And then added a line to output the execution time:

Write-Output "Script took $($*) seconds to execute."

How can Altiris software management run PowerShell script easily? Get the answer here

This gave me a nice little output showing how long it took. Pretty neat, huh?

Scheduling and Deployment

With the script working, I set up a schedule for it to run weekly. I also played around with different deployment options. Altiris has some cool features for targeting specific groups of machines, so I made sure to set that up correctly. I don’t want this thing running on servers or anything, you know?

Wrap-Up

So, yeah, that’s pretty much it. It was a bit of a learning curve, but I finally got my PowerShell script running smoothly through Altiris. The main takeaway here is to double-check the execution context and make sure it’s set appropriately for your needs. And don’t forget to test, test, and test some more! It saves a lot of headaches down the line.

Hopefully, this little write-up helps someone out there. It’s always those small things that get you, right? Anyway, if you’ve got any questions or wanna share your own Altiris stories, feel free to leave a comment. I’m always up for a good tech chat. After assign the policy to the Microsoft Entra groups, the PowerShell script runs, and the run results are reported. Once the script executes, it doesn’t execute again unless there’s a change in the script or policy.

How can Altiris software management run PowerShell script easily? Get the answer here

Original article by the Author:Colin,If you intend to republish this content, please attribute the source accordingly:https://www.suntrekenergy.com/6743.html