Quantcast
Channel: Devolutions Forum - Recent Posts
Viewing all articles
Browse latest Browse all 19717

Topic "Metadata Update from List" a message from Peter Cermak

$
0
0
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


<#.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 &quotd:\ServerList.txt&quot 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 = &quotd:\ServerList.txt&quot
$ServerCSV = Import-Csv -Delimiter &quot`t&quot -Path $MyServerFile

# Define Session color (object) for the different Networks:
$SessionColor = &quot&quot | Select &quotNetInt&quot,&quotNetWeb&quot,&quotNetDMZ&quot
$SessionColor.NetInt = &quot#C0FFC0&quot # Green
$SessionColor.NetWeb = &quot#FF8080&quot # Red
$SessionColor.NetDMZ = &quot#FFFF00&quot # 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 += &quot`r`n&quot + $ServerLine.Network
$Keywords += &quot`r`n&quot + $ServerLine.PersonApp
$Keywords += &quot`r`n&quot + $ServerLine.PersonOS
# Get Session for the current server:
$Session = $RDMSessions | where {$_.Name -eq &quot$($ServerLine.Server)&quot}
# If we don't find an existing session named after the server:
if ($Session.Name.length -lt 2) {
# New Server:
Write-Host &quot.Creating New Session '$($ServerLine.Server)'.&quot
# Get the correct template for the servers network:
$TemplateID = ( Get-RDM-Template | where {$_.TemplateName -like &quot*$($ServerLine.Network)*&quot}).ID
# Create the Session:
$Session = New-RDM-Session -Group $($ServerLine.Network) -Host $($ServerLine.Server) -Kind &quotRDPConfigured&quot -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 &quot$($ServerLine.Server)&quot}
$StatisticServerNew ++
} else {
if ($AddNewOnly.IsPresent) {
Write-Verbose &quot.Skipping GHServer '$($ServerLine.Server)' because of parameter 'AddNewOnly'.&quot
$StatisticServerSkipped ++
# next Server in list:
continue
}
$StatisticServerChanged ++
}
# Not existing or duplicate Session Name
if ( (-not $Session) -or ($Session.count -ge 2) ) {
Write-Host &quot-Error getting Session`r`n$(($Session | fl * | out-string).trim())&quot -BackgroundColor red
$StatisticServerError ++
# next Server in list:
Continue
}
# Don't refresh RDM:
Set-RDM-Session -Session $Session.session -NoRefresh
Write-Host &quot.Processing Server $LineNow '$($ServerLine.Server)', Session '$($Session.Name)', Network: '$($ServerLine.Network)'.&quot

Set-RDM-Property -ID $Session.id -Path &quotMetaInformation&quot -Property &quotKeywords&quot -value &quot$KeyWords&quot
if ($SetColors.IsPresent) {
Set-RDM-Property -ID $Session.id -Property &quotColor&quot -Value $SessionColor.$($ServerLine.Network)
Set-RDM-Property -ID $Session.id -Property &quotGroupTab&quot -Value $ServerLine.Network
}
Set-RDM-Property -ID $Session.id -Path &quotMetaInformation&quot -Property &quotState&quot -Value $ServerLine.Rack
Set-RDM-Property -ID $Session.id -Property &quotDescription&quot -Value $ServerLine.Description
# Defining The Server Hardware Type (VM, Blade, Rack) and set the corresponding fields:
if ($ServerLine.Rack -like &quotBlade*&quot) {
$ServerType = &quotBlade&quot
# i use the ZIP code to identify the Blade Bay
Set-RDM-Property -ID $Session.id -Path &quotMetaInformation&quot -Property &quotZipCode&quot -Value $ServerLine.Details
Set-RDM-Property -ID $Session.id -Path &quotMetaInformation&quot -Property &quotIsVirtualMachine&quot -Value &quotFalse&quot
# Integrated Lights out of HP Blade Enclosure Onboard Administrator:
Set-RDM-Property -ID $Session.id -Path &quotMetaInformation&quot -Property &quotServerRemoteManagementUrl&quot -Value &quothttps://$($ServerLine.Rack)-oa1&quot
# HP Mangement Homepage:
Set-RDM-Property -ID $Session.id -Path &quotMetaInformation&quot -Property &quotServerHomePageUrl&quot -Value &quothttps://$($Session.Name):2381/&quot
} elseif ($ServerLine.Standort -eq &quotVM&quot) {
$ServerType = &quotVM&quot
Set-RDM-Property -ID $Session.id -Path &quotMetaInformation&quot -Property &quotIsVirtualMachine&quot -Value &quottrue&quot
Set-RDM-Property -ID $Session.id -Path &quotMetaInformation&quot -Property &quotVirtualMachineName&quot -Value &quot$($Session.Name)&quot
} else {
$ServerType = &quotRack&quot
# i use the ZIP code to identify the Racks Height unit where the server is locats
Set-RDM-Property -ID $Session.id -Path &quotMetaInformation&quot -Property &quotZipCode&quot -Value $ServerLine.Details
Set-RDM-Property -ID $Session.id -Path &quotMetaInformation&quot -Property &quotIsVirtualMachine&quot -Value &quotfalse&quot
# Integrated Lights out of HP Rack mounted Server:
Set-RDM-Property -ID $Session.id -Path &quotMetaInformation&quot -Property &quotServerRemoteManagementUrl&quot -Value &quothttps://$($Session.Name)-ilo&quot
# HP Mangement Homepage:
Set-RDM-Property -ID $Session.id -Path &quotMetaInformation&quot -Property &quotServerHomePageUrl&quot -Value &quothttps://$($Session.Name):2381/&quot
} # < if ($ServerLine.Rack -like &quotBlade*&quot)

Set-RDM-Property -ID $Session.id -Path &quotMetaInformation&quot -Property &quotCustomField1Title&quot -Value &quotPersonOS&quot
Set-RDM-Property -ID $Session.id -Path &quotMetaInformation&quot -Property &quotCustomField2Title&quot -Value &quotPersonApp&quot
Set-RDM-Property -ID $Session.id -Path &quotMetaInformation&quot -Property &quotCustomField3Title&quot -Value &quotUsage&quot
Set-RDM-Property -ID $Session.id -Path &quotMetaInformation&quot -Property &quotCustomField4Title&quot -Value &quotApplication&quot
Set-RDM-Property -ID $Session.id -Path &quotMetaInformation&quot -Property &quotCustomField5Title&quot -Value &quotDescription&quot
Set-RDM-Property -ID $Session.id -Path &quotMetaInformation&quot -Property &quotCustomField1Value&quot -Value $ServerLine.PersonOS
Set-RDM-Property -ID $Session.id -Path &quotMetaInformation&quot -Property &quotCustomField2Value&quot -Value $ServerLine.PersonApp
Set-RDM-Property -ID $Session.id -Path &quotMetaInformation&quot -Property &quotCustomField3Value&quot -Value $ServerLine.Usage
Set-RDM-Property -ID $Session.id -Path &quotMetaInformation&quot -Property &quotCustomField4Value&quot -Value $ServerLine.Application
Set-RDM-Property -ID $Session.id -Path &quotMetaInformation&quot -Property &quotCustomField5Value&quot -Value $ServerLine.Description

Write-Host &quot+Finished Server '$($Session.Name)', Type: '$ServerType'.&quot
}

Write-Host &quot.Finished Fill-RDM-Data, Errors: $StatisticServerError , New: $StatisticServerNew , Changed: $StatisticServerchanged, Skipped: $StatisticServerSkipped&quot
return $StatisticServerError


edited by Peter Cermak (POI) on 4/16/2013

Viewing all articles
Browse latest Browse all 19717

Trending Articles