<#
.Synopsis
    Hydration EDITIONS ENI 
.DESCRIPTION
    Hydration EDITIONS ENI 
.EXAMPLE
    C:\Setup\Scripts\New-HydraDS.ps1 -Path "E:\MDTBuildLab" -Description "MDT Build Lab" -BuildAccount "MDT_BA" -DSNumber DS001 -Type Lab
.NOTES
    Created:	 2015-12-15
    Version:	 1.0

    Author - BEZET-TORRES Jérôme
    Twitter: @JM2K69
   
       
    Disclaimer:
    This script is provided "AS IS" with no warranties, confers no rights and 
    is not supported by the author.

#>

[cmdletbinding(SupportsShouldProcess=$True)]
Param (
    [Parameter(Mandatory=$True,Position=0)]
    $Path,

    [Parameter(Mandatory=$True,Position=1)]
    $Description,
    
    [Parameter(Mandatory=$True,Position=2)]
    $BuildAccount,
    
    [Parameter(Mandatory=$True,Position=3)]
    [ValidateSet('DS001','DS002')]
    $DSNumber = "DS001",

    [Parameter(Mandatory=$True,Position=4)]
    [ValidateSet('Lab','Production')]
    $Type 
)

# Check for elevation
If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(`
    [Security.Principal.WindowsBuiltInRole] "Administrator"))
{
    Write-Warning "Oupps, you need to run this script from an elevated PowerShell prompt!`nPlease start the PowerShell prompt as an Administrator and re-run the script."
	Write-Warning "Aborting script..."
    Break
}
Write-Host "PowerShell runs elevated, OK, continuing..." -ForegroundColor Green
Write-Host ""

# Verify that MDT 2013 Update 1 is installed
if (!((Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Where-Object -Property Displayname -like -Value "Microsoft Deployment Toolkit 2013 Update*").Displayname).count) {Write-Warning "MDT 2013 Update 1 is not installed, aborting...";Break}

#Set Variables
Write-Verbose "Starting"
$COMPUTERNAME = $Env:COMPUTERNAME
$RootDrive = $Env:SystemDrive
$ShareName = "\\" + $COMPUTERNAME + "\" + ($Path | Split-Path -Leaf) + "$"
Write-Verbose "Deployment Share Path: $Path"
Write-Verbose "Deployment Share Name: $ShareName"
Write-Verbose "Deployment Share Description: $Description"

# Create the MDT Build Lab Deployment Share root folder
New-Item -Path $Path -ItemType directory

# Create the MDT Build Lab Deployment Share
Import-Module "$RootDrive\Program Files\Microsoft Deployment Toolkit\bin\MicrosoftDeploymentToolkit.psd1"
New-PSDrive -Name "$DSNumber" -PSProvider "MDTProvider" -Root "$Path" -Description $Description -NetworkPath $ShareName | add-MDTPersistentDrive
Write-Verbose "Change permissions for $Path"
New-SmbShare –Name (($Path | Split-Path -Leaf) + "$") –Path "$Path" –ChangeAccess 'Tout le monde'
icacls.exe $Path /grant ($BuildAccount + ":(OI)(CI)(RX)")
icacls.exe $Path\Captures /grant ($BuildAccount + ":(OI)(CI)(M)")

Switch ($Type)
	{
		"Lab"
		{
		        # Create MDT Logical Folders
        New-Item -Path "$DSNumber`:\Operating Systems" -enable "True" -Name "Windows 10" -Comments "" -ItemType "folder"
        New-Item -Path "$DSNumber`:\Task Sequences" -enable "True" -Name "Reference Task Sequences" -Comments "" -ItemType "folder"
        New-Item -Path "$DSNumber`:\Packages" -enable "True" -Name "Windows 10 x86" -Comments "" -ItemType "folder"
        New-Item -Path "$DSNumber`:\Packages" -enable "True" -Name "Windows 10 x64" -Comments "" -ItemType "folder"
        }
		
        "Production"
		{
			
                # Create MDT Logical Folders
        New-Item -Path "$DSNumber`:\Operating Systems" -enable "True" -Name "Windows 10" -Comments "" -ItemType "folder"
        New-Item -Path "$DSNumber`:\Task Sequences" -enable "True" -Name "Windows 10" -Comments "" -ItemType "folder"
        New-Item -Path "$DSNumber`:\Out-Of-Box Drivers" -enable "True" -Name "WinPE x86" -Comments "" -ItemType "folder"
        New-Item -Path "$DSNumber`:\Out-Of-Box Drivers" -enable "True" -Name "WinPE x64" -Comments "" -ItemType "folder"
        New-Item -Path "$DSNumber`:\Out-Of-Box Drivers" -enable "True" -Name "Windows 10 x64" -Comments "" -ItemType "folder"
		}
		
	} #end switch



