Resource management in your PowerShell framework

Resource management, when building a framework that handles automated installations, application configuration, encryption and OS configuration, we often tend to use data sources, such as .csvs and SQL databases.

Although both of those can be effective data sources for our scripts in Powershell, there is still something to be said about a good old fashioned folder collection.

Here’s a neat way to build such a collection.

  1. First, build your folders:
    1. Root
      1. Libraries \ Modules
      2. Configuration
      3. Resources
      4. And so on…
  2. Second, start storing collections of each of those hierarchies as global objects:
#Compute your root location
$rootFolder = [string](Split-Path -Path $MyInvocation.MyCommand.Definition -Parent)

#Get your resources and store them in a files collection
#Include any file extensions you want to pick up
Set-Variable resources -Scope Global -Value (Get-ChildItem $rootFolder -Recurse -Include "*.exe","*.csv","*.xml","*.msi","*.mst","*.png","*.url","*.reg" -ErrorAction SilentlyContinue | Select-Object Directory, Name

#Grab the configurations folders from the resources object
Set-Variable Configurations -Scope Global -Value ($resources | Where-Object {$_.Directory -match "Configurations"})
Auto-Update your framework Global Files-Delete Function

No Comments

No comments yet

Leave a Reply

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