Hi, I’m trying to create a powershell script which will automate logging into AWS and Azure AD, take information from specific tags then input that information to the relevant places in solarwinds. Currently, I have no knowledge on how to do this so any help would be fantastic.
Hi,
Show us your script.
Create a credential profile
encrypts your credentials and stores them in your home folder
Set-AWSCredential -AccessKey
-SecretKey `
-StoreAs MyNewProfile
connect to SolarWinds
$Hostname = “localhost”
$Username = “admin”
$Password = “”
$swis = Connect-Swis -Hostname $Hostname -Username $Username -Password $Password
set default values for AWS profile and region
Set-AWSCredential -ProfileName MyNewProfile
Set-DefaultAWSRegion -Region us-east-2
list of tags to sync
$tags = “Environment”, “Owner”
gather all instance IDs
$instanceIDs = @()
$reservations = Get-EC2Instance
foreach($res in $reservations) {
foreach($inst in $res.Instances) {
$instanceIDs += $inst.InstanceId
}
}
iterate through the list of instance IDs
foreach ($instanceID in $instanceIDs) {
# get the tag values for this instance
$tagValues = Get-EC2Tag -Filter @{Name=“resource-id”;Values=$instanceID}, @{Name=“key”;Values=$tags}
# get the custom properties for the corresponding node
$node = Get-SwisData $swis "SELECT Nodes.NodeID
, CP.Uri
, CP.Environment
, CP.Owner
FROM Orion.Nodes AS Nodes
LEFT JOIN Orion.Cloud.Aws.Instances AS Instances ON Nodes.NodeID = Instances.NodeID
LEFT JOIN Orion.NodesCustomProperties AS CP ON Nodes.NodeID = CP.NodeID
WHERE InstanceId = '$($instanceID)'"
# update the value for each custom property if needed
foreach($tag in $tagValues) {
# check if the custom property is empty
if(!$node.($tag.Key)) {
# if it is empty, update it with the AWS tag value
$props = @{
($tag.Key) = $tag.Value;
}
Set-SwisObject $swis -Uri $node.Uri -Properties $props
}
}
}
I have this so far, this was given to me, and I was told changes needed to be made for it to work properly, thanks.
Ben,
Welcome to the forum.
Before we proceed … When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.
Thanks in advance
How to format code in PowerShell.org <---- Click
So please go back, edit your last post and fix the formatting of your code.
This forum is for scripting questions rather than script requests. We do not write customized and ready to use scripts or solutions on request. And we do not review or refactor scripts you’ve found on the internet of have been given by colleagues.
What have you tried so far? We expect you to make an own attempt to get your task done or to solve your problem. If you have done so already please document here what exactly you have done and show your code. Then we probably might be able to help you step further.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.