45 lines
2.6 KiB
PowerShell
45 lines
2.6 KiB
PowerShell
[CmdletBinding()]
|
|
param(
|
|
[string]$SourcePath = 'C:\Program Files\Microsoft Configuration Manager\Client',
|
|
[string]$DestinationPath = 'C:\ProgramData\LCI-Admin\ClientSource',
|
|
[string]$ShareName = 'CEDClient$',
|
|
[string]$ReaderGroup = 'LCI\CED-WiFi-Equipos',
|
|
[string]$TargetOuDn = 'OU=Centro de Experiencia Digital,OU=Laboratorio,DC=lci,DC=lasalle,DC=mx'
|
|
)
|
|
$ErrorActionPreference = 'Stop'
|
|
foreach ($file in 'ccmsetup.exe','x64\client.msi') {
|
|
if (-not (Test-Path (Join-Path $SourcePath $file))) { throw "Missing client media: $file" }
|
|
}
|
|
if ((Get-AuthenticodeSignature (Join-Path $SourcePath 'ccmsetup.exe')).Status -ne 'Valid') {
|
|
throw 'Client bootstrapper signature is invalid.'
|
|
}
|
|
New-Item -ItemType Directory -Path $DestinationPath -Force | Out-Null
|
|
$acl = [Security.AccessControl.DirectorySecurity]::new()
|
|
$acl.SetAccessRuleProtection($true,$false)
|
|
foreach ($sid in 'S-1-5-18','S-1-5-32-544') {
|
|
$acl.AddAccessRule([Security.AccessControl.FileSystemAccessRule]::new(
|
|
[Security.Principal.SecurityIdentifier]::new($sid),'FullControl','ContainerInherit,ObjectInherit','None','Allow'))
|
|
}
|
|
$acl.AddAccessRule([Security.AccessControl.FileSystemAccessRule]::new(
|
|
$ReaderGroup,'ReadAndExecute','ContainerInherit,ObjectInherit','None','Allow'))
|
|
Import-Module ActiveDirectory
|
|
$domain = Get-ADDomain
|
|
$computers = @(Get-ADComputer -SearchBase $TargetOuDn -Filter 'Enabled -eq $true')
|
|
foreach ($computer in $computers) {
|
|
$acl.AddAccessRule([Security.AccessControl.FileSystemAccessRule]::new(
|
|
$computer.SID,'ReadAndExecute','ContainerInherit,ObjectInherit','None','Allow'))
|
|
}
|
|
Set-Acl -LiteralPath $DestinationPath -AclObject $acl
|
|
& robocopy.exe $SourcePath $DestinationPath /E /COPY:DAT /DCOPY:DAT /R:1 /W:1 /NFL /NDL /NJH /NJS /NP | Out-Null
|
|
if ($LASTEXITCODE -ge 8) { throw "Client media copy failed: $LASTEXITCODE" }
|
|
$share = Get-SmbShare -Name $ShareName -ErrorAction SilentlyContinue
|
|
if ($share -and $share.Path -ne $DestinationPath) { throw 'Share already exists at a different path.' }
|
|
if (-not $share) {
|
|
New-SmbShare -Name $ShareName -Path $DestinationPath -ReadAccess $ReaderGroup -FullAccess 'BUILTIN\Administrators' -EncryptData $true | Out-Null
|
|
}
|
|
foreach ($computer in $computers) {
|
|
# Direct machine permissions avoid waiting for existing Kerberos group tickets.
|
|
Grant-SmbShareAccess -Name $ShareName -AccountName ($domain.NetBIOSName+'\'+$computer.SamAccountName) -AccessRight Read -Force | Out-Null
|
|
}
|
|
[pscustomobject]@{Source="\\$env:COMPUTERNAME\$ShareName";Readers=$ReaderGroup;MediaVersion=(Get-Item (Join-Path $DestinationPath 'ccmsetup.exe')).VersionInfo.FileVersion}
|