Search This Blog

Monday, November 15, 2010

Automatic Folder Creation for QTrees

Hi,

Following is the script which takes desired folder name as input and then create folder structure.

The content of folder.txt shud be like this

P:\ManagedFolder\Temp\1
P:\ManagedFolder\Temp\1\7
P:\ManagedFolder\Temp\1\8
P:\ManagedFolder\Temp\1\9

Level0Folder\Level1Folder\Level2Folder\

It will create the required folders automatically
****************************************************
$FolderList =Get-Content P:\ManagedFolder\Temp\folder.txt

foreach ($folderName in $folderList)
{

write-host $folderName

if(Test-Path $folderName) {
write-host -ForegroundColor Red "$folderName" folder already exists in the given location
}
else {

write-host creating folder "$foldername"
New-Item "$foldername" -type Directory

}
}
****************************************

For creating  shares following code can be used
$objwmi = [WmiClass] 'win32_share'
$objwmi.create($foldername,$sharename,0)

Regards,
Navdeep aka v-2nas

No comments:

Post a Comment