Script Repository – Part II

Ok so I figured out how to post the code in WordPress.

FYI, I’ve seen this many time I just didn’t know it was that easy…

Here’s the link to get you started posting your source code Pretty cool huh?

$csvRepository = @"
Folder
scripts
scripts\cmd
scripts\modules
scripts\temp
scripts\tools
scripts\hta
scripts\vbs
scripts\export
scripts\sources
scripts\sources\csv
scripts\sources\xml
scripts\sources\txt
scripts\sources\xlsx
scripts\ps1
scripts\ps1\adds
scripts\ps1\dsa
scripts\ps1\azure
scripts\ps1\dsc
scripts\ps1\fsrm
scripts\ps1\gpmc
scripts\ps1\dssite
scripts\ps1\exch
scripts\ps1\wmi
scripts\ps1\365
scripts\ps1\azure
scripts\ps1\download
"@ | ConvertFrom-Csv

function create-scriptrepository {
    param(
        $parentFolder,
        $folder
    )

    if(!(Test-Path "$parentFolder\$folder")) {
        New-Item -Path "$parentFolder\$folder" -ItemType Directory | Out-Null
    }
    Else {
        Write-Warning "Folder $parentFolder\$folder already exists."
    }
}

foreach($item in $csvRepository) {
    #Create script repository in parent folder
    create-scriptrepository -parentFolder C:\Temp -folder $item.Folder
}

Ok, here’s a quick rundown of what’s happening here…

ConvertFrom-Csv comes in handy When you don’t want to go through all the hassle of creating and importing a csvFile. The @”…”@ thing is a literal string.

I used a parentFolder parameter just in case you want to create your repository elsewhere.
I’m a big fan of foreach. I know there are one-liners out there but foreach just keeps it readable. It helps if someone else has to read your code.

So there you have it, your own script repository. Feel free to use it and add your own folders. I’m sure you’ll think of something… 😉

Tip: Keep to folder name to a bare minimum. If it’s about SQL Server stuff then sql is a great folder name (Really Urv? I would have never guessed! You sir have a vast grasp of the obvious…) Hehe…

Hope it’s worth something to you. This helps me keep thing tidy and organized. Up next some tips on Script naming that keeps me sane.

Ttyl,

Urv

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s