In many cases, especially for larger environments, it makes sense to have a list of the user accounts that have been used to protect agents and the accounts used for SQL Exchange Metadata.Please note that the metadata credentials are setup by default to be the same as those used to protect agents.
To address the issue a Powershell Script has been created. The result is a table with the following columns: index (for reference), Agent (contains the Agent Name), AgentId (contains the Agent id -- useful when working with the registry), User_login (shows the user account under which the agent was protected) and user_meta (the user account for metadata retrieval). The script can be run without any parameters, in which case will show the values in the table in the default order (registry IDs for the agents). When using the -sorttype parameter one can choose the column to sort; if combined with the -desc parameter, the results are sorted by the chosen column in descending order. Using the -reportpath parameter will result in committing the results to a text file. The acceptable values are "default" or the path to the desired file.
Please note that running
get-help usersforagents.2.ps1 will display the help fro the script. Other help commands are get-help usersforagents.2.ps1 -full and get-help usersforagents.2.ps1 -examples
The code for the script is included below between the horizontal lines and attached to the KB.
_____________________________________
<#
.Synopsis
List User accounts used to protect Agents and to Acquire Matadata from Protected Maschines.
.Description
This script creates a list of the agents, agent id-s, usernames used to protect agents and user names used to acquire metadata (i.e. SQL and Exchange)
.Parameter sorttype
values: agent, agentid, user_login, user_meta
.Parameter desc
if present the results are sorted in descending order. results are sorted in ascending order by default when the sorttype parameter is present
.Parameter reportpath
allows exporting the results to a file
value: default -- saves results to a default file
.Example
UsersforAgents.2.ps1 -reportpath default
.Example
UsersforAgents.2.ps1
.Example
UsersforAgents.2.ps1 -sorttype user_login -reportpath default
.Example
UsersforAgents.2.ps1 -UsersforAgents.2.ps1 -sorttype agent
#>
Param ( [string]$sorttype,
[switch]$desc = $false,
[string]$reportpath=$null
)
cd c:
$list=@()
$currentlocation = get-location
$agentpath = "hklm:\Software\AppRecovery\Core\Agents"
cd hklm:
cd \
$IDPath = get-childitem -path $agentpath
#get agentname, agentid
for ($i=0;$i -lt $idpath.count;$i++){
$agentid = (($IDPath[$i].Name).toString()).Substring((($IDPath[$i].Name).toString()).LastIndexOf("\")+1)
$agentname=(Get-ItemProperty -path $IDPath[$i].Name -name displayname).displayname
$user_login=(Get-ItemProperty -path "$($IDPath[$i].Name)\credentials" -name username).username
$user_meta=(Get-ItemProperty -path "$($IDPath[$i].Name)\MetadataCredentials\DefaultCredentials" -name username).username
$listitem=[pscustomobject]@{Index=$i;AgentId=$agentid;Agent=$agentname;User_login=$user_login;User_meta=$user_meta}
$list += $listitem
}
set-location $currentlocation
#$list | Format-Table -AutoSize -Wrap
$property=$null
$direction=$null
$filereport =$null
$defaultreportpath = "c:\temp\usersforagents_$((get-date).tostring(`"yyyy-MM-dd_hh-mm-ss_tt`")).txt"
if($PSBoundParameters.ContainsKey("sorttype"))
{
if ("agent", "agentid", "user_login", "user_meta" -contains $sorttype){
$property = "| sort-object -Property $sorttype"
}
else {Write-host "Wrong parameter";exit}
if($PSBoundParameters.ContainsKey("desc")){
$direction = " -Descending"
}
}
if($PSBoundParameters.ContainsKey("reportpath"))
{
if ($reportpath -eq "default"){$filereport = " | out-file -filepath $defaultreportpath"}
else {$filereport = " | out-string | out-file -filepath `"$reportpath`""}
}
$reportpattern = "`$list $property $direction | Format-Table -autosize -wrap $filereport"
$sb = [scriptblock]::create($reportpattern)
Invoke-Command -ScriptBlock $sb
_____________________________________
Product: AppAssure 5.3.x, 5.4.x
Defect ID#: