asked on
GENERAL ################################################################################################
$Global:DomainFQDN = $env:USERDNSDOMAIN
SERVERS ################################################################################################
$Global:SCCMSiteServer01 = 'SCCMSERVER'
$Global:ConnectionBroker01 = 'CONNECTIONBROKER'
#ADDING EXTRA SERVERS HERE
#FQDN
#FOR EACH SERVER, ADD A GLOBAL VARIABLE SERVER_FQDN, HOWTO DO THIS?
$Global:SCCMSiteServer01_FQDN = ($SCCMSiteServer01 + '.' + $DomainFQDN))
$Global:ConnectionBroker01_FQDN = ($ConnectionBroker01 + '.' + $DomainFQDN)
ASKER
ASKER
#before
$Global:SCCMSiteServer01 = 'SCCMSERVER'
$Global:ConnectionBroker01 = 'CONNECTIONBROKER'
#after
$Global:AutoVar_SCCMSiteServer01 = 'SCCMSERVER'
$Global:AutoVar_ConnectionBroker01 = 'CONNECTIONBROKER'
#then
get-variable -scope Global | ? {$_.Name -like 'AutoVar_*' -and $_.Value -ne $null -and $_.Value -ne ''} | % {if (!(get-variable | ? {$_.Name -eq "$($_.name)_FQDN"})){New-Variable -Name "$($_.name)_FQDN" -Value "$($_.Value).$($Global:DomainFQDN)" -Force}}
That way you keep your name intact, variables are recognizable globally by prefix.
Windows PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework. PowerShell provides full access to the Component Object Model (COM) and Windows Management Instrumentation (WMI), enabling administrators to perform administrative tasks on both local and remote Windows systems as well as WS-Management and Common Information Model (CIM) enabling management of remote Linux systems and network devices.
TRUSTED BY
Please find following example. I suggest to name your server variables with some constant, I used MySpecialVariable_ prefix to distinguish them.
Open in new window
Regards,
Daniel