Solved

Powershell ise

Posted on 2014-11-19
17
224 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
  • 7
  • 7
  • 2
17 Comments
 
LVL 16

Expert Comment

by:Rajitha Chimmani
Comment Utility
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
Comment Utility
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 68

Expert Comment

by:Qlemo
Comment Utility
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
 

Author Comment

by:kingcastle
Comment Utility
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
Comment Utility
So, you are expecting an email with status and not receiving it?
0
 
LVL 68

Expert Comment

by:Qlemo
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 68

Expert Comment

by:Qlemo
Comment Utility
. .\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 68

Expert Comment

by:Qlemo
Comment Utility
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
Comment Utility
Would just be a ref description I would myself
0
 
LVL 68

Expert Comment

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

Author Comment

by:kingcastle
Comment Utility
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 68

Accepted Solution

by:
Qlemo earned 500 total points
Comment Utility
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
Comment Utility
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 68

Expert Comment

by:Qlemo
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Find out how to use Active Directory data for email signature management in Microsoft Exchange and Office 365.
The recent Microsoft changes on update philosophy for Windows pre-10 and their impact on existing WSUS implementations.
This tutorial will show how to configure a new Backup Exec 2012 server and move an existing database to that server with the use of the BEUtility. Install Backup Exec 2012 on the new server and apply all of the latest hotfixes and service packs. The…
This tutorial will walk an individual through setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…

743 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now