Tag: how

  • Get Primary, Secondary, Tertiary DNS values and more from Multiple Servers

    Get Primary, Secondary, Tertiary DNS values and more from Multiple Servers

    Came across a unique request to get primary, secondary, and tertiary DNS values for multiple computers/servers across the domain. I started writing the script and got what I wanted.

    Now this started off as just to query for DNS Server information, but then I thought to add other pieces to get myself a good Network Inventory of all the servers in the environment.

    I am utilizing the Win32_NetworkAdapterConfiguration WMI Class to get the required information.

    You can modify the script below to suit your needs. The complete list of settings that can be captured:

      string   Caption;
      string   Description;
      string   SettingID;
      boolean  ArpAlwaysSourceRoute;
      boolean  ArpUseEtherSNAP;
      string   DatabasePath;
      boolean  DeadGWDetectEnabled;
      string   DefaultIPGateway[];
      uint8    DefaultTOS;
      uint8    DefaultTTL;
      boolean  DHCPEnabled;
      datetime DHCPLeaseExpires;
      datetime DHCPLeaseObtained;
      string   DHCPServer;
      string   DNSDomain;
      string   DNSDomainSuffixSearchOrder[];
      boolean  DNSEnabledForWINSResolution;
      string   DNSHostName;
      string   DNSServerSearchOrder[];
      boolean  DomainDNSRegistrationEnabled;
      uint32   ForwardBufferMemory;
      boolean  FullDNSRegistrationEnabled;
      uint16   GatewayCostMetric[];
      uint8    IGMPLevel;
      uint32   Index;
      uint32   InterfaceIndex;
      string   IPAddress[];
      uint32   IPConnectionMetric;
      boolean  IPEnabled;
      boolean  IPFilterSecurityEnabled;
      boolean  IPPortSecurityEnabled;
      string   IPSecPermitIPProtocols[];
      string   IPSecPermitTCPPorts[];
      string   IPSecPermitUDPPorts[];
      string   IPSubnet[];
      boolean  IPUseZeroBroadcast;
      string   IPXAddress;
      boolean  IPXEnabled;
      uint32   IPXFrameType[];
      uint32   IPXMediaType;
      string   IPXNetworkNumber[];
      string   IPXVirtualNetNumber;
      uint32   KeepAliveInterval;
      uint32   KeepAliveTime;
      string   MACAddress;
      uint32   MTU;
      uint32   NumForwardPackets;
      boolean  PMTUBHDetectEnabled;
      boolean  PMTUDiscoveryEnabled;
      string   ServiceName;
      uint32   TcpipNetbiosOptions;
      uint32   TcpMaxConnectRetransmissions;
      uint32   TcpMaxDataRetransmissions;
      uint32   TcpNumConnections;
      boolean  TcpUseRFC1122UrgentPointer;
      uint16   TcpWindowSize;
      boolean  WINSEnableLMHostsLookup;
      string   WINSHostLookupFile;
      string   WINSPrimaryServer;
      string   WINSScopeID;
      string   WINSSecondaryServer;

    Since the scripts are querying for information it is best if it runs from a DC or a privileged server with an account that has privileged access.

    To get the results you need the following two scripts:

    I needed to get all the network information for all the domain controllers in the domain. So the following code retrieves it for me. This came really handy in viewing all the DNS settings setup on all the DCs and correcting them if needed.

    This will get the information and export to an excel file that you can have handy for reference or auditing. Hope this helps!

  • Convert a Dynamic IP to Static

    Convert a Dynamic IP to Static

    Working on a project where on some servers the DHCP assigned addresses needs to be converted to static. Since there is always more than one…I needed to script it.

    Here is a quick way to do it via PowerShell.

    Hope this helps!

  • Hack: Microsoft Outlook AutoComplete

    Hack: Microsoft Outlook AutoComplete

    Outlook maintains the AutoComplete list. The list is used by both the automatic name-checking feature and the automatic completion feature. The AutoComplete list, also known as the nickname cache, is generated automatically when you send email messages from Outlook. The list contains SMTP addresses, LegacyExchangeDN entries, and display names for people to whom you have sent mail previously.

    [su_note note_color=”#fafae8″]Note The AutoComplete list for Outlook is specific to Outlook and is not shared by Outlook Web App (OWA). OWA maintains its own AutoComplete list.[/su_note]

    The following sections provide information about the AutoComplete feature.

    Limit to the number of entries

    Outlook limits the number of entries that you can save in the AutoComplete list. After you reach this limit, Outlook uses an internal algorithm to determine the best names to remove from the list. It does this based on a usage weighting. Therefore, you may find some names unexpectedly removed from your nickname cache. There are two general approaches that you can use to avoid this situation:

    1. You can proactively remove AutoComplete list entries that you no longer need. This is the preferred approach. For more information about how to do this, see the section titled “How to remove AutoComplete list entries one at a time.”
    2. You can increase the limit for the nickname cache. If you have a larger nickname cache, you could also lose a larger number of cached entries if your nickname cache becomes unusable because of corruption.

    The limits are as follows:

    • Outlook 2016: 1,000 entries
    • Outlook 2013: 1,000 entries
    • Outlook 2010: 1,000 entries
    • Outlook 2007: 2,000 entries
    • Outlook 2003: 1,000 entries

    How to enable the AutoComplete feature

    Outlook 2010, Outlook 2013, and Outlook 2016

    To access the AutoComplete setting, follow these steps:

    • On the File menu, click Options.
    • Select the Mail tab.
    • Scroll approximately halfway down until you see Send messages. Make sure that the Use Auto-Complete List to suggest names when typing in the To, Cc, and Bcc lines box is checked. If you need to disable Auto-Complete uncheck the box.

    How to import .nk2 files into Outlook 2010, Outlook 2013, and Outlook 2016

    Microsoft Office Outlook 2007 and earlier versions store the AutoComplete list in an nickname (.nk2) file on the disk. Outlook 2010, Outlook 2013, and Outlook 2016 store the AutoComplete list as a hidden message in your primary message store. Outlook 2010, Outlook 2013, and Outlook 2016 let you import the older .nk2 files.

    For more information about how to import .nk2 files in Outlook 2010, go to the following Microsoft website:

     

    How to import .nk2 files into Outlook 2013 or Outlook 2016

    When you start Microsoft Outlook 2013 or Outlook 2016 for the first time, your nickname cache (stored in the  profilename.nk2 file) is imported into a hidden message in your default message store.

    [su_note note_color=”#fafae8″]Note profilename is the name of your Outlook profile.[/su_note]

    For example, if you are using a Microsoft Exchange account, the nickname cache is imported into a hidden message in the Exchange mailbox.

    Note Outlook 2007 and earlier versions store the nickname cache .nk2 file in the following folder.

    • Windows XP
      Drive:\Documents and Settings\Username\Application Data\Microsoft\Outlook
    • Windows Vista and later versions
      Drive:\Users\Username\AppData\Roaming\Microsoft\Outlook

    After the nickname cache is imported, the
    profilename.nk2 file is renamed to
    profilename.nk2.old. On the next start of Outlook, your nickname cache is not imported. Outlook 2013 and Outlook 2016 do not use the .nk2 file for maintaining your nickname cache. All updates to your nickname cache in Outlook 2013 and Outlook 2016 are made to the hidden message in your default message store.

    Note If you have multiple Outlook profiles, the nickname cache from each profile is merged into your new Outlook 2013 or Outlook 2016 nickname cache on the first start of Outlook by using that profile. Therefore, you may find more than one .nk2 file renamed to .nk2.old.

    However, there may be situations where you have to import a nickname cache file after this first-run nickname cache import process has finished. For example, a colleague wants to share their nickname cache with you and you want to update your existing nickname cache with your colleague’s data.

    To import .nk2 files into Outlook 2013 or Outlook 2016, follow these steps:

    • Make sure that the .nk2 file is in the following folder:
      %appdata%\Microsoft\Outlook

      Note The .nk2 file must have the same name as your current Outlook 2013 or Outlook 2016 profile. By default, the profile name is “Outlook.” To check the profile name, follow these steps:

      1. Click Start, and then click
        Control Panel.
      2. Double-click Mail.
      3. In the Mail Setup dialog box, click
        Show Profiles.
    • Click Start, and then click
      Run.
    • In the Open box, type
      outlook.exe /importnk2 , and then click
      OK. This should import the .nk2 file into the Outlook profile.

    [su_note note_color=”#fafae8″]Note After you import the .nk2 file, the contents of the file are merged into the existing nickname cache that is currently stored in your mailbox.[/su_note]

    [su_note note_color=”#fafae8″] Note The .nk2 file is renamed with a .old file name extension on the first start of Outlook 2013 or Outlook 2016. Therefore, if you try to re-import the .nk2 file, remove the .old file name extension.[/su_note]

    How to copy the AutoComplete list

    The steps to export and import the AutoComplete list are different, depending on the version of Outlook that you are using.

    Outlook 2010, Outlook 2013, and Outlook 2016

    To copy the AutoComplete list in Outlook 2010, Outlook 2013, and Outlook 2016, follow these steps:

    [su_tooltip position=”north” content=”To change the text to lowercase Goto: TextFX > TextFX Characters > lower case”]Note: Please make sure the you are using the appropriate MFCMAPI for x86 or x64.[/su_tooltip]

    Step 1

    To export the AutoComplete mailbox message, follow these steps:

    1. Exit Outlook, and then close Outlook Web Access or Outlook Web App (OWA) on all workstations that are connected to your mailbox.
    2. Download and install MFCMAPI from http://mfcmapi.codeplex.com.
    3. Run mfcmapi.exe.
    4. On the Session menu, click Logon.

    5. If you are prompted for a profile, select the desired profile name, and then click OK.

    6. In the top pane, locate the line that corresponds to your mailbox, and then double-click it.
    7. In the left-side navigation pane, expand Root Container, and then expand Top of Information Store or IPM_SUBTREE.
    8. Right-click the Inbox folder, and then click Open Associated Content Table. This action opens a new MFCMAPI window that contains various properties.

    9. Under the Subject column, right-click the item that has the subject IPM.Configuration.Autocomplete,


      and then click Export Message. This action opens the Save Message To File window.

    10. In the drop-down list, select MSG file (UNICODE), and then click OK.
    11. Select a folder location to which you want to save the message, and then click Save. Note this location.

    Step 2

    To import the AutoComplete mailbox message, follow these steps.

    1. Exit Outlook, and then close Outlook Web Access or Outlook Web App (OWA) on all workstations that are connected to your mailbox.
    2. Download and install MFCMAPI from http://mfcmapi.codeplex.com
    3. Run mfcmapi.exe.
    4. On the Session menu, click Logon.
    5. If you are prompted for a profile, select the desired profile name, and then click OK.
    6. In the top pane, locate the line that corresponds to your mailbox, and then double-click it.
    7. In the left-side navigation pane, expand Root – Mailbox, and then expand Top of Information Store or IPM_SUBTREE.
    8. Right-click the Inbox folder, and then click Open Associated Content Table. This action opens a new MFCMAPI window that contains various properties.
    9. To avoid duplicate entries, you must delete the existing AutoComplete message.

      [su_note note_color=”#fafae8″]Note: Before you delete the IPM.Configuration.Autocomplete message, you must export the message.[/su_note]

      To delete the existing AutoComplete message, follow these steps:

      1. In the Subject column, locate the item that has the subject IPM.Configuration.Autocomplete.
      2. Right-click the item, and then click Delete message. This opens the Delete Item window.
      3. In the drop-down list, select Permanent deletion (deletes to deleted item retention if supported), and then click OK.
      4. On the Folder menu, click Import, and then click From MSG.

      5. Locate the .msg file that you created in step 11 of the “How to Export the Auto-Complete List” section, and then click OK.
      6. In the Load MSG window that appears, select Load message into current folder in the Load style list, and then click OK.

    The AutoComplete information is imported from the IPM.Configuration.Autocomplete_<hexadecimal code>.msg , where the placeholder<hexadecimal code>  represents a long string of numbers and letters.

    How to remove AutoComplete list entries one at a time

    To remove entries from the AutoComplete cache one entry at a time, follow these steps:

    1. Open a new email message.
    2. Type the first few characters of the AutoComplete entry that you want to remove.
    3. When the entry appears in the list of suggested names, move your mouse pointer over the name until it becomes highlighted, but do not click the name.
    4. When the “X” icon appears next to the highlighted name, click X to remove the name from the list, or press the Delete key on the keyboard.

    How to clear the whole AutoComplete list

    This section explains how to delete the AutoComplete list.

    Outlook 2010, Outlook 2013, and Outlook 2016

    Use one of the following two methods to delete the AutoComplete list in Outlook 2010, Outlook 2013, and Outlook 2016.

    Method 1

    1. Open Outlook.
    2. On the File tab, click Options.
    3. Click the Mail tab.
    4. Under Send Messages, click Empty Auto-Complete List.

    5. Click Yes.

    Method 2

    Start Outlook by using the /CleanAutoCompleteCache switch. To do this, follow these steps:

    1. Click Start, and then click Run.
    2. Type Outlook.exe /CleanAutoCompleteCache .

      Note If Outlook is not installed in the default location, you must point to the path of Outlook.exe.

    Filling the Auto-Complete list with Contact addresses

    You can directly fill the list again by creating a new message addressed to all your contacts at once.

    1. Place Outlook in ‘Work Offline’ mode (see instructions below)
    2. Create a new message.
    3. Press the To… button.
    4. Select the contact list in the right top corner from which you would like to add the contacts from.
      Examples; Contacts folder, Global Address List (GAL) or a contacts folder in a Public folder.
    5. Select the first contact.
    6. Scroll all the way down to your last contact.
    7. Hold the SHIFT button on your keyboard while clicking on the last contact to select them all.
    8. Press the To –> button to add them all to the To… field.
    9. Repeat step 3 to 7 if you have contacts in additional lists that you would like to add.
    10. Press OK to close the dialog and to return to the newly created message.
    11. Now when you address a new message the AutoSuggest/Auto-Complete feature will pop-up again.

    For Outlook 2010, Outlook 2013 and Outlook 2016, you must send the message to actually store these addresses in the AutoSuggest cache. However, by placing Outlook in Offline Mode first via the Send/Receive tab, you can easily prevent it from actually being sent by removing it from the Outbox and then place Outlook back online mode.

    Working in Offline Mode

    This is fairly simple for folks that dont know.

    The main confusion is about Work Offline icon which is being displayed on the Send/Receive tab in the Ribbon in Outlook 2010 and Outlook 2013; you’ll find a globe with a red cross in front of it. This doesn’t mean you are in Offline Mode as the icon is always like this. The icon doesn’t change to for instance a globe without a red cross when you are Online

    When you actually are in Offline Mode, the icon will show highlighted (as see below, when using a black color theme for Office 2016)  and your Status Bar will also show “Working Offline”. Clicking on the icon then will bring you back to Online Mode.

    Status Bar:

    POP3 Accounts:

    When you are using a POP3 account, you can reuse your original pst-file on another computer or when reconfiguring the account without losing your AutoComplete cache. However, it is important that you do this in the correct way or the list will still be lost.

  • How to Configure Time Server (NTP Server) on Centos 7?

    How to Configure Time Server (NTP Server) on Centos 7?

    Prerequisites:

    VM/ Physical – It is recommended to have the time server as a physical server, but VMs should be okay depending on your setup and requirement. My virtual lab environment is VMware based so here’s the guide for a VM. Once the CentOS Minimal is installed on the VM make sure to install open-vm-tools.

    yum install open-vm-tools

    If you are not conformable with Vi Editor please use install nano for editing.

    yum install nano

    Installing the time server:

    1. First we need to install NTPd . to do this open command line :
      [root@mytimesrv01 ~]# yum -y install ntp
    2. Then open NTP main configuration file for editing:[su_note note_color=”#fafae8″]If you are planning on hosting your time servers externally like time01.yourdomain.com, time02.yourdomain.com with ports 123 open on the firewall. Each of the time server will be talking to 0.us.pool.ntp.org, 0.us.pool.ntp.org, 0.us.pool.ntp.org, 0.us.pool.ntp.org. Later on you can probably add your time servers to the NTP.org by joining the pool. For my example, I am not using the centos default pool, but i am using the U.S. zone. For internal servers/workstations you can point it to the local ip/dns name for the local time servers.[/su_note]
      [root@mytimesrv01 ~]# vi /etc/ntp.conf
      # For more information about this file, see the man pages
      # ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).
      
      driftfile /var/lib/ntp/drift
      
      # Permit time synchronization with our time source, but do not
      # permit the source to query or modify the service on this system.
      restrict default nomodify notrap nopeer noquery
      
      # Permit all access over the loopback interface. This could
      # be tightened as well, but to do so would effect some of
      # the administrative functions.
      restrict 127.0.0.1
      restrict ::1
      
      # Hosts on local network are less restricted.
      #restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
      
      # Use public servers from the pool.ntp.org project.
      # Please consider joining the pool (http://www.pool.ntp.org/join.html).
      
      #Your time servers go here:
      server 0.us.pool.ntp.org iburst
      server 1.us.pool.ntp.org iburst
      server 2.us.pool.ntp.org iburst
      server 3.us.pool.ntp.org iburst
      
      #Default OOB time servers
      #server 0.centos.pool.ntp.org iburst
      #server 1.centos.pool.ntp.org iburst
      #server 2.centos.pool.ntp.org iburst
      #server 3.centos.pool.ntp.org iburst
      
      #broadcast 192.168.1.255 autokey # broadcast server
      #broadcastclient # broadcast client
      #broadcast 224.0.1.1 autokey # multicast server
      #multicastclient 224.0.1.1 # multicast client
      #manycastserver 239.255.254.254 # manycast server
      #manycastclient 239.255.254.254 autokey # manycast client
      
      # Enable public key cryptography.
      #crypto
      
      includefile /etc/ntp/crypto/pw
      
      # Key file containing the keys and key identifiers used when operating
      # with symmetric key cryptography.
      keys /etc/ntp/keys
      
      # Specify the key identifiers which are trusted.
      #trustedkey 4 8 42
      
      # Specify the key identifier to use with the ntpdc utility.
      #requestkey 8
      
      # Specify the key identifier to use with the ntpq utility.
      #controlkey 8
      
      # Enable writing of statistics records.
      #statistics clockstats cryptostats loopstats peerstats
      
      # Disable the monitoring facility to prevent amplification attacks using ntpdc
      # monlist command when default restrict does not include the noquery flag. See
      # CVE-2013-5211 for more details.
      # Note: Monitoring will not be disabled with the limited restriction flag.
      disable monitor
      
      logfile /var/log/ntp.log
    3. Then start and enable ntp server:
      [root@mytimesrv01 ~]# systemctl start ntpd
      [root@mytimesrv01 ~]# systemctl enable ntpd
    4. You need to allow ntp service on firewall(NTP service uses UDP port 123). So run next command:
      [root@mytimesrv01 ~]# firewall-cmd –add-service=ntp –permanent
      success
      [root@mytimesrv01 ~]# firewall-cmd –reload
      success
    5. Verify you ntp service with next command:
      [root@mytimesrv01 ~]# ntpq -p

    Your output should be similar to:

  • How to restart management agents on ESX or ESXi host

    How to restart management agents on ESX or ESXi host

    If you are not unable to connect ESXi server to vCenter, or when you cannot connect to ESXi server from VI client it may be necessary to restart the management agents on ESX or ESXi host.

    To restart the management agents on ESXi 6.x

    This applies to ESX4/5.x/6.x

    For the restart of the management agents (mgmt-vmware and vmware-vpxa) do the following:

    Log in to SSH or Local console as root.
    Run these commands:

    /etc/init.d/hostd restart
    /etc/init.d/vpxa restart

    Or also (alternative way)
    To reset the management network on a specific VMkernel interface, by default vmk0, run the command:

    esxcli network ip interface set -e false -i vmk0; esxcli network ip interface set -e true -i vmk0

    [su_note note_color=”#fafae8″]Note: Using a semicolon (;) between the two commands ensures the VMkernel interface is disabled and then re-enabled in succession. If the management interface is not running on vmk0, change the above command according to the VMkernel interface used.[/su_note]

    to restart all management agents on the host, run the command:

    services.sh restart

    To restart the Management agents on ESXi Server – via the console:

    1.) Connect to the console of your ESX Server and press F2
    2.) Login as root and when using the Up/Down arrows navigate to Restart Management Agents.
    3.) Press Enter and press F11 to restart the services.
    4.) When the service has been restarted, press Enter. Then you can press Esc to logout of the system.

    Screen should be similar to:

    To restart the management agents on ESXi 4.x and 5.x:

    From Local Console or SSH:
    1. Log in to SSH or Local console as root.
    2. Run this command:
    /sbin/services.sh restart

    You can also check:  Service mgmt-vmware restart may not restart hostd (1005566).

    To restart the management agents on ESX Server 3.x, ESX 4.x:

    1. Login to your ESX Server as root from SSH session or directly from the console.
    2. Type service mgmt-vmware restart  and press Enter
      Make sure that automatic Startup/Shutdown of virtual machines is disabled before running this command otherwise you might reboot the virtual machines. See more at 103312
    3. Type service vmware-vpxa restart and press Enter.
    4. Type logout and press Enter to disconnect from the ESX Server.

    Successful output :

    Stopping vmware-vpxa: [ OK ]
    Starting vmware-vpxa: [ OK ]

    This may also server as a solution for the error “Unable to access file since it is locked. An error occurred while consolidating disks: One or more disks are busy.”