Paradox: Math is simpler than Anydice!
This application is another, beautiful use case of the Binomial distribution: you actually do not need anydice.
The probability of getting \$t\$ successes in a Nd6 roll is given by
$$
P(t,N)= \sum_{i=0}^t \mathcal{B}(N,i,1/6)\cdot\mathcal{B}(N-i,t-i,1/6)
$$
where \$\mathcal{B}(N,t,s)\$ is the Binomial distribution of parameters \$N,s\$. The mathematical explanation is given further in the text.
To infinity and beyond!
Someone_Evil's anydice program works fine, but the problem with anydice programs is that it can not run them for a large value for \$N\$: in this case just for a 7d6 roll the site stop working. Instead, using direct formulas you can simulate rolls with an high amount of dice, in the case you are interested into the distribution analysis, or in the case you can add bonus dice to the reroll. The figure below refers to a roll 100d6.
Mathematical explanation
Given \$N\$ independent trials with the same change of success \$s\$, the probability to get \$t\$ success is given by
$$
\mathcal{B}(N,t,s) = \begin{pmatrix}N\\t\end{pmatrix}s^t(1-s)^{N-t}
$$
where \$\begin{pmatrix}N\\t\end{pmatrix}\$ is the binomial coefficient.
Let's compute the probability \$P(2,6)\$ of getting exactly two 6s on a 5d6 roll under the proposed rules: this is given by
$$
P(2,5)= P(0,5)\cdot P(2,5) + P(1,5)\cdot P(1,4) + P(2,5)\cdot P(0,3)
$$
where
- the first term computes the probability of getting zero 6s on the first roll and two 6s on re-rolling all the dice,
- the second term computes the probability of getting just one 6 on the first roll and another one in the re-rolling of the remaining 5 dice,
- the last term accounts for getting two 6s on the first roll and none on re-rolling the remaining 4 dice.
Each probability above can be computed by the Binomial distribution: hence
$$
P(2,5)= \mathcal{B}(5,0,1/6)\cdot\mathcal{B}(5,2,1/6) + \mathcal{B}(4,1,1/6)\cdot(3,1,1/6)+\mathcal{B}(5,2,1/6)\cdot\mathcal{B}(3,0,1/6)
$$
or, more compactely,
$$
P(2,5)= \sum_{i=0}^2 \mathcal{B}(5,i,1/6)\cdot\mathcal{B}(5-i,2-i,1/6)
$$
and \$P(2,5)=0.35531228235766055 \sim 35.53\%\$, accordingly to SomeoneEvil's answer.
It can be easily generalized to the case of getting \$t\$ success in a Nd6 roll:
$$
P(t,N)= \sum_{i=0}^t \mathcal{B}(N,i,1/6)\cdot\mathcal{B}(N-i,t-i,1/6)
$$
The following python code produces the results for \$N=5, t\in\{0,1,2,3,4,5\}\$:
from scipy.stats import binom
# Number for dice
n = 5
# Probability of success
p = 1/6
print("Succ\tProbability")
for i in range(n + 1):
P = 0;
for j in range(i+1):
P = P + binom.pmf(j, n, p)*binom.pmf(i-j, n-j, p)
print(str(i) + "\t" + str(P))