PS: Dynamically Creating Folder and File Structure

In many cases, systems engineers require to setup a system where in they need to automatically create a file and folder structure. Here is a simple code that serves such a need: $Folder   = "D:TEMP" $UserName = “TestUser009” $FileName = "ReadMe.txt" $Path     = $Folder + ” + $UserName if (!(Test-Path -path $Path)){     new-item -path $Folder -name $UserName -type directory } if (!(Test-Path -path "$Path$FileName")){     new-item -path $Path -name $FileName -type file }

Read more

PowerShell Script to Dynamically Map a Free Drive Letter

In case when you need to map a local path as a new drive at a runtime, you need to determine which letter is free for use as a next drive letter. Here is a simple code that does this: foreach ($letter in [char[]]([char]’A’..[char]’Z’)) {     $drive = $letter + ‘:’     if (!(Test-Path -path $drive)){         break     } } SUBST $drive "C:TempUser1Data"   For a descending order of processing change the alphabets series as below in foreach loop foreach ($letter in [char[]]([char]’Z’..[char]’A’)) {   This can be a usual case for virtualized environments where you support mapping client […]

Read more