Windows PowerShell Best Practices by Ed Wilson

Windows PowerShell Best Practices by Ed Wilson

Author:Ed Wilson [Ed Wilson]
Language: eng
Format: epub, pdf
Tags: COMPUTERS / System Administration / General
ISBN: 9780735666481
Publisher: Microsoft Press
Published: 2014-01-13T16:00:00+00:00


Note

Keep in mind that you want to convert the contents of the passwordHash.txt file to a secure string and not the path to the passwordHash.txt file. The first time I attempted this operation, I used the following command: ConvertTo-SecureString C:\fso-\-passwordHash.txt, which does not work. I then realized that I was trying to encrypt the path to the file and not the contents of the file.

A more efficient way to create the password hash text file is to use pipelining and thus avoid the intermediate variable as shown here. When the command is run, it prompts for the password.

PS C:\> Read-Host -Prompt "Enter your password" -AsSecureString | >> ConvertFrom-SecureString >> C:\fso\passwordHash.txt

To use this password hash text file in a script, you can use a script like the one shown here.

Example 11-26. UsePasswordHashFile.ps1

$user = "Nwtraders\administrator" $password = ConvertTo-SecureString -String (Get-content C:\fso\passwordHash.txt) $credential = new-object system.management.automation.PSCredential $user,$password Get-WmiObject -class Win32_Bios -computername berlin -credential $credential



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.