jueves, 5 de mayo de 2016

Run script As user (Useful when running scripts with encrypted credentials) | Ejecutar script como otro usuario (útil cuando el script tiene credenciales encriptadas)


Sometimes you need to store username and password on your scripts and if you are sharing them with other members of your team you should use a common account to encrypt the values, in my case we run scripts manually or by using PDQ Deploy (Admin Arsenal) running on a service account, encrypting credentials mean that if someone has physical access to the scripts they will not have the credentials to execute it unless they get access to the credentials used to encrypt them.

$Credentials = (Get-Credential)
$ScriptToExecute = {return (
Get-Item Env:AppData)}
$AppData =
Invoke-Command -ComputerName localhost -Credential $Credentials -ScriptBlock $ScriptToExecute
$AppData # Now contains the Environment var named "AppData"

Thank you Mathias for sharing this quick and easy way to do this:





Algunas veces es necesario guardar passwords dentro de un script, en este caso lo mejor es encriptarlo usando las credenciales de otro usuario, sobre todo si el script será usado por otros miembros de tu equipo or por alguna herramienta, en mi caso usamos PDQ Deploy (Admin Arsenal) para ejecutar algunas tareas; al guardar el password encriptado tenemos al menos una capa de protección en caso de que el script quede expuesto.

$Credentials = (Get-Credential)
$ScriptToExecute = {return (
Get-Item Env:AppData)}
$AppData = 
Invoke-Command -ComputerName localhost -Credential $Credentials -ScriptBlock $ScriptToExecute
$AppData # AppData contiene el resultado del script

Gracias a Mathias por compartir esta rápida y efectiva forma de lograr esto:


No hay comentarios.:

Publicar un comentario