Powershell ise

Hi all

I downloaded a script from Microsoft that monitors server up and down via simple test-connection and it emails status.

Now the thing is it works perfectly when I run it through powershell ise but when I try to start it via powershell by running command .\scriptname it just returns me to the powershell prompt. No errors appear.

Any ideas?

Ta
kingcastleAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rajitha ChimmaniCommented:
Why are you expecting an error and what is the error you are expecting? Post the script here and the expected output when you run it.
0
kingcastleAuthor Commented:
It's not that I'm expecting an error sorry it's just the script works out of the box in powershell ise but like I say when I run the exact same script from the powershell prompt it does nothing I.e. Just goes onto a new powershell line like a carriage return
0
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
Please show the script. In this context there should be no difference between PS and PS ISE, but maybe some PS Host vars and functions are used to display things, and they won't work now.
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

kingcastleAuthor Commented:
Thanks, I found the script on the Microsoft website here
Server Reboot Monitor (Report Online/Offline Status) + Email (Updated Jul 2014)
https://gallery.technet.microsoft.com/scriptcenter/2d537e5c-b5d4-42ca-a23e-2cbce636f58d

I just copied that script to ise
0
Rajitha ChimmaniCommented:
So, you are expecting an email with status and not receiving it?
0
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
The script only defines the function Start-Monitor, but does not run it.
PS (without ISE) considers a script to define an own scope, that is everything defined in it will not get part of the shell after the script has been finished. The trick is to use the dot operator, which is kind of "include" or "run in my scope":
. .\ScriptName.Ps1
Start-Monitor PC1, PC2, PC3

Open in new window

PS ISE however runs the script you loaded into the editor, and keeps everything, so you can use what has been defined, calculated and so on.
0
kingcastleAuthor Commented:
Ah ok so even tho I was running from ps the command .\start-monitor pc1 it still wouldn't run.

Was this because I should have entered . .\start-monitor pc1

So I was missing a . Really?
0
kingcastleAuthor Commented:
Ale on your a star just tried what you said and it works perfect. I just going to add that to a windows batch file now to run from a shortcut so cheers for that.

You know the way that script checks computers do you know how I would add to it so that it would display the computer name but also a computer description I give it?
0
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
. .\start-monitor pc1 does not work, because the script defines a function, and a function needs to be called after defining. There are scripts you can call that way, and it isn't difficult to change the script to do that, but I think that is a moot point.
0
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
Re: http:#a40453825, do you want to provide the description with the machine name, or read it from the machine itself?
The former requires a different parameter format (pairs of strings instead of single strings), the latter WMI or similar.
0
kingcastleAuthor Commented:
Would just be a ref description I would myself
0
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
No, not that easy, the way the script is written. Requires major rework.
0
kingcastleAuthor Commented:
Ok no worries at all.

How would you go about running it from batch file?
I tried "powershell.exe -noexit -file c:\start-monitor.ps1"
That opens powershell and loads the script into memory but I still have to enter
Start-monitor pc1 then after that manually

And maybe having it emailing two people rather than one?
0
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
Can't believe this script is posted on a MS site [shaking head]. You need to change
  $tonotification = "user@domain.org",  
to
  $tonotification = @("user@domain.org",  "user2@domain.org"),
to mail to two people.

To run from (.cmd) batch file:
powershell.exe -noexit -command ". c:\start-monitor.ps1; start-monitor PC1"

Open in new window

Optionally remove the -noexit.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kingcastleAuthor Commented:
works perfect great post Qlemo

I was going to use a good few of the scripts from MS script site to help with server side stuff but not sure now. is there any good sites out there that powershell scripts can be found and implemented by non powershell experts?
0
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
Usually MS Technet is a good source, but sometimes you find something less "optimal". http://blogs.technet.com/b/heyscriptingguy/, http://poshcode.org/ and http://powershell.com/ are other common sources.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.