Skip to content

Instantly share code, notes, and snippets.

@mczerniawski
Last active October 2, 2017 21:13
Show Gist options
  • Save mczerniawski/33b977421311684d7d65acea87f1a486 to your computer and use it in GitHub Desktop.
Save mczerniawski/33b977421311684d7d65acea87f1a486 to your computer and use it in GitHub Desktop.
Create File share for GPO Installations for LAPS
$ShareName = 'GPOInstalls'
$RemoteChildFolder = 'LAPS'
$FileServer = 'FileServer1'
$LocalFilesPath = "C:\$ShareName"
$RemoteFilesPath = Join-Path -Path "\\$FileServer" -ChildPath $LocalFilesPath.Replace(':','$')
New-Item -Path (split-Path $RemoteFilesPath -Parent) -ItemType Directory -Name $ShareName
$cimSession = New-CimSession -ComputerName $FileServer
$shareProps = @{
Description = 'GPOInstallation'
ReadAccess= $Share_GPOInstalls_RGroupProps.SamAccountName, 'Authenticated Users'
FullAccess = $Share_GPOInstalls_RWGroupProps.SamAccountName
Path = $LocalFilesPath
Name =$ShareName
CimSession= $cimSession
}
New-SmbShare @shareProps
$AclAccount='Authenticated Users'
$Acl = Get-Acl $RemoteFilesPath
$AclPermissions = New-Object system.Security.AccessControl.FileSystemAccessRule($AclAccount, "ReadAndExecute", "ContainerInherit, ObjectInherit", "None", "Allow")
$Acl.Setaccessrule($AclPermissions)
Set-Acl $RemoteFilesPath $Acl
$cimSession | Remove-CimSession
$RemoteDirectoryPath = Join-Path -Path $RemoteFilesPath -ChildPath $RemoteChildFolder
Get-ChildItem -Path $TempFolder | ForEach-Object {
Copy-Item -Path $_.FullName -Destination (Join-Path -Path $RemoteDirectoryPath -ChildPath $($_.Name))
}
Remove-Item -Path $TempFolder -Force -Recurse -Confirm:$false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment