Aaron
Aaron

Reputation: 3325

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'
cls
Get-EventLog system -computername COMPUTERNAMEHERE -InstanceId 2147489657 -Newest 5 | ft EventID,TimeWritten,MachineName -AutoSize
Pause

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

Upvotes: 1

Views: 5106

Answers (1)

Joseph Alcorn
Joseph Alcorn

Reputation: 2442

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.

Upvotes: 1

Related Questions