Re: [PSH] get-credential automation



BTW, even if the scripts are just for you, you should consider using the
convert(to/from)-securestring cmdlets to save your password in a secure
fashion. Example:

PS>$password = read-host -as
**********
PS>ConvertFrom-SecureString $password | out-file password.txt
PS>type password.txt
01000000d08c9ddf0115d1118c7a00c04fc297eb0100000092ada41141c9bf499276a7e159e42fbc0000000002000000000003660000a8000000100
00000869cff29b48417b2555baacc8fd6a1030000000004800000a000000010000000ead25fb7b7b27340849b2ffc36604ba11800000049cf194538
a7a510ae24178477e9d9ae31e82260dc5465e7140000002d3931e24db729f147d4e26cc6aa5c77e54f8eee


This is encoded using my credentials so only my user can get the contents.
Lets try decoding it from another user account:

PS C:\Documents and Settings> type password.txt
01000000d08c9ddf0115d1118c7a00c04fc297eb0100000092ada41141c9bf499276a7e159e42fb
c0000000002000000000003660000a800000010000000869cff29b48417b2555baacc8fd6a10300
00000004800000a000000010000000ead25fb7b7b27340849b2ffc36604ba11800000049cf19453
8a7a510ae24178477e9d9ae31e82260dc5465e7140000002d3931e24db729f147d4e26cc6aa5c77
e54f8eee
PS C:\Documents and Settings> type password.txt | ConvertTo-SecureString
ConvertTo-SecureString : Key not valid for use in specified state.
At line:1 char:43
+ type password.txt | ConvertTo-SecureString <<<<


Now, lets try reading it back in from the account that created it:

PS>type password.txt
01000000d08c9ddf0115d1118c7a00c04fc297eb0100000092ada41141c9bf499276a7e159e42fbc0000000002000000000003660000a8000000100
00000869cff29b48417b2555baacc8fd6a1030000000004800000a000000010000000ead25fb7b7b27340849b2ffc36604ba11800000049cf194538
a7a510ae24178477e9d9ae31e82260dc5465e7140000002d3931e24db729f147d4e26cc6aa5c77e54f8eee
PS>type password.txt | ConvertTo-SecureString
System.Security.SecureString



--
Marcel Ortiz [MSFT]
Windows PowerShell
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.


"Wei Wu [MSFT]" <wwu@xxxxxxxxxxxxx> wrote in message
news:OqbmnupeGHA.3468@xxxxxxxxxxxxxxxxxxxxxxx
1. construct a securestring object using either read-host or new-object
PS C:\monad> $securestr1 = read-host -as
******
PS C:\monad> $securestr2 = new-object security.securestring
PS C:\monad> $securestr2.appendchar('s')
...

2. construct a PSCredential object using new-object
PS C:\monad> $cred = new-object management.automation.pscredential
username,$securestr1

3. now you can use this PSCredential object in get-credential or
get-wmiobject etc.
PS C:\monad> get-credential $cred

UserName Passw
--------
-----
username System.Security.SecureStr
--
Wei Wu [MSFT]
MSH Team
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no
rights.


"ebgreen" <ebgreen@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:66772AFA-6388-4818-AF2B-CEBFA7D22557@xxxxxxxxxxxxxxxx
I often have the need to run automated scripts that will use a local admin
name and password on a remote machine to get WMI info. I can not find a
way
to avoid the password prompt that comes from using get-credential or
using
-credentials in get-wmiobject. I realize that there are security issues
here,
but these are scripts that I run myself and are not distributed so plain
text
passwords is not a huge concern for me. Any idea how I can automate this
and
avoid the popup?




.



Relevant Pages

  • Re: Help with vbs and html
    ... - What OS are you using to run the scripts? ... - Why avoid using WMI? ... > seem to replicate this type of functionality. ...
    (microsoft.public.scripting.vbscript)
  • Re: Pythonic indentation (or: beating a dead horse)
    ... My work since some year is to decrease probability of errors - I'm creating testing tools, environments and scripts, performing integrations tests and so on. ... I don't like unnecessary syntax elements for scripting languages, because they spoil the view for the real problems. ... So I like Ruby's ability to avoid brackets, ... Would "J" encourage people to avoid comments and empty lines to avoid 50% of scrolling? ...
    (comp.lang.ruby)
  • Re: RFT: bin/106642: [patch] Allow excluding certain files from mergemaster (8)
    ... Doug Barton wrote: ... like this -- so I wish to avoid mergemaster's questions about installing ... Well another question -- is it possible teach somehow mergemaster, that it should never touch passwd, groups, /etc/ttys or bunch of another files? ... About pre-script which you suggested, there is another problem -- I MAY have new scripts in /etc/rc.d, but NEVER change the system's scripts. ...
    (freebsd-current)
  • Re: need help on shell scripting
    ... Michael Tosch wrote: ... >> Can I achieve some complex programing through scripts. ... You also need to init av to avoid a blank in that case: ...
    (comp.unix.shell)
  • Re: CFT: BSD-licensed grep [Fwd: cvs commit: ports/textproc/bsdgrep Makefile distinfo]
    ... This general behavior should be considered a GNUism, the type of thing that we want to avoid in scripts. ...
    (freebsd-current)