Jump to content

njordur

Members
  • Content Count

    24
  • Joined

  • Last visited

  • Days Won

    3

Reputation Activity

  1. Thanks
    njordur reacted to support in API Create Password with $ in it   
    Hi Njordur,
     
    Unfortunately we don't think we can change the API to accomodate for this, but we do have a fix for you to update your scripts.  I've given an exact example below which works, and an explanation below that of what you need to change:
     
    # Begin Script
     
    param(
    $username, 
    $password, 
    $description
    )
     
    $jsonString = '
    {
    "PasswordListID":9914,
    "Title":"company\\' + $username + '",
    "Description":"' + $description + '",
    "AccountTypeID":82,
    "UserName":"' + $username + '",
    "password":"' + $password + '",
    "APIKey":"63fca2537db89e4fb32954234532455",
    "PasswordResetEnabled":true,
    "PrivilegedAccountID":2044,
    "HeartbeatEnabled":true,
    "ValidationScriptID":9,
    "ADDomainNetBIOS":"halox"
    }
    "
    '
     
    Invoke-RestMethod -Uri https://alien.halox.net/api/passwords/ -Method Post -ContentType "application/json" -Body $jsonString
     
    # End Script
     
     
    Things I changed:
    1.  The opening brackets of the JSON string   $jsonString = @"    to     $jsonString = '
    2.  the variables inside the jsons string are now enclosed with a single quote and + symbol.  So we went from "UserName":"$username" to "UserName":"' + $username + '"
    3. the closing brackets of the JSON went from }"@ to }'
     
    I hope this is not too much trouble to change your scripts, and we hope this helps!
     
    Regards,
    Support.
  2. Thanks
    njordur reacted to Fabian Näf in API Create Password with $ in it   
    Hi All
     
    I'm not sure if this helps (I had no time to test it).
    I usually create the JSON as following: Create a Powershell Object, then convert it to JSON.
    If you do it like this, then you dont have to struggle with the string-creation.
     
    $Body = @{ PasswordList = $Name Description = $Description ApplyPermissionsForUserID = $global:UserToPermit CopySettingsFromTemplateID = $global:PasswordstateTemplateID LinkToTemplate = "False" Permission = "A" PrivatePasswordList = "false" NestUnderFolderID = $ParentFolderID APIKey = $global:PasswordStateSystemWideAPIKey } $jsonBody = $Body | ConvertTo-Json (just an example, it doesn't fit to your requirement)
     
    Best regards,
     
    Fabian
  3. Like
    njordur got a reaction from thorirb in Reset SQL Password without Privileged Account Credentials   
    Changed the default script so I could have the option of allowing the SQL user change his password by providing the old password. This way I don't have to define a Privileged Account with the password reset script.
    <# .SYNOPSIS Connect to a Microsoft SQL server using the current SQL user, and change the password for a local SQL account. .NOTES Requires database connections on in-use Port to be allowed through Firewall SQL user needs to be allowed to change own password #> function Set-SQLPassword2 { [CmdletBinding()] param ( [String]$HostName, [String]$InstanceName, [String]$SQLPort, [String]$UserName, [String]$NewPassword, [String]$OldPassword ) #$SQLScript to be called once a database connection has been established. Add one command per line. $SQLScript = @" ALTER LOGIN $UserName WITH PASSWORD = '$NewPassword' OLD_PASSWORD = '$OldPassword' "@ try { #Declare some connection string variables [String]$InstanceNameString = '' [String]$SQLPortString = '' #Construct the Instance Name section of the connection string if required if ($InstanceName -ne '') { $InstanceNameString = '\' + $InstanceName } #Construct the Port Number section of the connection string if required if ($SQLPort -ne '') { $SQLPortString = ',' + $SQLPort } $SQLConnection = New-Object System.Data.SqlClient.SqlConnection $SQLConnection.ConnectionString = "Server=" + $HostName + $InstanceNameString + $SQLPortString + ";User ID=" + $UserName + ";Password=" + $OldPassword + ";" $SQLConnection.Open() $SQLCommand = New-Object System.Data.SqlClient.SqlCommand($SQLScript, $SQLConnection) $SQLCommand.ExecuteScalar() $SQLConnection.Close() Write-Output "Success" } catch { switch -wildcard ($error[0].Exception.ToString().ToLower()) { "*A network-related or instance-specific*" { Write-Output "Failed to execute script correctly against Host '$HostName' for the account '$UserName'. Please check SQL details are correct, and that a firewall is not blocking access - default Port is 1433."; break } "*because it does not exist or you do not have permission*" { Write-Output "Failed to execute script correctly against Host '$HostName' for the account '$UserName'. Error = Account does not exist or you do not have permission."; break } "*Login failed for user*" { Write-Output "Failed to connect to the Host '$HostName' to reset the password for the account '$UserName'. Please check the Privileged Account Credentials provided associated with the Password Reset script are correct"; break } #Add other wildcard matches here as required default { Write-Output "Failed to reset the password for the SQL account '$UserName' on Host '$HostName'. Error = " + $error[0].Exception } } } } #Make a call to the Set-SQLPassword2 function Set-SQLPassword2 -HostName '[HostName]' -InstanceName '[SQLInstanceName]' -SQLPort '[DatabasePort]' -Username '[UserName]' -NewPassword '[NewPassword]' -OldPassword '[OldPassword]'  
  4. Like
    njordur got a reaction from support in Reset SQL Password without Privileged Account Credentials   
    Changed the default script so I could have the option of allowing the SQL user change his password by providing the old password. This way I don't have to define a Privileged Account with the password reset script.
    <# .SYNOPSIS Connect to a Microsoft SQL server using the current SQL user, and change the password for a local SQL account. .NOTES Requires database connections on in-use Port to be allowed through Firewall SQL user needs to be allowed to change own password #> function Set-SQLPassword2 { [CmdletBinding()] param ( [String]$HostName, [String]$InstanceName, [String]$SQLPort, [String]$UserName, [String]$NewPassword, [String]$OldPassword ) #$SQLScript to be called once a database connection has been established. Add one command per line. $SQLScript = @" ALTER LOGIN $UserName WITH PASSWORD = '$NewPassword' OLD_PASSWORD = '$OldPassword' "@ try { #Declare some connection string variables [String]$InstanceNameString = '' [String]$SQLPortString = '' #Construct the Instance Name section of the connection string if required if ($InstanceName -ne '') { $InstanceNameString = '\' + $InstanceName } #Construct the Port Number section of the connection string if required if ($SQLPort -ne '') { $SQLPortString = ',' + $SQLPort } $SQLConnection = New-Object System.Data.SqlClient.SqlConnection $SQLConnection.ConnectionString = "Server=" + $HostName + $InstanceNameString + $SQLPortString + ";User ID=" + $UserName + ";Password=" + $OldPassword + ";" $SQLConnection.Open() $SQLCommand = New-Object System.Data.SqlClient.SqlCommand($SQLScript, $SQLConnection) $SQLCommand.ExecuteScalar() $SQLConnection.Close() Write-Output "Success" } catch { switch -wildcard ($error[0].Exception.ToString().ToLower()) { "*A network-related or instance-specific*" { Write-Output "Failed to execute script correctly against Host '$HostName' for the account '$UserName'. Please check SQL details are correct, and that a firewall is not blocking access - default Port is 1433."; break } "*because it does not exist or you do not have permission*" { Write-Output "Failed to execute script correctly against Host '$HostName' for the account '$UserName'. Error = Account does not exist or you do not have permission."; break } "*Login failed for user*" { Write-Output "Failed to connect to the Host '$HostName' to reset the password for the account '$UserName'. Please check the Privileged Account Credentials provided associated with the Password Reset script are correct"; break } #Add other wildcard matches here as required default { Write-Output "Failed to reset the password for the SQL account '$UserName' on Host '$HostName'. Error = " + $error[0].Exception } } } } #Make a call to the Set-SQLPassword2 function Set-SQLPassword2 -HostName '[HostName]' -InstanceName '[SQLInstanceName]' -SQLPort '[DatabasePort]' -Username '[UserName]' -NewPassword '[NewPassword]' -OldPassword '[OldPassword]'  
×
×
  • Create New...