Guest User

Untitled

a guest
May 20th, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. Write-Verbose "Display Name: $Display"
  2.  
  3. $TruncatedBaseDisplay = (-join([char[]]$Display | select -first 15))
  4.  
  5. $FirstUnusedName = (
  6. ($TruncatedBaseDisplay.Length)..1 | %{
  7. $ThisLength = $_;
  8. $Digits = 15 - $ThisLength;
  9. (-join([char[]]$Display | select -first $ThisLength)) | %{
  10. $ThisName = $_
  11. $Zeroes = -join('0'*$Digits)
  12. 0..([int64](-join('1',$Zeroes)) - 1) | %{-join($ThisName,$_)} | ?{-not(Get-ADUser -filter {samaccountname -eq $_})} | %{
  13. $_
  14. break
  15. }
  16. }
  17. }
  18. )
Add Comment
Please, Sign In to add comment