Per GPO bestimmten User auf den Client und Server löschen
Hallo Admin Kollegen,
Ich möchte gerne unter
C:\Users\Test
Das Profil und den User "Test" komplett löschen lassen auf allen Clients und Servern.
Dies möchte Ich gerne per GPO realisieren.
Hat jemand ne Idee ?
Dankeschön
Ich möchte gerne unter
C:\Users\Test
Das Profil und den User "Test" komplett löschen lassen auf allen Clients und Servern.
Dies möchte Ich gerne per GPO realisieren.
Hat jemand ne Idee ?
Dankeschön
Please also mark the comments that contributed to the solution of the article
Content-Key: 62846046370
Url: https://administrator.de/contentid/62846046370
Printed on: June 18, 2024 at 14:06 o'clock
10 Comments
Latest comment
würde ich per Batch oder Powershell-Befehle in einer Computerrichtlinie machen.
Für das saubere Löschen des Benutzerprofils gibt es hier eine Lösung: Profile sauber löschen via Batch
Für das saubere Löschen des Benutzerprofils gibt es hier eine Lösung: Profile sauber löschen via Batch
Mache ich mittels PS Startskript und GPO:
Gruß
function Remove-Userprofile {
[cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
param(
[Parameter(mandatory=$true)][string[]]$identity
)
begin {
if(!(new-object System.Security.Principal.WindowsPrincipal([System.Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole(544)){
write-error "CMDLet needs to be run elevated!" -Category PermissionDenied
break
}
Add-Type –MemberDefinition '[DllImport("ntdll.dll")] public static extern int RtlAdjustPrivilege(int Privilege, bool Enable, bool CurrentThread, ref bool EnabledOut);' -name token -namespace priv | out-null
9,17,18 | %{[void][priv.token]::RtlAdjustPrivilege($_,1,0,[ref]0)}
$userprofiles = Get-CimInstance Win32_Userprofile | ?{!$_.Special -and !$_.Loaded}
}
process{
foreach($ident in $identity){
if ($ident -notlike 'S-1-5*'){
try{
$ident = (New-Object System.Security.Principal.NTAccount($ident)).Translate([System.Security.Principal.SecurityIdentifier]).Value
}catch{}
}
$profile = $userprofiles | ?{$_.SID -eq $ident}
if ($profile){
if ($PSCmdlet.ShouldProcess($ident,"Remove user profile")){
Write-Verbose "Removing profile for identity '$ident'"
# remove userprofile
$profile | Remove-CimInstance
# remove profile data
if (Test-Path -LiteralPath $profile.LocalPath -PathType Container){
remove-item -LiteralPath $profile.LocalPath -Recurse -Force
}
}
}else{
Write-Warning "Profile for identity '$ident' not found."
}
}
}
end{}
}
Remove-Userprofile -identity 'Test' -verbose
Gruß
Du hattest nicht spezifiziert ob es sich um einen lokalen User auf den Maschinen oder Domain-User handelt.
WARNUNG: Profile for identity 'Test' not found.
Wenn es kein lokaler User auf den Maschinen ist sondern ein AD-User bitte auch die Domain vor dem Usernamen angeben!Remove-Userprofile -identity 'DOMAIN\Test' -verbose
Zitat von @Technoolli:
Aber kann Ich das wie oben geschrieben auch auf die gesamte Domaine ausweiten ?
Aber kann Ich das wie oben geschrieben auch auf die gesamte Domaine ausweiten ?
Ja sicher steht doch oben schon x mal.
Nimm eine GPO, dort das Skript als Computer-Startskript definieren und auf die gewünschte OU anwenden, das wolltest du ja auch in deinem Beitrag!
Dies möchte Ich gerne per GPO realisieren.