Guest User

Untitled

a guest
Oct 21st, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. $SQLUser = "Username"
  2. $SQLPasswordFile = "\pathtoUserPW.txt"
  3. $SQLKeyFile = "\pathtoUserPW.key"
  4. $SQLkey = Get-Content $SQLKeyFile
  5. $SQLMyCredential = New-Object -TypeName System.Management.Automation.PSCredential `
  6. -ArgumentList $SQLUser, (Get-Content $SQLPasswordFile | ConvertTo-SecureString -Key $SQLkey)
  7. $SQLCredentials = Get-Credential -Credential $SQLMyCredential
  8. $SQLSession = New-PSSession -ComputerName "uhpkpdb01" -Credential $SQLCredentials
  9. Invoke-Command -Session $SQLSession -ScriptBlock {
  10. $exist = Invoke-Sqlcmd "select count(1) from [table] where USER_NAME = '$($args[0])'" -ServerInstance "SERVERNAME"
  11. if ($exist.column1 -eq "1") {
  12. Invoke-Sqlcmd "UPDATE [table] SET PASSWORD = '$($args[1])' WHERE USER_NAME = '$($args[0])'"
  13. Write-Host "Account Updated" }
  14. else {
  15. Write-Host "User Does Not Exists"}} -ArgumentList $env:USERNAME, "PASSWORD"
  16. Remove-PSSession $SQLSession
Add Comment
Please, Sign In to add comment