Logo_PowerShell

Ok, it’s not one line but here’s what I have just done to Powershell in my profile.  I created a function called “ChangeDomain” It’s not a fancy function, it just builds TWO global variables, one called $DOMAIN and the other called $CREDS.

The nice part is it’s VERY easy to add alternate domains to the list, and very easy to use and NON-DESTRUCTIVE! And with the Quest Active Roles Management shell it’s incredibly easy to use these new variables.

So I can do this now

CHANGEDOMAIN

 

and it will give me a list of Domains like this

image

Key in a number from 0 to whatever to choose and let it populate the variables.

And now you can run any Quest Cmdlet like this

GET-QADUSER –service $domain –credential $creds

 

And it will connect and work on the foreign domain.   Yes you could just type it all in.  But the important part in this little function is it now allows you to make managing multiple Domains EASIER with techs by just giving them a predefined list of accounts, Domain IP’s and showing them some basic stuff from quest.

 

And isn’t that the important part?  Making life easier on ourselves?

Sean
The Energized Tech

———————– Begin Global function changedomain —————————————-

function global:ChangeDomain ( $PreChoice ) {

# Check whether Quest Active Roles Snapin is loaded.  If not, load it. 
# If it can’t the whole function should do nothing
#

$STATUSLOADED=$FALSE

$SNAPIN=’Quest.Activeroles.ADManagement’

ADD-PSSNAPIN $SNAPIN –erroraction SilentlyContinue

IF ((GET-PSSNAPIN $SNAPIN) –eq $NULL)
     {

          WRITE-HOST ‘This Script requires Quest ActiveRoles Management Shell’
          WRITE-HOST ‘Which can be downloaded free from http://www.quest.com/powershell/activeroles-server.aspx’
     }
ELSE
    {
          # If it DID, Flag Status as GOOD
          #
          $STATUSLOADED=$TRUE
     }

IF ($STATUSLOADED)

{

#
# Defined list of Domains
# First field is Domain name, Second field is the FQDN or NETBIOS name of a DC
# that domain, Third Field is the IP address if the DC, Fourth field is an account
# with Domain Admin rights to work in the Domain
#
# The variable just uses the IP address right now but you can modify it to
# use the fqdn/netbios name.   Whatever you are comfortable with
#

$DomainList = ("SMITH","dc.fqdn.local","192.168.1.5","Administrator"),("JOHNANDJOHN","dc.fqdn.local","192.168.1.5","Administrator")
$DomainList += ,("BIGLAWFIRM","dc.fqdn.local","192.168.1.5","Administrator")
$DomainList += ,("TEST","dc.fqdn.local","192.168.1.5","Administrator")
$DomainList += ,("SOMEBODYINC","dc.fqdn.local","192.168.1.5","Administrator")

Do
{
$DONE=$FALSE
$CountDomains=0

WRITE-HOST ‘Which Domain are we managing Today?’
WRITE-HOST ‘———————————–‘
WRITE-HOST ”

FOREACH ($Domain in $DomainList)
{
Write-Host $CountDomains, $Domain[0]
$CountDomains++
}

$Choice=READ-HOST ‘( 0 – ‘($CountDomains-1)’)’
IF ($Choice -ge 0 -and $Choice -lt $CountDomains)
    { $DONE=$TRUE }
ELSE
    { $DONE=$FALSE ; Write-Host $Choice; Write-Host $CountDomains; Write-Host ‘Please Make a Correct Selection’ }
}
# When the $DONE Variable contains a Boolean $TRUE the loop ends.

Until ($DONE)

# Using $GLOBAL creates a variable that can be accessed globally, not just locally

# Creates variable $CREDS as a GLOBAL variable

$GLOBAL:CREDS=Get-Credential -Credential ($DomainList[$Choice][0]+’\’+$DomainList[$Choice][3])

# Creates variable $Domain as a GLOBAL variable

$GLOBAL:Domain=$Domainlist[$Choice][2]+’:389′

Connect-QADSERVICE ($Domainlist[$Choice][2]+’:389′) -credential $CREDS

}

}

——————————————————————————————————

Advertisements