Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
###########################################
######### 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
You can’t perform that action at this time.