PowerShell Script That Creates A Folder And A Shortcut On Your Desktop

Basic example of a script that creates a folder in your Local Disk "C"  and then makes a shortcut on desktop so you have easy access to the folder.

First of all, open your powershell as administrator and make sure you are at a place where you are able to create folders such as the C:\ drive.
PS C:\WINDOWS\system32> cd ..
PS C:\WINDOWS> cd ..
PS C:\>

And now you are able to run the script!
– Copy and paste what is written below

$path = "C:\"
New-Item .\EpicFolder -ItemType Directory -Force

$wshshell = New-Object -ComObject WScript.Shell
$desktop = [System.Environment]::GetFolderPath('Desktop')
  $lnk = $wshshell.CreateShortcut($desktop+"\ShortcutName.lnk")
  $lnk.TargetPath = "c:\EpicFolder"
  $lnk.Save() 

Write-Host "Folders and Shortcut created!"

Now that we have tried to create one folder, why not try to create 2 folders within the folder we just created?

Below you see a slightly different script that creates 1 folder and in that folder, you create 2 folders.

(If you already know that you are going to write a lot and likes to keep an order – this might become helpful)

$path="C:\"
New-Item .\EpicFolder -ItemType Directory -Force


$path = "C:\"
New-Item .\EpicFolder\Plugins -ItemType Directory -Force
New-Item .\EpicFolder\Plugins\TestPluginDocument.doc -ItemType File

$path="C:\"
New-Item .\EpicFolder\Powershell -ItemType Directory -Force
New-Item .\EpicFolder\Powershell\TestPowershellDocument.doc -ItemType File

$wshshell = New-Object -ComObject WScript.Shell
$desktop = [System.Environment]::GetFolderPath('Desktop') 
$lnk = $wshshell.CreateShortcut($desktop+"\ShortcutName.lnk") 
$lnk.TargetPath ="c:\EpicFolder"
   $lnk.Save() 


Write-Host "Folders and Shortcut created!"

 

Just play with the thought that you already know that you are going to work with different things, such as Powershell/Word/GroupPolicy/Plugins and so on.

With this script you will save time for everyone, since you don’t have to create the folders and documents again and again – All you need, is to run the script on the computer you use and everyone will have the same folders as you.

Maybe your colleague or friend works with the exact same thing, then this might become useful.

I wouldn’t  expect people to do this with just 2 folders and 1 shortcut, but imagine if you had to create 20 folders within 5 folders and then you need to create something more.

Instead of clicking and create everything by yourself, run this script and it will do it for you!

Hope this helped a little,

– Alex


Leave a Reply