Showing posts with label Powershell. Show all posts
Showing posts with label Powershell. Show all posts

Wednesday, December 17, 2014

Displaying IIS Server Metrics

A significant problem has developed for me: how to let a user of as silverlight app know what is going on the web server running it? For example: How many users are on it? Is there a process hogging all the resources?  Does the app have enough bandwidth to run properly? Turns out IIS 7 does provide tools to query and serve up this information in real time!

http://www.iis.net/overview/control/powerfuladmintools

And one such feature is being able to use PowerShell to script the tools to provide the data you want.

http://www.iis.net/downloads/microsoft/powershell

And on codeproject.com there was an article about putting real-time gauges on a web site,. This could be a great tool for displaying the data to users.

http://www.codeproject.com/Articles/604502/A-Universal-Gauge-for-Your-Web-Dashboard


Friday, August 22, 2014

Using Powershells Scripts in Software Solutions

I've been working on a project that will require being able to run Powershell scripts from a Silverlight application. What we want is to give users the option of running their own scripts to do calculations that our app does not already do. Fortunately, one of my co-workers has already figured out how to add add a routine to run Powershell scripts. All we need to do is to pass it the script as a text string. He used two articles to write the service we are using:

http://www.codeproject.com/Articles/18229/How-to-run-PowerShell-scripts-from-C
http://www.codeproject.com/Articles/18409/Asynchronously-Execute-PowerShell-Scripts-from-C

In addition there are three things that came up in trying to write Powersehell scripts. 1. The set-excutionpolicy cmdlet must be set on the computer that will run the scripts. A good link for understanding what your options is: http://technet.microsoft.com/en-us/library/ee176961.aspx
You should choose the option that is best for your situation. Because our app will be on a webserver, we will need to use high security like the policy "allsigned" because then only signed scripts will be allowed to run.

2. This choice means that I  had to figure out how to digitally sign my scripts. One easy way would have been to buy a digital certificate from Globalsign or Verisign. Problem is that this can be expensive, so I opted for self-signing. Searching the internet kept turning up a solution such as:

http://powershellscripts.com/article3_powershell_script_signing.html

The problem with this is that I could not install the sdk so I could run MakeCert.exe This means that I could not create a certificate let alone sign my scripts. But I found a Powershell scripts that creates a certificate for free and when I tired to use the certificate, it worked! You can find the script at:

http://itproguru.com/expert/2013/10/how-to-create-a-self-signed-computer-certificate-using-powershell-step-by-step-much-easier-than-makecert-exe/

The following article explains what to do with the certificate after generating it. One important thing to remember is that when the script is signed, it is important to export the certificate because if you wanna run the script on a different computer than the one you wrote the script on, you have to install your certificate on that computer.

http://www.hanselman.com/blog/SigningPowerShellScripts.aspx

I did find a problem. Sometimes you may get an error when you try to run:

PS C:\> Set-AuthenticodeSignature c:\foo.ps1 @(Get-ChildItem cert:\CurrentUser\My -codesign)[0]

where C:\foo.ps1 is the name of the script you are signing. The error is an "Unknown Error". Here is a link that explains how to fix it. I just opened the script in notepad and then resaved it and the error went away just like the article said it would

http://blogs.msdn.com/b/vijay/archive/2010/07/13/quot-set-authenticodesignature-quot-returns-unknown-error-while-registering-the-script-with-a-certificate.aspx

3. The other issue is that some scripts require administrative permissions to run properly. It would be best if the program could elevate itself rather than be ran from a prompt with administrative permission. This is very important for me too because I'm calling the script from Silverlight not from a command prompt. But this article saved me.

http://stackoverflow.com/questions/7690994/powershell-running-a-command-as-administrator

All in all,putting these three things together will mean being able to write powershell scripts in any Windows environment.



Tuesday, August 12, 2014

A self elevating PowerShell script - Ben Armstrong - Site Home - MSDN Blogs

Here is a link to an article sharing a powershell script that will cause a powershell script to elevate itself to run as administrator! It does work extremely well! I've added it to three of my powershell scripts and it works as advertized. I did learn to paste this code after the declaration of powershell commandline variables are defined!



A self elevating PowerShell script - Ben Armstrong - Site Home - MSDN Blogs



Friday, May 30, 2014

Querying Databases With Powershell

I've been trying to get a PowerShell script to query a MS Database for a couple of weeks and no success. I even ended up having to re-image my computer because I ended up trying to install AccessDatabase_x64.exe on Windows 7 and my script began to work - for a short time. Then Office 2010 stopped working. I think the problem was that my OS is Win7 64-bit but my MS Office 2010 is 32-bit. This broke office. I found the fix by running PowerShell as 32-bit. MS Office processor type must match the version of PowerShell running the script.  This worked just fine! Here are some links that helped me fix this.

ODBC Fails in 64 bit environment - Access MDB
Use ACE Drivers and PowerShell to Talk to Access and Excel
HOW TO: FIX ERROR - "the 'microsoft.ace.oledb.12.0' provider is not registered on the local machine"
How to Use Databases from within Windows PowerShell
Using Powershsell to Access SQL Data
Using PowerShell with an MS-Access Database




Wednesday, May 7, 2014

Monday, February 17, 2014

Create zip files using PowerShell - CodeProject

Here is some help putting together a script in PowerShell for zipping files.



Create zip files using PowerShell - CodeProject

Monday, July 29, 2013

PowerShell 4.0 - What's new? - CodeProject

This is article is handy to have!

In this article we'll discover some great new features that simplify the live of an administrator or an operator. We'll be shown features like Desired State Configuration. New and extended cmdlets will be demonstrated. Details about PowerShell internals and PowerShell 4.0 internals can be found in may previous article.


PowerShell 4.0 - What's new? - CodeProject

Thursday, April 11, 2013

registry - Returning value from HKCR using Powershell - Stack Overflow

English: Screenshot of Windows PowerShell 1.0 ...
English: Screenshot of Windows PowerShell 1.0 Deutsch: Screenshot von Windows PowerShell 1.0 فارسی: عکس صفحه‌ی نمایش از ویندوز پاورشل نسخه‌ی 1.0 Русский: Сессия в Windows PowerShell (Photo credit: Wikipedia)
Use PowerShell to read the HKCR  registries inWindows.

registry - Returning value from HKCR using Powershell - Stack Overflow
Enhanced by Zemanta

powershell - How to pass credentials to the Send-MailMessage command for sending emails - Stack Overflow

WIndows PowersHell
WIndows PowersHell (Photo credit: Eifion)
Here is a good article with information about how to pass username and password using PowerShell. to send E-Mail.

powershell - How to pass credentials to the Send-MailMessage command for sending emails - Stack Overflow
Enhanced by Zemanta

Tuesday, April 9, 2013

Powershell - Check for Registry value and change if not correct

English: Screenshot of Windows PowerShell 1.0 ...
English: Screenshot of Windows PowerShell 1.0 Deutsch: Screenshot von Windows PowerShell 1.0 فارسی: عکس صفحه‌ی نمایش از ویندوز پاورشل نسخه‌ی 1.0 Русский: Сессия в Windows PowerShell (Photo credit: Wikipedia)
Need to use PowerShell to read the Windows Directory? Yeah. Me too. The following article gives good advice.

Powershell - Check for Registry value and change if not correct
Enhanced by Zemanta

Hey, Scripting Guy! How Can I Check for the Presence or Absence of a Text File? - Hey, Scripting Guy! Blog - Site Home - TechNet Blogs

Windows PowerShell ISE, with multiple open Pow...
Windows PowerShell ISE, with multiple open PowerShell sessions (RunSpaces) in the Windows PowerShell 2.0 (Photo credit: Wikipedia)
This article tells you how to check to see if a file exists using PowerShell. 

Hey, Scripting Guy! How Can I Check for the Presence or Absence of a Text File? - Hey, Scripting Guy! Blog - Site Home - TechNet Blogs
Enhanced by Zemanta

Creating Text Files - Power Tips - PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources

WIndows PowersHell
WIndows PowersHell (Photo credit: Eifion)
Here are some articles that are great for making text files using PowerShells

Creating Text Files - Power Tips - PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources


Enhanced by Zemanta

Sending email using Powershell script - SharePoint and Others - Site Home - MSDN Blogs

English: Screenshot of Windows PowerShell 1.0 ...
English: Screenshot of Windows PowerShell 1.0 Deutsch: Screenshot von Windows PowerShell 1.0 فارسی: عکس صفحه‌ی نمایش از ویندوز پاورشل نسخه‌ی 1.0 Русский: Сессия в Windows PowerShell (Photo credit: Wikipedia)
Here is an article for how to use Powershell to send e-mail

Sending email using Powershell script - SharePoint and Others - Site Home - MSDN Blogs

This article is good for sending e-mail with attachments.

Send an email with an attachment using PowerShell
Enhanced by Zemanta

syntax - How do you comment out code in Powershell? - Stack Overflow

Windows PowerShell ISE, with multiple open Pow...
Windows PowerShell ISE, with multiple open PowerShell sessions (RunSpaces) in the Windows PowerShell 2.0 (Photo credit: Wikipedia)
Here is a great article about how to add comments in PowerShell!

syntax - How do you comment out code in Powershell? - Stack Overflow
Enhanced by Zemanta

Powershell Multidimensional Arrays - Stack Overflow

Windows PowerShell ISE, with multiple open Pow...
Windows PowerShell ISE, with multiple open PowerShell sessions (RunSpaces) in the Windows PowerShell 2.0 (Photo credit: Wikipedia)
Ever needed to use multi-dimensional arrays  in Power Sheel? Me too. This article helps!

Powershell Multidimensional Arrays - Stack Overflow
Enhanced by Zemanta

How to backup application event log to .evtx file using powershell

WIndows PowersHell
WIndows PowersHell (Photo credit: Eifion)
Here is advice how to use Powershell to back up an event log!

How to backup application event log to .evtx file using powershell
Enhanced by Zemanta

Saturday, June 9, 2012

Deployment made simple using Powershell - CodeProject

This is going to come in very handy. I was just looking for something like this!!!

Powershell scripts allow you to take advantage of .NET libraries and write scripts which are almost as powerful as the .NET code itself. You can do many powerful operations like call external DLLs, use .NET namespaces like System.IO, System.Net, run processes and intercept output, call web services etc. The possibilities are endless. Here, I will show you a Powershell script which assists you in day to day deployment of websites. Everyday, we make changes to web projects, which need to be deployed to development servers, sometimes on beta servers, and finally on the production server. Using this script, you can automate all the manual work that you do again and again on your deployment package every time you upload your website to some server. We use this script in Pageflakes every single day during our local development server upload, beta release, and final production server release. All we do is run the script, go to the server, and extract a zip file on the web folder, and that's all. The new version gets deployed within two minutes without any manual work at all, and completely removes any possibility of human error during deployment.

Deployment made simple using Powershell - CodeProject