windows - Test-sti til lokal brugerprofil mappebane vender tilbage sandt, selv efter at brugerprofilen er slettet. Og der er ingen brugermappe til stede

Indlæg af Hanne Mølgaard Plasc

Problem



Sletning af brugerprofil
    $ UserFolderPath1='\ $ Server \ C $ \ Users \ $ UserName'


Try {
         (Get-WmiObject -ComputerName $Server Win32\_UserProfile | Where-Object {$\_.LocalPath -eq "C:Users$UserName"}).Delete()
         Write-Host -ForegroundColor Green "$UserName has been deleted from $Server"

       } Catch [System.Management.Automation.MethodInvocationException]{
         Write-Host -ForegroundColor Red "ERROR: Profile is currently locked on $Server "

       } Catch [System.Management.Automation.RuntimeException] {
         Write-Host -ForegroundColor Yellow -BackgroundColor Blue "INFO: $UserName Profile does not exist on $host"

       } Catch {
         Write-Host -ForegroundColor Red "ERROR: an unknown error occoured. The error response was $($error[0])"

       }


Brugermappen er slettet, men testbanen c: \ users \ userprofilefolder vises stadig som sand


    if(test-path "$UserFolderPath1"){

       Write-host "user folder found"
       Get-ChildItem $UserFolderPath1 -Recurse | Remove-Item -recurse -Force  
       Remove-Item $UserFolderPath1 -Force   

    }

Bedste reference