itglue / automation

A place for IT Glue's user community to learn ways of automating their documentation.
Apache License 2.0
99 stars 33 forks source link

Automation AD powershell #11

Open ggill27 opened 5 years ago

ggill27 commented 5 years ago

Hi,

I'm after a powershell script to reset domain account password and update in IT glue. I already have the script just need the guidance to update the password in IT glue. I'm got the API Keys.

CalebAlbers commented 5 years ago

Hey @ggill27,

Are you using the IT Glue PowerShell module? If so, below is some sample code that I used when testing the New-ITGluePasswords and Set-ITGluePasswords functions.

The first step is to form a $data variable that holds the relevant password information, as so:

$data = @{
    'type' = 'passwords'
    'attributes' = @{
        'name' = 'Domain Admin'
        'username' = 'contoso\administrator'
        'password' = $myPassword
        'notes' = "Admin credentials for the domain admin account"
        'password-category-id' = '<<<fill this in>>>'
        'password-category-name' = '<<<fill this in>>>'
        'organization_id' = $org_id
    }
}

Note the password categories pertain to things like "Web/FTP" or "Application." You can get a list of the current password categories in your IT Glue account by running Get-ITGluePasswordCategories.

If you are creating a new password, simply pass the new variable to the New-ITGluePasswords function. You should get a response in the $output variable that holds the id of the new password.

$output = New-ITGluePasswords -data $data

With the password id now in hand, you can have your script easily update the existing password. Just modify the $data contents for the new password, and pass along the password id as so:

Set-ITGluePasswords -id $password_id -data $data
ggill27 commented 5 years ago

ConvertTo-Json : Cannot validate argument on parameter 'Depth'. The argument is null, empty, or an element of the argument collection contains a null value. Supply a collection that does not contain any null values and then try the command again. At C:\Ad password.ps1:33 char:54

Set-ITGluePasswords : The remote server returned an error: (400) Bad Request. At line:1 char:1

This is the error message I'm getting and below is the code $data = @{ 'type' = 'passwords' 'attributes' = @{

    'name' = 'test'
    'username' = 'test'
    'password' = $newpwd
    'notes' = "Admin credentials for the domain admin account"
    'password-category-id' = '9999' 
    'password-category-name' = 'Active Directory'
    'organization_id' = $org_id

}

} $password_id ="99999" Set-ITGluePasswords -id $password_id -data $data