• Skip to primary navigation
  • Skip to main content
  • Skip to footer

Stephanos Constantinou Blog

PowerShell Scripting

  • Home
  • Blogs
    • PowerShell Tutorials
    • PowerShell Scripts
    • PowerShell Modules
      • Modules Cmdlets
    • Software Reviews
  • About
  • Contact
You are here: Home / PowerShell Scripts / Encrypt password with key using PowerShell

Encrypt password with key using PowerShell

28/12/2017 by Stephanos 9 Comments

Encrypt password with key using PowerShell

Scenario:

Encrypt password with key using PowerShell.

One major issue that I had to overcome, was to hide the password for the scripts that I will use them on schedule and there will be no need to include it as clear text. Using the below I was able to encrypt the password of the user that I will use in a script and retrieve it within the script whenever is needed. The below method encrypts the password using a 256-bit AES encryption key, which is consider from 32 x 8-bit integers. The numbers that you can use are from 0 to 255.

Related Links:

  • PowerShell Scripts
  • PowerShell Tutorials
  • Using the Read-Host Cmdlet – TechNet – Microsoft
  • ConvertFrom-SecureString – Microsoft Docs
  • Using the Out-File Cmdlet – TechNet – Microsoft

Solution / Script:

$File = "C:\Scripts\Password.txt"
$Key = (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32)
$Password = Read-Host -AsSecureString "Enter the password"
$Password | ConvertFrom-SecureString -Key $key | Out-File $file
Summary
Encrypt password with key using PowerShell
Article Name
Encrypt password with key using PowerShell
Description
Encrypt password with key using PowerShell. This is what I used so I will be able to encrypt password needed to be used on my scripts that are running on schedule and I don't need it to include in the script as clear text. Stephanos Constantinou Blog - PowerShell Scripting
Author
Stephanos
Publisher Name
Stephanos Constantinou Blog
Publisher Logo
Stephanos Constantinou Blog

Filed Under: PowerShell Scripts Tagged With: ConvertFrom-SecureString, Out-File, Read-Host

Reader Interactions

Trackbacks

  1. Send Email using PowerShell - Stephanos Constantinou says:
    03/01/2018 at 17:03

    […] Encrypt Password with key using PowerShell […]

    Reply
  2. Find users with password never expire using PowerShell - Stephanos Constantinou says:
    04/01/2018 at 11:44

    […] Encrypt password with key using PowerShell […]

    Reply
  3. Email error variable in PowerShell - Stephanos Constantinou says:
    05/01/2018 at 14:24

    […] Encrypt password with key using PowerShell […]

    Reply
  4. PowerShell List all Users and Group Membership - Stephanos Constantinou says:
    10/01/2018 at 11:59

    […] Encrypt password with key using PowerShell […]

    Reply
  5. Exchange custom attributes on groups automatically with PowerShell - Stephanos Constantinou says:
    15/01/2018 at 15:19

    […] Encrypt password with key using PowerShell […]

    Reply
  6. Set Active Directory user attributes automatically with PowerShell - Stephanos Constantinou says:
    15/01/2018 at 15:30

    […] Encrypt password with key using PowerShell […]

    Reply
  7. PowerShell Get registry value data for backups - Stephanos Constantinou says:
    25/01/2018 at 13:20

    […] Encrypt password with key using PowerShell […]

    Reply
  8. Enable Unified Messaging Office 365 using PowerShell. - Stephanos Constantinou says:
    31/01/2018 at 15:10

    […] Encrypt password with key using PowerShell […]

    Reply
  9. Check if AD group is in correct OU - Stephanos Constantinou says:
    15/02/2018 at 19:18

    […] Encrypt password with key using PowerShell […]

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Footer

Recent Posts

  • ICS Cube Product Review 26/04/2019
  • PowerShell Module SysInfo v1.2.0 15/03/2019
  • PowerShell Module SysInfo v1.1.2 13/11/2018
  • PowerShell Module SysInfo 24/10/2018
  • Get-VoltageProbe 24/10/2018
  • Get-VideoController 24/10/2018
  • Get-USBController 24/10/2018
  • Get-TrackPoint 24/10/2018
  • Get-TrackBall 24/10/2018
  • Get-TouchScreen 24/10/2018
Planet PowerShell

Categories

  • Modules Cmdlets (57)
  • PowerShell Modules (5)
  • PowerShell Scripts (38)
  • PowerShell Tutorials (35)
  • Software Reviews (2)

Archives

  • April 2019 (1)
  • March 2019 (1)
  • November 2018 (1)
  • October 2018 (56)
  • September 2018 (13)
  • August 2018 (9)
  • July 2018 (6)
  • June 2018 (8)
  • May 2018 (7)
  • April 2018 (9)
  • March 2018 (4)
  • February 2018 (6)
  • January 2018 (12)
  • December 2017 (4)
Top 10 PowerShell 2018

Blogroll

  • Planet PowerShell
  • Reddit – PowerShell
  • PowerShell Magazine
  • PowerShell.org
  • PowerShell Team Blog
  • Hey, Scripting Guy! Blog
  • Mike F Robbins
  • PowerShell Explained with Kevin Marquette
  • Mike Kanakos – Network Admin
  • The Lonely Administrator
  • AskME4Tech
PowerShell Blogs Sysadmin Blogs Banners for Top 20 Programming Blogs

© 2023 · Stephanos Constantinou Blog

  • Home
  • Blogs
  • About
  • Contact