Ask and use user input

I am trying to make a script that will prompt the user for their computer name, then use that info in a Get-EventLog line. I am new to powershell and I use to do it with batch scripts however I am not sure how to do it here.

This is what I have so far:

$name1 = Read-Host 'Enter name'
Get-EventLog system -computername COMPUTERNAMEHERE -InstanceId 2147489657 -Newest 5 | ft EventID,TimeWritten,MachineName -AutoSize

Also... how do would I make this run by double clicking on it like you would with a batch script?


Not really answering your first question, as you seem to have that covered, Regarding the error that you get about disabled scripts: By default and design, Microsoft closed a major attack vector that was present in all it's previous scripting attempts: the arbitrary execution of code. You will need to look into Execution Policies to learn more, but basically, out of the box, PowerShell only allows line by line execution from a command host.

@jscott is right that the -ExecutionPolicy Bypass parameter to the PowerShell exe will work for you, but I would recommend you understand the implications of the Bypass execution policy if you use this all over the place.

My favorite policy for trusted machines is the RemoteSigned policy. It gives you a measure of security against arbitrary execution (any script not originating on your machine needs to be cryptographically signed by trusted certificate) and still allows you to run scripts.

Need Your Help

Change background color on runtime

android themes background-color

I am working on an android application which is sort of an e-reader but it reads xml files. What I want it to change the background color of the xml file views using a change background button. Quite

find holidays between start Date and End Date from list of Holidays

java hibernate

I have a method which returning list of Holidays between StartDate and End Date.I am adding Holidays in database so suppose that there is holiday in database like 14/01/2014-16/01/2014.