none
repeat function RRS feed

  • Question

  • I have a little script to delete userprfiles using delprof. I want to be able repeat te function for more than one user.
    The problem is that the script exits after one repeat (2 deleted users). What do i need to do to be able to run a function more than 2 times?

    This is the script i have for now:

    clear
    $A = Get-ChildItem C:\Users | select Name
    Write-Host $A
    function delete-user {
    $user = Read-Host "Enter username to delete profile or 'all' to delete all profiles"
    if ( $user -eq "all" ) {
      & 'C:\scripts\Delprof\DelProf2.exe' /u /q /ed:Sam
    }
    else {
      & 'C:\scripts\Delprof\DelProf2.exe' /u /q /ed:Sam /id:$user
    }
    }
    delete-user
    $what_next = Read-Host "Do you want to delete another user y/n?"
    if ( $what_next -eq "y") {
      & delete-user
    }
    else {
      exit
    }

    Tuesday, June 27, 2017 9:29 AM

Answers

  • Have you asked the person who wrote the function for help?

    Have you spent some time learning basic PowerShell?

    Start by reading: help about_While


    \_(ツ)_/

    • Marked as answer by Wim Duizer Tuesday, June 27, 2017 12:38 PM
    Tuesday, June 27, 2017 10:26 AM

All replies

  • Have you asked the person who wrote the function for help?

    Have you spent some time learning basic PowerShell?

    Start by reading: help about_While


    \_(ツ)_/

    • Marked as answer by Wim Duizer Tuesday, June 27, 2017 12:38 PM
    Tuesday, June 27, 2017 10:26 AM
  • thanx, its the While command that did it for me
    Tuesday, June 27, 2017 12:38 PM