[PowerShell] Search for mailbox that are not hidden from the GAL on O365

Below is a script I use to search O365 for mailbox that are not hidden from GAL after the user had left the company.

This is done by getting a list of leavers from the AD OU and query O365 for their mailbox attribute of HiddenFromAddressListsEnabled

$UserCredential = Get-Credential yourusername
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session

$leavers = get-aduser -filter '*' -SearchBase "OU=User_Decommissioning"

foreach($leaver in $leavers){
 
 
 Get-Mailbox -Identity $leaver.UserPrincipalName|where{($_.HiddenFromAddressListsEnabled -eq $false)}|select Alias,HiddenFromAddressListsEnabled|export-csv -Path "NotHiddenFromGAL0365.csv" -Append -NoTypeInformation 
 
 
 
 
 }

 

Advertisements

[PowerShell]Get all distribution list and members from AD with PowerShell

The following script will create a csv file for every distribution list with the members listed:

$allDL=get-adgroup -filter 'GroupCategory -eq "Distribution"' | sort name|select SamAccountName

foreach($dl in $allDL){

$filename=($dl.SamAccountName).ToString()
Get-ADGroupMember -identity $dl.SamAccountName|select-object name,SamAccountName,distinguishedName,objectClass|Export-Csv -Path $filename".csv" -NoTypeInformation

}

List Security group members with a autocomplete form

 

#http://social.technet.microsoft.com/wiki/contents/articles/28824.how-to-add-a-graphical-user-interface-to-your-powershell-functions-using-the-net-systemwindowsform-class.aspx
#https://community.spiceworks.com/topic/255740-powershell-script-to-show-all-groups-in-ad
#https://www.petri.com/powershell-problem-solver-exporting-active-directory-groups-csv
get-adgroup -filter 'GroupCategory -eq "Security"'  | sort name | select Name|Export-Csv -Path $env:temp\ADGroup.txt -NoTypeInformation
(Get-Content $env:temp\ADGroup.txt) -replace '"''' | Set-Content $env:temp\ADGroup.txt
Import-Module activedirectory
#import Presentation framework for error message pop-up
Add-Type -AssemblyName PresentationCore,PresentationFramework
Function getADMember($groupName)
{
    try
    {
        Get-ADGroupMember $groupName -Recursive|select-object name,SamAccountName,distinguishedName,objectClass|Export-Csv -Path $env:temp\$groupName.csv -NoTypeInformation
        #|Export-Csv -Path $env:temp\$groupName.csv -NoTypeInformation
        #Out-GridView -PassThru|
        invoke-item -Path $env:temp\$groupName.csv
    }
    catch
    {
        $ButtonType = [System.Windows.MessageBoxButton]::OK
        $MessageIcon = [System.Windows.MessageBoxImage]::Error
        $MessageBody = $($_.Exception.Message)
        $MessageTitle "Error"
        $Result = [System.Windows.MessageBox]::Show($MessageBody,$MessageTitle,$ButtonType,$MessageIcon)
    }
    finally
    {
        
    }
}
#region Boring beginning stuff
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
#endregion
  
#region begin to draw forms
$Form = New-Object System.Windows.Forms.Form
$Form.Text = "Get AD Group Member"
$Form.Size = New-Object System.Drawing.Size(300,170)
$Form.StartPosition = "CenterScreen"
$Form.KeyPreview = $True
$Form.MaximumSize = $Form.Size
$Form.MinimumSize = $Form.Size
  
$label = New-Object System.Windows.Forms.label
$label.Location = New-Object System.Drawing.Size(5,5)
$label.Size = New-Object System.Drawing.Size(240,30)
$label.Text = "Type any group name"
$Form.Controls.Add($label)
$textbox = New-Object System.Windows.Forms.TextBox
$textbox.Location = New-Object System.Drawing.Size(5,40)
$textbox.Size = New-Object System.Drawing.Size(165,25)
#$textbox.Text = "Select source PC:"
$Form.Controls.Add($textbox)
  
$search_group =
{
#region Actual Code
  
$statusBar1.Text = "Searching..."
$DLName $textbox.Text
  
getADMember($DLName)
  
$statusBar1.Text = "Searching Complete"
#endregion
}
  
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(180,38)
$OKButton.Size = New-Object System.Drawing.Size(50,23)
$OKButton.Text = "OK"
$OKButton.Add_Click($search_group)
$Form.Controls.Add($OKButton)
  
$result_label = New-Object System.Windows.Forms.label
$result_label.Location = New-Object System.Drawing.Size(5,65)
$result_label.Size = New-Object System.Drawing.Size(240,30)
$result_label.Text = ""
$Form.Controls.Add($result_label)
  
$statusBar1 = New-Object System.Windows.Forms.StatusBar
$statusBar1.Name = "statusBar1"
$statusBar1.Text = "Ready..."
$form.Controls.Add($statusBar1)
  
$Form.Add_KeyDown({if ($_.KeyCode -eq "Enter"){& $search_group}})
$Form.Add_KeyDown({if ($_.KeyCode -eq "Escape")
{$Form.Close()}})
#endregion begin to draw forms
#Autocomplete region begins here
$textbox.AutoCompleteSource = 'CustomSource'
$textbox.AutoCompleteMode='SuggestAppend'
$textbox.AutoCompleteCustomSource=$autocomplete
#Importing from a file
Get-content -Path $env:temp\ADGroup.txt | % {$textbox.AutoCompleteCustomSource.AddRange($_) }
#Autocomplete region ends here
  
#Show form
$Form.Topmost = $True
$Form.Add_Shown({$Form.Activate()})
[void] $Form.ShowDialog()

Creating a form with .NET library in PowerShell

Below is an example of calling .NET library with PowerShell to build a form. The form will have a textbox for user to input a computer name to ping.

Web link reference included in the comment

#http://social.technet.microsoft.com/wiki/contents/articles/28824.how-to-add-a-graphical-user-interface-to-your-powershell-functions-using-the-net-systemwindowsform-class.aspx
#region Boring beginning stuff
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
#endregion
  
#region begin to draw forms
$Form = New-Object System.Windows.Forms.Form
$Form.Text = "Computer Pinging Tool"
$Form.Size = New-Object System.Drawing.Size(300,170)
$Form.StartPosition = "CenterScreen"
$Form.KeyPreview = $True
$Form.MaximumSize = $Form.Size
$Form.MinimumSize = $Form.Size
  
$label = New-Object System.Windows.Forms.label
$label.Location = New-Object System.Drawing.Size(5,5)
$label.Size = New-Object System.Drawing.Size(240,30)
$label.Text = "Type any computer name to test if it is on the network and can respond to ping"
$Form.Controls.Add($label)
$textbox = New-Object System.Windows.Forms.TextBox
$textbox.Location = New-Object System.Drawing.Size(5,40)
$textbox.Size = New-Object System.Drawing.Size(120,20)
#$textbox.Text = "Select source PC:"
$Form.Controls.Add($textbox)
  
$ping_computer_click =
{
#region Actual Code
  
$statusBar1.Text = "Pinging..."
$ComputerName $textbox.Text
  
if (Test-Connection $ComputerName -quiet -Count 2){
Write-Host -ForegroundColor Green "Computer $ComputerName has network connection"
$result_label.ForeColor= "Green"
$result_label.Text = "System Successfully Pinged"
}
Else{
Write-Host -ForegroundColor Red "Computer $ComputerName does not have network connection"
$result_label.ForeColor= "Red"
$result_label.Text = "System is NOT Pingable"
}
  
$statusBar1.Text = "Testing Complete"
#endregion
}
  
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(140,38)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "OK"
$OKButton.Add_Click($ping_computer_click)
$Form.Controls.Add($OKButton)
  
$result_label = New-Object System.Windows.Forms.label
$result_label.Location = New-Object System.Drawing.Size(5,65)
$result_label.Size = New-Object System.Drawing.Size(240,30)
$result_label.Text = "Results will be listed here"
$Form.Controls.Add($result_label)
  
$statusBar1 = New-Object System.Windows.Forms.StatusBar
$statusBar1.Name = "statusBar1"
$statusBar1.Text = "Ready..."
$form.Controls.Add($statusBar1)
  
$Form.Add_KeyDown({if ($_.KeyCode -eq "Enter"){& $ping_computer_click}})
$Form.Add_KeyDown({if ($_.KeyCode -eq "Escape")
{$Form.Close()}})
#endregion begin to draw forms
  
#Show form
$Form.Topmost = $True
$Form.Add_Shown({$Form.Activate()})
[void] $Form.ShowDialog()

Find empty groups in Active Directory using PowerShell script

Nice way to find empty groups in AD.

Little bit about Active Directory

You can find the empty groups from your domain using below powershell command.

Import-Module activedirectory
Get-ADGroup -Filter * -Properties Members | where {-not $_.members} | select Name | Export-Csv D:emprtygroups.csv –NoTypeInformation

To find empty groups from any specific OU present in other domain:-

Import-Module activedirectory
Get-ADGroup -Filter * -Properties Members -searchbase “OU fqdn” –server Domain.com:3268  | where {-not $_.members} | select Name | Export-Csv D:emprtygroups.csv –NoTypeInformation

View original post

[AutoIT] Creating a Welcome document for new joiners.

The WelcomePack is an application written in AutoIT to generate a Word document with information of the current login user. The generated document will be saved under a folder with the current user’s display name.

WelcomePack.exe will search for $Date, $Username, $tel, $ext, $Email, $ComputerName, $NetworkDrives, $Printers and replace them with the information gathered.

The information includes with the source listed:

  • logon name – Windows session
  • direct line – AD
  • extension number – Shoretel
  • email address – AD
  • distribution list the user is a member of – AD
  • computer name – Windows session
  • mapped drive – Windows session
  • connected printers – Windows session

 

System requirements:

  • Word 2010 or later
  • The template file named “!Default Template.doc”
  • MySQL ODBC 5.3 Unicode Driver

 

*Shoretel DB credential  and server info removed

Minimal error handling has been implement into the code.

 

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****

#AutoIt3Wrapper_Compression=4

#AutoIt3Wrapper_UseX64=Y

#AutoIt3Wrapper_Res_Comment=Welcome Pack Executable

#AutoIt3Wrapper_Res_Description=WF Welcome Pack

#AutoIt3Wrapper_Res_Fileversion=1.0

#AutoIt3Wrapper_Res_LegalCopyright=Max Lee (argentolee@hotmail.com)

#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <Word.au3>

#include <Date.au3>

#include <MsgBoxConstants.au3>

 


;*****************************************

;WelcomePack.au3 by Max Lee

;Created with ISN AutoIt Studio v. 0.95 BETA

;*****************************************

 


; Create application object

Global $oWord = _Word_Create()

If @error <> 0 Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFindReplace Example", _

        "Error creating a new Word application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

; Open template document, read-only

Global $oDoc = _Word_DocOpen($oWord, @ScriptDir & "\!Default Template.doc", Default, Default, True)

If @error <> 0 Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFindReplace Example", _

        "Error opening '!Default Template.doc'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

 


; *****************************************************************************

; Replacing variables in the Word document

; *****************************************************************************

_Word_DocFindReplace($oDoc, "$Date", _NowDate())

_Word_DocFindReplace($oDoc, "$Username", @UserName)

_Word_DocFindReplace($oDoc, "$ComputerName", @ComputerName)

_Word_DocFindReplace($oDoc, "$Email", GetMail())

_Word_DocFindReplace($oDoc, "$NetworkDrives", GetMappedDrives())

_Word_DocFindReplace($oDoc, "$Printers", GetMappedPrinters())

_Word_DocFindReplace($oDoc, "$tel", GetTel())

_Word_DocFindReplace($oDoc, "$DL", _GetDL())

_Word_DocFindReplace($oDoc, "$ext", _GetExt())

;_Word_DocFindReplace($oDoc, "$othertel", GetotherTelephone())

 


 


 


If @error <> 0 Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFindReplace Example", _

        "Error replacing text in the document." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

;MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFindReplace Example", "Text successfully replaced.")

 


DirCreate(@ScriptDir & "\" & GetDisplayName())

_Word_DocSaveAs($oDoc, @ScriptDir & "\" & GetDisplayName() & "\" & GetDisplayName() & ".doc")

 


 


Func GetDisplayName()

    Local $objRootDSE, $strDomain, $objConnection, $objCommand, $objRecordSet, $strDN

    ;Const ADS_SCOPE_SUBTREE = 2

 


    

    $objRootDSE = ObjGet("LDAP://RootDSE")

    $strDomain = $objRootDSE.Get("DefaultNamingContext")

 


 


 


    ;Set ADO connection

    $objConnection = ObjCreate("ADODB.Connection")

    $objConnection.Provider = "ADsDSOObject"

    $objConnection.Open("Active Directory Provider")

 


    ;Set ADO command

    $objCommand = ObjCreate("ADODB.Command")

    $objCommand.ActiveConnection = $objConnection

    $objCommand.Properties("Searchscope") = 2

    $objCommand.CommandText = "SELECT distinguishedName FROM 'LDAP://" & $strDomain & "' WHERE objectCategory='user' AND samAccountName = '" & @UserName & "'"

 


    ;Set recordset to hold the query result

    $objRecordSet = $objCommand.Execute

 


    ;If a user was found - Retrieve the distinguishedName

    If Not $objRecordSet.EOF Then

        $strDN = $objRecordSet.Fields("distinguishedName").Value

 


        Dim $objUser = ObjGet("LDAP://" & $strDN)

 


        Return $objUser.displayName

    Else

        ;"Not found"

        Return

    EndIf

 


EndFunc   ;==>GetDisplayName

 


 


Func GetMail()

    Local $objRootDSE, $strDomain, $objConnection, $objCommand, $objRecordSet, $strDN

    ;Const ADS_SCOPE_SUBTREE = 2

 


    

    $objRootDSE = ObjGet("LDAP://RootDSE")

    $strDomain = $objRootDSE.Get("DefaultNamingContext")

 


 


 


    ;Set ADO connection

    $objConnection = ObjCreate("ADODB.Connection")

    $objConnection.Provider = "ADsDSOObject"

    $objConnection.Open("Active Directory Provider")

 


    ;Set ADO command

    $objCommand = ObjCreate("ADODB.Command")

    $objCommand.ActiveConnection = $objConnection

    $objCommand.Properties("Searchscope") = 2

    $objCommand.CommandText = "SELECT distinguishedName FROM 'LDAP://" & $strDomain & "' WHERE objectCategory='user' AND samAccountName = '" & @UserName & "'"

 


    ;Set recordset to hold the query result

    $objRecordSet = $objCommand.Execute

 


    ;If a user was found - Retrieve the distinguishedName

    If Not $objRecordSet.EOF Then

        $strDN = $objRecordSet.Fields("distinguishedName").Value

 


        Dim $objUser = ObjGet("LDAP://" & $strDN)

 


        Return $objUser.mail

    Else

        ;Msgbox(4096,"Title","Not found")

        Return

    EndIf

 


EndFunc   ;==>GetMail

 


Func GetMappedDrives()

 


    Local $strNetworkDrives

    Local $aArray = DriveGetDrive("NETWORK")

    If @error Then

        ; An error occurred when retrieving the drives.

        MsgBox($MB_SYSTEMMODAL, "", "It appears an error occurred.")

    Else

        For $i = 1 To $aArray[0]

            ; Show all the drives found and convert the drive letter to uppercase.

            ;MsgBox($MB_SYSTEMMODAL, "", "Drive " & $i & "/" & $aArray[0] & ":" & @CRLF & StringUpper($aArray[$i]) & "  " & DriveMapGet($aArray[$i]) &@CRLF )

            $strNetworkDrives = $strNetworkDrives & (@TAB & @TAB & @TAB & StringUpper($aArray[$i]) & "  " & DriveMapGet($aArray[$i]) & @CR)

        Next

 


        Return $strNetworkDrives

    EndIf

 


EndFunc   ;==>GetMappedDrives

 


 


Func GetMappedPrinters()

 


    $objWMIService = ObjGet("winmgmts:\\.\root\CIMV2")

    $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Printer")

    Local $strNetworkPrinters

 


    For $objItem In $colItems

 


        If StringLen($objItem.ShareName) > 3 Then

            $strNetworkPrinters = $strNetworkPrinters & @TAB & @TAB & @TAB & $objItem.ShareName & @CR

        Else

 


        EndIf

 


    Next

 


    Return $strNetworkPrinters

 


EndFunc   ;==>GetMappedPrinters

 


Func GetTel()

    Local $objRootDSE, $strDomain, $objConnection, $objCommand, $objRecordSet, $strDN

    ;Const ADS_SCOPE_SUBTREE = 2

 


    

    $objRootDSE = ObjGet("LDAP://RootDSE")

    $strDomain = $objRootDSE.Get("DefaultNamingContext")

 


 


 


    ;Set ADO connection

    $objConnection = ObjCreate("ADODB.Connection")

    $objConnection.Provider = "ADsDSOObject"

    $objConnection.Open("Active Directory Provider")

 


    ;Set ADO command

    $objCommand = ObjCreate("ADODB.Command")

    $objCommand.ActiveConnection = $objConnection

    $objCommand.Properties("Searchscope") = 2

    $objCommand.CommandText = "SELECT distinguishedName FROM 'LDAP://" & $strDomain & "' WHERE objectCategory='user' AND samAccountName = '" & @UserName & "'"

 


    ;Set recordset to hold the query result

    $objRecordSet = $objCommand.Execute

 


    ;If a user was found - Retrieve the telephoneNumber

    If Not $objRecordSet.EOF Then

        $strDN = $objRecordSet.Fields("distinguishedName").Value

 


        Dim $objUser = ObjGet("LDAP://" & $strDN)

 


        Return $objUser.telephoneNumber

    Else

        ;Not found

        Return

    EndIf

 


EndFunc   ;==>GetTel

Func _GetExt()

    Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")

    Local $sUsername = 'username'

    Local $sPassword = 'password'

    Local $sDatabase = 'shoreware'

    Local $sServer = 'server'

    Local $sDriver = "{MySQL ODBC 5.3 Unicode Driver}"

    Local $iPort = 4308!Default Template

    Local $result

 


 


    $ObjConn = ObjCreate("ADODB.Connection")

    $ObjConn.ConnectionString = "DRIVER=" & $sDriver & ";SERVER=" & $sServer & ";DATABASE=" & $sDatabase & ";User=" & $sUsername & ";Password=" & $sPassword & ";PORT=" & $iPort

    If IsObj($ObjConn) Then

        $ObjConn.open()

    Else

        Exit

    EndIf

 


 


    $rsResult = $ObjConn.Execute("SELECT UserDN FROM users WHERE GuiLoginName='" & @UserName & "'")

    With $rsResult

        While Not .EOF

            

            ;MsgBox(0,'',.Fields("UserDN").Value)

            $result = .Fields("UserDN").Value

            .MoveNext

        WEnd

        .Close

    EndWith

    $ObjConn.Close

    ;MsgBox(0,'',$result)

    Return $result

    

EndFunc   ;==>_GetExt

 


 


 


 


 


Func _ErrFunc($oError)

    ; Do anything here.

    ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _

            @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _

            @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _

            @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _

            @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _

            @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _

            @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _

            @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _

            @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _

            @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF)

EndFunc   ;==>_ErrFunc

 


 


Func _GetDL()

    

    Local $objUser, $objRootDSE, $objConnection, $objRecordSet, $objCommand

    Local $GroupCollection, $ObjGroup, $result

    Local $StrUserName, $StrDomName, $StrSQL

 


    $objRootDSE = ObjGet("LDAP://RootDSE")

    $StrDomName = $objRootDSE.Get("DefaultNamingContext")

 


 


    $StrUserName = @UserName

    $StrSQL = "Select ADsPath From 'LDAP://" & $StrDomName & "' Where ObjectCategory = 'User' AND SAMAccountName = '" & $StrUserName & "'"

 


    ;Set ADO connection

    $objConnection = ObjCreate("ADODB.Connection")

    $objConnection.Provider = "ADsDSOObject"

    $objConnection.Open("Active Directory Provider")

 


 


 


 


    ;Set ADO command

    $objCommand = ObjCreate("ADODB.Command")

    $objCommand.ActiveConnection = $objConnection

    $objCommand.Properties("Searchscope") = 2

    $objCommand.CommandText = $StrSQL

    ;Set recordset to hold the query result

    $objRecordSet = $objCommand.Execute

 


 


    If Not $objRecordSet.EOF Then

        $objRecordSet.MoveLast

        $objRecordSet.MoveFirst

        $objUser = ObjGet($objRecordSet.Fields("ADsPath").Value)

        $GroupCollection = $objUser.Groups

 


        For $ObjGroup In $GroupCollection

            If ($ObjGroup.GroupType = 2 Or $ObjGroup.GroupType = 4 Or $ObjGroup.GroupType = 8) Then

                $result = $result & @TAB & @TAB & @TAB & $ObjGroup.CN & @CR

            Else

                ;Do nothing

            EndIf

            

        Next

 


        $ObjGroup = Null ;

        $GroupCollection = Null ;

        $objUser = Null ;

 


        Return $result ;

    Else

 


    EndIf

    

EndFunc   ;==>_GetDL

 


 


 


Func GetotherTelephone()

    Local $objRootDSE, $strDomain, $objConnection, $objCommand, $objRecordSet, $strDN

    ;Const ADS_SCOPE_SUBTREE = 2

 


    

    $objRootDSE = ObjGet("LDAP://RootDSE")

    $strDomain = $objRootDSE.Get("DefaultNamingContext")

 


 


 


    ;Set ADO connection

    $objConnection = ObjCreate("ADODB.Connection")

    $objConnection.Provider = "ADsDSOObject"

    $objConnection.Open("Active Directory Provider")

 


    ;Set ADO command

    $objCommand = ObjCreate("ADODB.Command")

    $objCommand.ActiveConnection = $objConnection

    $objCommand.Properties("Searchscope") = 2

    $objCommand.CommandText = "SELECT distinguishedName FROM 'LDAP://" & $strDomain & "' WHERE objectCategory='user' AND samAccountName = '" & @UserName & "'"

 


    ;Set recordset to hold the query result

    $objRecordSet = $objCommand.Execute

 


    ;If a user was found - Retrieve the otherTelephone

    If Not $objRecordSet.EOF Then

        $strDN = $objRecordSet.Fields("distinguishedName").Value

 


        Dim $objUser = ObjGet("LDAP://" & $strDN)

 


        Return $objUser.otherTelephone

    Else

        ;"Not found"

        Return

    EndIf

 


EndFunc   ;==>GetotherTelephone

Default template attached:

[SHORETEL] Get workgroup, user extension, user login and workgroup description.

To get a list of workgroup, user extension, user login and workgroup description, connect to the Shoretel Shoreware database and run the following SQL:

SELECT workgroupmembers.WorkgroupDN,workgroupmembers.UserDN,users.GuiLoginName, dn.Description FROM workgroupmembers 
INNER JOIN DN ON workgroupmembers.WorkgroupDN=dn.DN
INNER JOIN users ON workgroupmembers.UserDN=users.UserDN

 

[Oracle] Allowing Oracle ADI users to switch database with a batch file

Some ADI users will need to switch between database for different purposes. However, this would not be easy without having to change the network config files for Oracle.

I had created a batch file to allow users to change database by first preparing all the database registry, network config (tnsnames.ora and sqlnet.ora) and put them under C:\ADI. I had grant normal users the rights to change those files.

Below is the batch:

@ECHO off
cls
:start
ECHO.
ECHO ADI Menu.
ECHO 1. PRD 8000
ECHO 2. TST 8001
ECHO 3. UAT 8002
ECHO 4. DEV 8003
ECHO 5. PTH 8018
ECHO 6. Exit

set choice=
set /p choice=Please select database from the above list and press enter:
REM if not '%choice%'=='' set choice=%choice:~0,1%
if '%choice%'=='1' goto PRD8000
if '%choice%'=='2' goto TST8001
if '%choice%'=='3' goto UAT8002
if '%choice%'=='4' goto DEV8003
if '%choice%'=='5' goto PTH8018
if '%choice%'=='6' goto Exit
REM set choice
ECHO "%choice%" is not a valid input, Please try again.
pause
ECHO.
cls
goto start

:PRD8000
ECHO PRD8000 selected.
del /q C:\orant\NET80\ADMIN\sqlnet.ora
del /q C:\orant\NET80\ADMIN\tnsnames.ora
del /q C:\orant\NETWORK\ADMIN\sqlnet.ora
del /q C:\orant\NETWORK\ADMIN\tnsnames.ora

copy C:\ADI\tnsnames.ora_Prod8000 C:\orant\NETWORK\ADMIN\
copy C:\ADI\tnsnames.ora_Prod8000 C:\orant\NET80\ADMIN\

ren C:\orant\NETWORK\ADMIN\tnsnames.ora_Prod8000 tnsnames.ora
ren C:\orant\NET80\ADMIN\tnsnames.ora_Prod8000 tnsnames.ora

regedit /s c:\adi\prd8000.reg
goto end

:TST8001
ECHO TST8001 selected.
del /q C:\orant\NET80\ADMIN\sqlnet.ora
del /q C:\orant\NET80\ADMIN\tnsnames.ora
del /q C:\orant\NETWORK\ADMIN\sqlnet.ora
del /q C:\orant\NETWORK\ADMIN\tnsnames.ora

copy C:\ADI\tnsnames.ora_tst8001 C:\orant\NETWORK\ADMIN\
copy C:\ADI\tnsnames.ora_tst8001 C:\orant\NET80\ADMIN\

ren C:\orant\NETWORK\ADMIN\tnsnames.ora_tst8001 tnsnames.ora
ren C:\orant\NET80\ADMIN\tnsnames.ora_tst8001 tnsnames.ora

regedit /s c:\adi\tst8001.reg
goto end

:UAT8002
ECHO UAT8002 selected.
del /q C:\orant\NET80\ADMIN\sqlnet.ora
del /q C:\orant\NET80\ADMIN\tnsnames.ora
del /q C:\orant\NETWORK\ADMIN\sqlnet.ora
del /q C:\orant\NETWORK\ADMIN\tnsnames.ora

copy C:\ADI\tnsnames.ora_uat8002 C:\orant\NETWORK\ADMIN\
copy C:\ADI\tnsnames.ora_uat8002 C:\orant\NET80\ADMIN\

ren C:\orant\NETWORK\ADMIN\tnsnames.ora_uat8002 tnsnames.ora
ren C:\orant\NET80\ADMIN\tnsnames.ora_uat8002 tnsnames.ora

regedit /s c:\adi\uat8002.reg

goto end

:DEV8003
ECHO DEV8003 selected.
del /q C:\orant\NET80\ADMIN\sqlnet.ora
del /q C:\orant\NET80\ADMIN\tnsnames.ora
del /q C:\orant\NETWORK\ADMIN\sqlnet.ora
del /q C:\orant\NETWORK\ADMIN\tnsnames.ora

copy C:\ADI\tnsnames.ora_dev8003 C:\orant\NETWORK\ADMIN\
copy C:\ADI\tnsnames.ora_dev8003 C:\orant\NET80\ADMIN\

ren C:\orant\NETWORK\ADMIN\tnsnames.ora_dev8003 tnsnames.ora
ren C:\orant\NET80\ADMIN\tnsnames.ora_dev8003 tnsnames.ora

regedit /s c:\adi\dev8003.reg
goto end

:PTH8018
ECHO PTH8018 selected.
del /q C:\orant\NET80\ADMIN\sqlnet.ora
del /q C:\orant\NET80\ADMIN\tnsnames.ora
del /q C:\orant\NETWORK\ADMIN\sqlnet.ora
del /q C:\orant\NETWORK\ADMIN\tnsnames.ora

copy C:\ADI\tnsnames.ora_pth8018 C:\orant\NETWORK\ADMIN\
copy C:\ADI\tnsnames.ora_pth8018 C:\orant\NET80\ADMIN\

ren C:\orant\NETWORK\ADMIN\tnsnames.ora_pth8018 tnsnames.ora
ren C:\orant\NET80\ADMIN\tnsnames.ora_pth8018 tnsnames.ora

regedit /s c:\adi\pth8018.reg
goto end

:Cancel
exit

:end
start C:\orant\BIN\GLDI9032.EXE