Last active
April 24, 2019 11:34
-
-
Save Stephanevg/5d22faab64fb31396bde3980fbc7cf2d to your computer and use it in GitHub Desktop.
Create a Folder repository (With Share etc...)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Class Repository { | |
[System.IO.DirectoryInfo]$RootPath | |
[System.IO.DirectoryInfo[]]$Subfolders | |
Repository([String]$RootPath,[String[]]$SubFolders){ | |
$this.RootPath = $RootPath | |
$this.AddSubFolder($SubFolders) | |
} | |
AddSubFolder([String[]]$Subfolders){ | |
foreach($SubFolder in $Subfolders){ | |
[System.IO.DirectoryInfo]$Folder = join-Path $this.RootPath -ChildPath $subfolder | |
$this.Subfolders += $Folder | |
} | |
} | |
[void] CreateFolderStructure(){ | |
if(!($this.RootPath)){ | |
New-Item -Path $this.RootPath -ItemType Directory | |
} | |
foreach($subfolder in $this.subfolders){ | |
try{ | |
if(!($subfolder.Exists)){ | |
New-Item -Path $subfolder -ItemType Directory -ErrorAction Stop | |
write-verbose "Created folder $($subfolder.FullName)" | |
} | |
}Catch{ | |
write-warning $_ | |
} | |
} | |
} | |
} | |
Class RepositoryShare{ | |
[Repository]$Repository | |
[String]$Description | |
[String[]]$Accounts | |
RepositoryShare([Repository]$Repository,[String]$Description){ | |
$this.Repository = $Repository | |
$this.Description = $Description | |
} | |
CreateShare([String[]]$Accounts){ | |
try{ | |
New-SmbShare -Name "Repository" -Path $this.Repository.RootPath -Description $this.Description -FullAccess $Accounts -ErrorAction stop | |
}Catch{ | |
write-warning $_ | |
} | |
} | |
} | |
$GroupName = "GroupName" | |
$SubFolders = @("Scripts","Modules","Sources") | |
$Repo = [Repository]::new("D:\Repository",$SubFolders) | |
$Repo | |
$RepoShare = [RepositoryShare]::New($Repo,"Repository share") | |
$RepoShare.CreateShare($GroupName) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment