Hi,
Here is my script to create new sessions (or modify existing sessions) and fill in the Metadata from a file.
See attached file Fill-RDM-Data.ps1 Version 1.0.0
Regards,
Peter
edited by Peter Cermak (POI) on 4/16/2013
Here is my script to create new sessions (or modify existing sessions) and fill in the Metadata from a file.
See attached file Fill-RDM-Data.ps1 Version 1.0.0
Regards,
Peter
<#.Synopsis
Fill-RDM-Data
.Description
Fill Data from erver into RDM
** Result:
0 = OK
<>0 = Number of Errors
.Parameter AddNewOnly
Does not update all Server, but only adds new Servers (No session existing)
.Parameter SetColors
Also sets default colors per network
.Notes
***** Versions
1.0.0 (16.04.2013): Peter.Cermak@porscheinformatik.at, Created
.Example
Fill-RDM-Data.ps1 -AddNewOnly
Add Session for new Servers
#>
param(
[parameter(mandatory=$false)][Switch]$AddNewOnly,
[parameter(mandatory=$false)][Switch]$SetColors
)
#######################################################################
# requires -version 2.0
# > Begin Background information
#######################################################################
# CSV File "d:\ServerList.txt" contians these lines:
#Server Location Rack Details PersonOS PersonApp Application Usage Network Description
#Server01 VCenter VM 0 User1 User3 App1 TEST NetInt Description1
#Server02 Loc2 Rack1 0 User2 User4 App2 QA NetWeb Description2
#Server03 Loc1 Blade01 3 User1 User4 App3 PROD NetDMZ Description3
# The fiels in the file mean:
# Server : Servername
# Location : Datacenter Location
# Rack : Rack Or Blade Enclosure Name
# Details : Rack Heigth Unit or Blade Enclosure Bay
# PersonOS : Responsible Person for the Servers OS
# PersonApp : Responsible Person for the Servers Main Application
# Application : The Servers Main Application
# Usage : PRODuctio, QualityAssurance, Test
# Network : Internal, Web or DMZ (used for Template Selectin, groups and optional colors)
# Description : Additional infos
# Existing Templates
# Template_RDP_NetInt
# Template_RDP_NetWeb
# Template_RDP_NetDMZ
#######################################################################
# > Begin Script
#######################################################################
$MyServerFile = "d:\ServerList.txt"
$ServerCSV = Import-Csv -Delimiter "`t" -Path $MyServerFile
# Define Session color (object) for the different Networks:
$SessionColor = "" | Select "NetInt","NetWeb","NetDMZ"
$SessionColor.NetInt = "#C0FFC0" # Green
$SessionColor.NetWeb = "#FF8080" # Red
$SessionColor.NetDMZ = "#FFFF00" # Yellow
# Initiate Statistics:
[int]$StatisticServerNew = 0
[int]$StatisticServerChanged = 0
[int]$StatisticServerSkipped = 0
[int]$StatisticServerError = 0
[int]$LineNow = 0
# Walk through the File
foreach ($ServerLine in $ServerCSV) {
$LineNow ++
# Define the Keywords from the File:
$Keywords = $ServerLine.Usage
$Keywords += "`r`n" + $ServerLine.Network
$Keywords += "`r`n" + $ServerLine.PersonApp
$Keywords += "`r`n" + $ServerLine.PersonOS
# Get Session for the current server:
$Session = $RDMSessions | where {$_.Name -eq "$($ServerLine.Server)"}
# If we don't find an existing session named after the server:
if ($Session.Name.length -lt 2) {
# New Server:
Write-Host ".Creating New Session '$($ServerLine.Server)'."
# Get the correct template for the servers network:
$TemplateID = ( Get-RDM-Template | where {$_.TemplateName -like "*$($ServerLine.Network)*"}).ID
# Create the Session:
$Session = New-RDM-Session -Group $($ServerLine.Network) -Host $($ServerLine.Server) -Kind "RDPConfigured" -Name $($ServerLine.Server) -TemplateID $TemplateID
# Workaround for shard Templates (needed in Version 8.2.0.0)
$Session.SharedTemplate = $false
# Never forget to save the created session:
$SaveRes = Set-RDM-Session -Session $Session
# Re-read the Session to metadata processing
$Session = $RDMSessions | where {$_.Name -eq "$($ServerLine.Server)"}
$StatisticServerNew ++
} else {
if ($AddNewOnly.IsPresent) {
Write-Verbose ".Skipping GHServer '$($ServerLine.Server)' because of parameter 'AddNewOnly'."
$StatisticServerSkipped ++
# next Server in list:
continue
}
$StatisticServerChanged ++
}
# Not existing or duplicate Session Name
if ( (-not $Session) -or ($Session.count -ge 2) ) {
Write-Host "-Error getting Session`r`n$(($Session | fl * | out-string).trim())" -BackgroundColor red
$StatisticServerError ++
# next Server in list:
Continue
}
# Don't refresh RDM:
Set-RDM-Session -Session $Session.session -NoRefresh
Write-Host ".Processing Server $LineNow '$($ServerLine.Server)', Session '$($Session.Name)', Network: '$($ServerLine.Network)'."
Set-RDM-Property -ID $Session.id -Path "MetaInformation" -Property "Keywords" -value "$KeyWords"
if ($SetColors.IsPresent) {
Set-RDM-Property -ID $Session.id -Property "Color" -Value $SessionColor.$($ServerLine.Network)
Set-RDM-Property -ID $Session.id -Property "GroupTab" -Value $ServerLine.Network
}
Set-RDM-Property -ID $Session.id -Path "MetaInformation" -Property "State" -Value $ServerLine.Rack
Set-RDM-Property -ID $Session.id -Property "Description" -Value $ServerLine.Description
# Defining The Server Hardware Type (VM, Blade, Rack) and set the corresponding fields:
if ($ServerLine.Rack -like "Blade*") {
$ServerType = "Blade"
# i use the ZIP code to identify the Blade Bay
Set-RDM-Property -ID $Session.id -Path "MetaInformation" -Property "ZipCode" -Value $ServerLine.Details
Set-RDM-Property -ID $Session.id -Path "MetaInformation" -Property "IsVirtualMachine" -Value "False"
# Integrated Lights out of HP Blade Enclosure Onboard Administrator:
Set-RDM-Property -ID $Session.id -Path "MetaInformation" -Property "ServerRemoteManagementUrl" -Value "https://$($ServerLine.Rack)-oa1"
# HP Mangement Homepage:
Set-RDM-Property -ID $Session.id -Path "MetaInformation" -Property "ServerHomePageUrl" -Value "https://$($Session.Name):2381/"
} elseif ($ServerLine.Standort -eq "VM") {
$ServerType = "VM"
Set-RDM-Property -ID $Session.id -Path "MetaInformation" -Property "IsVirtualMachine" -Value "true"
Set-RDM-Property -ID $Session.id -Path "MetaInformation" -Property "VirtualMachineName" -Value "$($Session.Name)"
} else {
$ServerType = "Rack"
# i use the ZIP code to identify the Racks Height unit where the server is locats
Set-RDM-Property -ID $Session.id -Path "MetaInformation" -Property "ZipCode" -Value $ServerLine.Details
Set-RDM-Property -ID $Session.id -Path "MetaInformation" -Property "IsVirtualMachine" -Value "false"
# Integrated Lights out of HP Rack mounted Server:
Set-RDM-Property -ID $Session.id -Path "MetaInformation" -Property "ServerRemoteManagementUrl" -Value "https://$($Session.Name)-ilo"
# HP Mangement Homepage:
Set-RDM-Property -ID $Session.id -Path "MetaInformation" -Property "ServerHomePageUrl" -Value "https://$($Session.Name):2381/"
} # < if ($ServerLine.Rack -like "Blade*")
Set-RDM-Property -ID $Session.id -Path "MetaInformation" -Property "CustomField1Title" -Value "PersonOS"
Set-RDM-Property -ID $Session.id -Path "MetaInformation" -Property "CustomField2Title" -Value "PersonApp"
Set-RDM-Property -ID $Session.id -Path "MetaInformation" -Property "CustomField3Title" -Value "Usage"
Set-RDM-Property -ID $Session.id -Path "MetaInformation" -Property "CustomField4Title" -Value "Application"
Set-RDM-Property -ID $Session.id -Path "MetaInformation" -Property "CustomField5Title" -Value "Description"
Set-RDM-Property -ID $Session.id -Path "MetaInformation" -Property "CustomField1Value" -Value $ServerLine.PersonOS
Set-RDM-Property -ID $Session.id -Path "MetaInformation" -Property "CustomField2Value" -Value $ServerLine.PersonApp
Set-RDM-Property -ID $Session.id -Path "MetaInformation" -Property "CustomField3Value" -Value $ServerLine.Usage
Set-RDM-Property -ID $Session.id -Path "MetaInformation" -Property "CustomField4Value" -Value $ServerLine.Application
Set-RDM-Property -ID $Session.id -Path "MetaInformation" -Property "CustomField5Value" -Value $ServerLine.Description
Write-Host "+Finished Server '$($Session.Name)', Type: '$ServerType'."
}
Write-Host ".Finished Fill-RDM-Data, Errors: $StatisticServerError , New: $StatisticServerNew , Changed: $StatisticServerchanged, Skipped: $StatisticServerSkipped"
return $StatisticServerError
edited by Peter Cermak (POI) on 4/16/2013