Created
July 4, 2020 09:17
-
-
Save raulunzue/2be89e0936d6d6b46caecfa6d12b7c37 to your computer and use it in GitHub Desktop.
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
########################################### | |
######### RAUL UNZUE - ELBLOGDENEGU ####### | |
########################################### | |
#Script limpiar users para Citrix FSLOGIX # | |
########################################### | |
# EMPEZAMOS LOG: | |
Start-Transcript ("c:\scripts\logs\OWNER-ScriptLog{0:yyyyMMdd-HHmm}.txt" -f (Get-Date)) | |
# CARPETA PERFILES | |
$origen = "C:\Users" | |
# LISTAR PERFILES | |
Get-ChildItem $origen | Select-Object Name | Set-Content "c:\scripts\perfiles.txt" | |
# Eliminar valores | |
(Get-Content "c:\scripts\perfiles.txt") -replace ("@{Name=", "") -replace ("}","") | Set-Content "c:\scripts\perfiles.txt" | |
# Quitamos de la lista los usuarios que no queremos que borre | |
(Get-Content "c:\scripts\perfiles.txt") -replace ("Administrador", "") -replace ("runzue","") -replace ("Public","") -replace ("Default","") -replace ("pepe","") -replace ("svc_antivirus","") -replace ("svc_prueba","") | Set-Content "c:\scripts\perfiles.txt" | |
# Limpiamos los espacios en blanco y exportamos a TXT | |
(Get-Content "c:\scripts\perfiles.txt") | ? {$_.trim() -ne "" } | Set-Content "c:\scripts\perfiles.txt" | |
# Pasamos contenido a variable para tratar el dato | |
$perfiles= Get-Content "c:\scripts\perfiles.txt" | |
# TRATAMOS LOS PERFILES SI EXISTEN | |
if ($perfiles) { | |
# RECORREMOS EL FICHERO | |
ForEach ($p in $perfiles) { | |
if($p){ | |
# AGREGAR PERMISOS FULL CONTROL ADMINS DEL DOMINIO | |
icacls.exe "c:\Users\$p" /grant:r "NEGU\Admins. del dominio:(OI)(F)" /T | |
# BORRAMOS PERFIL | |
Remove-Item -Path "C:\Users\$p" -Force -Recurse | |
} | |
# Cuando se acabe la lista | |
else{ | |
Write-Output "Todos los perfiles procesados" | |
} | |
} | |
} | |
else { | |
Write-Output "No hay perfiles a eliminar" | |
} | |
# Borrar TXT | |
Remove-Item "c:\scripts\perfiles.txt" | |
# Paramos log | |
Stop-Transcript | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment