Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $SQLUser = "Username"
- $SQLPasswordFile = "\pathtoUserPW.txt"
- $SQLKeyFile = "\pathtoUserPW.key"
- $SQLkey = Get-Content $SQLKeyFile
- $SQLMyCredential = New-Object -TypeName System.Management.Automation.PSCredential `
- -ArgumentList $SQLUser, (Get-Content $SQLPasswordFile | ConvertTo-SecureString -Key $SQLkey)
- $SQLCredentials = Get-Credential -Credential $SQLMyCredential
- $SQLSession = New-PSSession -ComputerName "uhpkpdb01" -Credential $SQLCredentials
- Invoke-Command -Session $SQLSession -ScriptBlock {
- $exist = Invoke-Sqlcmd "select count(1) from [table] where USER_NAME = '$($args[0])'" -ServerInstance "SERVERNAME"
- if ($exist.column1 -eq "1") {
- Invoke-Sqlcmd "UPDATE [table] SET PASSWORD = '$($args[1])' WHERE USER_NAME = '$($args[0])'"
- Write-Host "Account Updated" }
- else {
- Write-Host "User Does Not Exists"}} -ArgumentList $env:USERNAME, "PASSWORD"
- Remove-PSSession $SQLSession
Add Comment
Please, Sign In to add comment