parameters - Hardcode run-as encrypted credentials in Powershell -


i got powershell script work help!!!!

$line_array = @() $multi_array = @() [hashtable]$my_hash = @{}  foreach ($i in $args){    $line_array+= $i.split(" ") }  foreach ($j in $line_array){     $multi_array += ,@($j.split("=")) }  foreach ($k in $multi_array){     $my_hash.add($k[0],$k[1]) }  $sender_ip = $my_hash.get_item("sender-ip")  $eventlist = @() get-eventlog "security" -computername $sender_ip `     | -filterscript {$_.eventid -eq 4624 -and $_.replacementstrings[4].length -gt 10 -and $_.replacementstrings[5] -notlike "*$"} `     | select-object -first 2 `     | foreach-object {         $row = "" | select username, logintime         $row.username = $_.replacementstrings[5]         $row.logintime = $_.timegenerated         $eventlist += $row         } $userid = $eventlist[0].username $userid 

can invoked with

.\foo.ps1 sender-ip=10.2.23.40 sender-name=joe sender-id=djoe 

but now, need prepare third-party program invoke it. script produce output, (i.e. given ip address find last user logged on) if runs service account. means when test script, can select 'run-as' , enter in service account credentials.

the third-party program doesn't run using service credentials, means must on program side.

how make program run-as service account automatically? how hardcode this? , username , password must encrypted.

can point me in right direction?

edit: reading link, http://blogs.technet.com/b/robcost/archive/2008/05/01/powershell-tip-storing-and-using-password-credentials.aspx

and shows how pump in encrypted password file

ps c:\> read-host -assecurestring | convertfrom-securestring | out-file c:\cred.txt 

and bring script

ps c:\> $password = get-content c:\cred.txt | convertto-securestring 

and create credential object

ps c:\> $credentials = new-object -typename system.management.automation.pscredential -argumentlist "myusername",$password 

but still trying figure out how make script run using these credentials

i assume crucial point (point, use alternate credentials) get-eventlog cmdlet. cmdlet not support -credential, can use get-winevent instead. mean need change filter. suggest moving part (all?) of filter get-winevent cmdlet:

get-winevent -filterhashtable @{      id = 4624     logname = 'security'  } -computername $sender_ip -credential $credential 

btw: if store credentials using convertto/from-securestring work account performing operation (so if 3rd party tool runs under different credentials, won't able process credentials produced).


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

jquery - How would i go about shortening this code? And to cancel the previous click on click of new section? -