Solved

Powershell ise

Posted on 2014-11-19
17
234 Views
Last Modified: 2014-11-22
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
0
Comment
Question by:kingcastle
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 7
  • 2
17 Comments
 
LVL 16

Expert Comment

by:Rajitha Chimmani
ID: 40453678
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
 

Author Comment

by:kingcastle
ID: 40453696
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
 
LVL 70

Expert Comment

by:Qlemo
ID: 40453707
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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

Author Comment

by:kingcastle
ID: 40453711
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
 
LVL 16

Expert Comment

by:Rajitha Chimmani
ID: 40453747
So, you are expecting an email with status and not receiving it?
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 40453754
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
 

Author Comment

by:kingcastle
ID: 40453766
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
 

Author Comment

by:kingcastle
ID: 40453825
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
 
LVL 70

Expert Comment

by:Qlemo
ID: 40453852
. .\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
 
LVL 70

Expert Comment

by:Qlemo
ID: 40453860
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
 

Author Comment

by:kingcastle
ID: 40453879
Would just be a ref description I would myself
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 40453935
No, not that easy, the way the script is written. Requires major rework.
0
 

Author Comment

by:kingcastle
ID: 40453966
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
 
LVL 70

Accepted Solution

by:
Qlemo earned 500 total points
ID: 40453983
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
 

Author Comment

by:kingcastle
ID: 40458379
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
 
LVL 70

Expert Comment

by:Qlemo
ID: 40459327
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

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
This article demonstrates probably the easiest way to configure domain-wide tier isolation within Active Directory. If you do not know tier isolation read https://technet.microsoft.com/en-us/windows-server-docs/security/securing-privileged-access/s…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …
This tutorial will show how to configure a single USB drive with a separate folder for each day of the week. This will allow each of the backups to be kept separate preventing the previous day’s backup from being overwritten. The USB drive must be s…

736 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question