Storing PowerShell Script Variables In a Simple Text File

Storing PowerShell Script Variables In a Simple Text File

If you prefer not to change variables in your PowerShell script files, read on.

If you prefer to pass in fewer variables to your PowerShell script files, read on.

If you prefer to use a simple format for storing variables in a configuration file, read on.

Recently I made a batch of scripts for a customer request for Active Directory scripts to delegate via Cimitra. I didn't want the customer to have to make any changes to the scripts in order to match the Active Directory context required by the scripts. So I created a method so that all of the scripts can read variables from a common settings.cfg file. The trick, however, was to make it so that the person who edits the settings.cfg file doesn't have to know things such as XML or JSON file formatting rules.

The method I created uses a simple syntax of: VARIABLE_NAME=VALUE

So the only thing that ever needs to change is the "VALUE". For example:

SERVER_ADDRESS=192.168.1.2

If the server address changes to 192.168.13, the line would be changed to:

SERVER_ADDRESS=192.168.1.3

Rather than waxing on, I put a detailed Readme on GitHub and all of the scripts for you to get, and hack to your heart's content. The NewUser.ps1 script has the most verbose documentation.

Special thanks to Adam Bertram. Whenever I go Googling for answers to PowerShell Scripting, I seem to always stumble into Adam's work. For example, I learned how to "source" other PowerShell scripts from an article by Adam, which made the methods I used in the Active Directory scripts mentioned above, possible.

Script On!

要查看或添加评论,请登录

Tay Kratzer的更多文章

  • Just Keep Trying

    Just Keep Trying

    Years ago I was having a philosophical discussion with a work colleague (Willem Bagchus) regarding the changes we make…

  • Tay's Tales (From 40 Years Ago)

    Tay's Tales (From 40 Years Ago)

    LinkedIn is the one social media platform that truly makes me feel better. I love to read posts from people like Rob…

    2 条评论
  • PowerShell Hero Clinic

    PowerShell Hero Clinic

    On Labor Day weekend, my son and I fixed a leaky dishwasher. I have no expertise in dishwashers, but YouTube made us…

  • A Gift For You - Active Directory & Exchange PowerShell User Management Script with 3 Dozen Actions

    A Gift For You - Active Directory & Exchange PowerShell User Management Script with 3 Dozen Actions

    Cimitra recently created a script (available on GitHub) with a customer who has Active Directory, and On-Premise…

  • How To (Truly) Get Rid of Output

    How To (Truly) Get Rid of Output

    I was creating a script today, and I wanted to create a way for "errors" to just go away, for usability purposes, since…

    17 条评论
  • PowerShell Script to Structure Unstructured Data (SQL Data)

    PowerShell Script to Structure Unstructured Data (SQL Data)

    A Cimitra customer was retrieving data from an SQL database with PowerShell. This script below changes the loose SQL…

  • Original Research on Combining The Power of Windows and Linux

    Original Research on Combining The Power of Windows and Linux

    Introduction Combine the power of Bash on Linux and PowerShell on Windows to create tools that are greater than the sum…

    1 条评论
  • 3 Ways To Learn a Topic Well

    3 Ways To Learn a Topic Well

    1. Learn something while attaching the knowledge you want to gain with a strong emotion attached, along with a deadline…

    1 条评论

社区洞察

其他会员也浏览了