Guest User

Untitled

a guest
Aug 25th, 2018
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. param([string] $path, [string]$username, [string]$password)
  2.  
  3. $username = 'testuser'
  4. $password = 'testpassword'
  5.  
  6. if ($path -eq $null -or $path -eq '')
  7. {
  8.     $path = 'C:\\Program Files (x86)\\FileZilla Server'
  9. }
  10.  
  11. $configPath = '{0}\\FileZilla Server.xml' -f $path
  12.  
  13. function Get-MD5([string]$Content)
  14. {
  15.     $cryptoServiceProvider = [System.Security.Cryptography.MD5CryptoServiceProvider];
  16.     $hashAlgorithm = new-object $cryptoServiceProvider
  17.     $bytes = [System.Text.Encoding]::Default.GetBytes($Content)
  18.     $hashByteArray = $hashAlgorithm.ComputeHash($bytes);
  19.     $formattedHash = [string]::join("",($hashByteArray | foreach {$_.tostring("X2")}))
  20.     return $formattedHash.ToLower();
  21. }
  22.  
  23. $password = Get-MD5($password)
  24.  
  25. [xml]$config = Get-Content $configPath
  26.  
  27. $users = $config.LastChild.LastChild
  28. $newuser = $users.FirstChild.CloneNode(1)
  29. $newuser.SetAttribute('Name', $username)
  30.  
  31. $password_option = $newuser.FirstChild
  32. $password_option.InnerText = $password
  33.  
  34. $password_option
  35.  
  36. $users.AppendChild($newuser)
  37.  
  38. $config.Save($configPath)
Add Comment
Please, Sign In to add comment