Thursday, October 24, 2013

How to use esxtop

I found this great article full of benefitial references for using esxtop. Here it is: http://www.yellow-bricks.com/esxtop/

How to download a diagnostic log bundle from an ESX/ESXi host using PowerCLI

Login to desired host using PowerCLI:
Connect-VIServer -Server HostnameOrIPAddress

Download a diagnostic log bundle from host:
Get-VMHost HostNameOrIP | Get-Log -Bundle -DestinationPath c:\Storage\Location\




 

Tuesday, September 17, 2013

More usefull powershell commands

Alternate authentication cmdlet
Sometimes it is pretty useful to be able and use alternate credentials in PowerShell command. This can be done by using Get-Credential cmdlet but a downside is that you can not specify password. Instead what will happen every time this cmdlet is ran it will produce a popup box to enter password.
A nice workaround is to store the credentials in encrypted variable such as $cred = Get-Credential Administrator this will initially pop up with authentication box where password is typed in but afterwards you can use $cred variable in your session without need to type it in again.

Run PowerShell command in background and keep control of your session for other tasks
In the situation where we need to run a cmdlet where output will take a while to be produced we can use -asjob switch. This will give us back our prompt to run additional command while our initial query will run in the background. Some of the related cmdlets with which we can control or view jobs are: Get-Job, Receive-Job, Remove-Job, Resume-Job, Start-Job, Stop-Job, Suspend-Job, Wait-Job

Output text in PowerShell
Write-Output

Input some text into powershell
Read-Host

Convert output of query to HTML
This is specifically usefully if desired output needs to be shared for wide audience. All needs to be done is convert it to HTML using ConvertTo-hmtl and output to file using Out-File to write contents into file on web server and your info is readily available for brain consumption.

Import contents of file into PowerShell for processing
Best example for this would be creating multiple users in AD from predefined csv file. We can use Import-CSV cmdlet to take a contents of csv file and pipe it into another cmdlet such as Import-CSV file.csv | New-ADUser. Please note that header of csv file should contain valid AD properties for user. Whichever properties you have, those properties will be created along with a user.

Tuesday, September 10, 2013

Basic help powershell commands that make life easier

get-help
displays help for desired commandlet

get-help -full
displays full help for desired commandlet including examples

get-help -online
if you have internet access this will display online help for any commandlets desired

update-help
downloads and installs help files from internet

show-command
opens gui for desired commandlet where you can see whole bunch of options and parameters. If desired these parameters can be filled out in gui and copied to run in PowerShell window in order to see exact syntax

get-command
this will list commands that pertain not only to PowerShell but a whole system

get-member
gets the properties and methods of objects. This is very useful to see what custom fields/methods you can use for specific cmdlet




Monday, September 9, 2013

Script to find files in size greater than desired size

Very useful when you need to find large size files on your system. This command can be run locally or on remote system as long as you have admin rights to remote system.


Get-ChildItem \\servername\c$ -Recurse -ErrorAction "SilentlyContinue" | Where-Object {$_.Length -gt 100MB} | Export-Csv c:\temp\myLargeFilesOnC_Report1.csv

Monday, September 2, 2013

Gracefully shutdown VM using PowerCLI

This is very useful for me when I need to power off my lab at home (trying to conserver energy) :)

Prerequisites for this to work is that you have PowerCLI installed on your computer as well as vm tools installed on all vm's that you would like to utilize this on

Power off single machine:

get-vm vm-name | ShutdownVMGuest

Power off group of machines:

Create a text file with list of vm's you would like to shut down with each vm in separate line such as
vm1
vm2
vm3
Let say this file is called servers.txt and is located in c:\users\mike\desktop
First we will create variable to load servers from text files:
$servers = Get-Content -Path c:\users\mike\desktop\servers.txt
second we will use previous command to shut down group of servers in the file:
get-vm $servers | Shutdown-VMGuest

Turn on group of machines: (This please be careful with as if you try to turn on too many machines at one time you could potentially overload your ESX box)

Start-VM -VM $servers

Thursday, August 29, 2013

IP address already assigned to another adapter

This issue occurs if a network adapter with the same IP address is in the Windows registry but is hidden in the Device Manager (My Computer > Properties > Hardware > Device Manager). This hidden adapter is called a ghosted network adapter.

  • You may see this if you recently performed a P2V and the resulting virtual machine still has the physical NICs and drivers for those NICs present. These ghost NICs have the old IP address and the virtual NIC cannot be assigned the same IP address.

Using the Show hidden devices option in the Device Manager (View > Show hidden devices) does not always show the old virtual NIC (ghosted adapter) to which that IP Address is assigned.
 
To resolve this issue, make the ghosted network adapter visible in the Device Manager and uninstall the ghosted network adapter from the registry:
  1. Click Start > Run.
  2. Type cmd and press Enter.
  3. At the command prompt, run this command:
    Note: In Windows 2008 and Windows 7, open the command prompt using the Run as Administrator option.

    set devmgr_show_nonpresent_devices=1
    Note: If this command does not work (a possibility in Windows Server 2000 and 2003), you may need to add the parameter to Windows and set its value:

    1. Right-click the My Computer desktop icon and choose Properties.
    2. Click the Advanced tab and select Environment Variables.
    3. In the System variables section, click New.
    4. Set the Variable name to devmgr_show_nonpresent_devices and set the Variable value to 1 to enable the parameter.
    5. Click OK to add the variable to Windows.
  4. Start the Device Manager by running this command from the same command prompt:

    start devmgmt.msc
  5. Click View > Show Hidden Devices.
  6. Expand the Network Adapters tree (click the plus sign next to the Network adapters entry).
  7. Right-click the dimmed network adapter, then click Uninstall.
  8. Once all of the grayed out NICs are uninstalled, assign the IP address to the virtual NIC.

    Note: To assign the IP address to the virtual NIC on the command line, run the command:

    netsh interface ip set address "Local Area Connection #" static IP_Address Subnet_Mask Default_Gateway

    For example:

    netsh interface ip set address "Local Area Connection 2" static 192.168.1.101 255.255.255.0 192.168.1.1

  9. Close the Device Manager
Source of this article: VMware KB1179 

Wednesday, August 28, 2013

How to manually push update if Global Address Book Exchange 2010 Taking time to update new user


  1. Get-GlobalAddressList | Update-GlobalAddressList
  2. Get-OfflineAddressBook | Update-OfflineAddressBook
  3. Get-ClientAccessServer | Update-FileDistributionService
  4. Download Full OAB in outlook
  5. On the Tools menu, point to Send/Receive, and then click Download Address Book.
  6. In the Offline Address Book dialog box, make sure that the Download changes since last Send/Receive check box is checked.
  7. Click OK.

Tuesday, August 13, 2013

Query interface information on remote machines

I found a nice script for this task that can be found by following link:
Scrip Source

The powershell command to run in order to query list of computers from text file list would be as follows:
$computers = Get-Content -Path c:\scripts\servers.txt
.\getipinfo.ps1 -ComputerName $computers | ft -AutoSize


This is the actual script:
[cmdletbinding()]
param (
[parameter(ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
    [string[]]$ComputerName = $env:computername
)           

begin {}
process {
foreach ($Computer in $ComputerName) {
  if(Test-Connection -ComputerName $Computer -Count 1 -ea 0) {
   $Networks = Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName $Computer | ? {$_.IPEnabled}
   foreach ($Network in $Networks) {
    $IPAddress  = $Network.IpAddress[0]
    $SubnetMask  = $Network.IPSubnet[0]
    $DefaultGateway = $Network.DefaultIPGateway
    $DNSServers  = $Network.DNSServerSearchOrder
    $IsDHCPEnabled = $false
    If($network.DHCPEnabled) {
     $IsDHCPEnabled = $true
    }
    $MACAddress  = $Network.MACAddress
    $OutputObj  = New-Object -Type PSObject
    $OutputObj | Add-Member -MemberType NoteProperty -Name ComputerName -Value $Computer.ToUpper()
    $OutputObj | Add-Member -MemberType NoteProperty -Name IPAddress -Value $IPAddress
    $OutputObj | Add-Member -MemberType NoteProperty -Name SubnetMask -Value $SubnetMask
    $OutputObj | Add-Member -MemberType NoteProperty -Name Gateway -Value $DefaultGateway
    $OutputObj | Add-Member -MemberType NoteProperty -Name IsDHCPEnabled -Value $IsDHCPEnabled
    $OutputObj | Add-Member -MemberType NoteProperty -Name DNSServers -Value $DNSServers
    $OutputObj | Add-Member -MemberType NoteProperty -Name MACAddress -Value $MACAddress
    $OutputObj
   }
  }
}
}           

end {}

Controll Exchange 2010 mail delivery using cost and hub site

Set-ADSiteLink, this command would be very useful in cases where one wants to favor one site  for queuing  over another. The lower the cost more likely site will be used. Keep in mind that direct delivery is always attempted first and only if it fails site cost is used to queue messages in a different hub server in different site.

Set-ADSiteLink -Identity fromtositelink -ExchangeCost 5

Set-AdSite is a command that is used to enable particular hub in site to force all email to pass through it.

ENABLE:
Set-AdSite -Identity 'sitename' -HubSiteEnabled $true

DISABLE:
Set-AdSite -Identity 'sitename' -HubSiteEnabled $false

Modifying exchange 2010 receive connector using EMS

To modify existing receive connector by adding banner message and increasing size of messages allowed Set-ReceiveConnector command is used

Set-ReceiveConnector -Name 'Name of existing receive connector' -Banner '220 Custom application connector' -MaxMessageSize '20MB'

Creating exchange 2010 receive connector using EMS

Following command creates a connector to accept messages only from internal application server with IP 192.168.1.100

New-ReceiveConnector -Name 'New Receive Connector Name' -Usage Custom - bindings 0.0.0.0:25 -RemoteIPRanges '192.168.1.100' -Server 'Server Name' -AuthMechanism 'None'

Modifying exchange 2010 send connector using EMS


This command would enable protocol logging and increase message size to 20MB.


Set-SendConnector -Name 'Name of the connector' -ProtocolLoggingLevel 'Verbose' -MaxMessageSize '20MB'

Wednesday, July 10, 2013

Microsoft Active Directory Topology Diagrammer

Totally useful diagraming tool!!! It requires you to have Visio as well.
Get tool here from Microsoft

Microsoft Surface Pro going to sleep every 2 minutes

I have been dealing with this issue for a while now and kept putting it on back burner. Today I just got so pissed off that I decided to have this done now or never. And thank God I did!!

For whatever odd reason surface pro was going to sleep after 2 minutes no matter what my power options were set to. I tried all kinds of settings.

After some research I found that apparently there is a power setting not available in GUI on Microsoft windows 7 and 8 this setting is called "system unattended sleep timeout". If you add following registry setting:[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\PowerSettings\238C9FA8-0AAD-41ED-83F4-97BE242C8F20\7bc4a2f9-d8fc-4469-b07b-33eb785aaca0]
"Attributes"=dword:00000002

and go to power setting --> sleep - you will see a new option for "system unattended sleep timeout". Change this setting to your desired value and problems gone!!!!

Tuesday, May 21, 2013

Time sync with external NTP on windows server 2008 R2 DC

  1. Locate PDC - C:\>netdom /query fsmo
  2. Log in to PDC Server and open the command prompt.
  3. Stop the W32Time service: C:\>net stop w32time
  4. Configure the external time sources, type: C:\> w32tm /config /syncfromflags:manual /manualpeerlist:”0.pool.ntp.org, 1.pool.ntp.org, 2.pool.ntp.org”
  5. Make your PDC a reliable time source for the clients. Type: C:\>w32tm /config /reliable:yes
  6. Start the w32time service: C:\>net start w32time
  7. The windows time service should begin synchronizing the time. You can check the external NTP servers in the time configuration by typing: C:\>w32tm /query /configuration
  8. Check the Event Viewer for any errors.
NOTE: Make sure your firewall allows NTP out before you do this or your DC will not be able to contact outside NTP servers.

Thursday, February 28, 2013

Exchange DAG replication using secondary NIC betwene servers on different subnets

Recently I ran into a problem with Exchange 2010 DAG configuration. I needed to replicate databases between servers that were geographically in different sites and were each on their own separate subnets. For this purpose I wanted to use our secondary data line in order to avoid overloading our main production line with replication traffic. DAG was all set and replicating fine over production line but when I disabled replication on main NIC's and enabled it on secondary NIC's routed via secondary data line, Exchange was still pushing replication via primary NIC. Issue resolved after I collapsed DAG network on secondary ISP into a single DAG network adding both near and far subnet into it. Great article that talks just about that particular setup you can find right here: http://blogs.technet.com/b/timmcmic/archive/2011/09/26/exchange-2010-collapsing-dag-networks.aspx

Tuesday, February 5, 2013

Exchange 2010 view database info powershell commands

Get some info on database in particular size of it:
Get-MailboxDatabase -status | select Servername,name,databasesize

Get whole bunch of info for particular database
Get-MailboxDatabase -identity | fl

Some usefull powershell commands for fixing content index state when failed

Set content index state of particular database in PS:
Set-MailboxDatabase -identity -indexenabled $true

List databases with content index in failed state:
Get-MailboxDatabaseCopyStatus -Server   | ? {$_.contentindexstate -eq "failed"}

Reset search index for particular database ( need to be in script directory - C:\Program Files\Microsoft\Exchange Server\Scripts):
.\ResetSearchIndex.ps1 -force

Update replication of catalog only on database:
Update-MailboxDatabaseCopy -identity \ -CatalogOnly

Update catalog index state only on all failed databases:
Get-MailboxDatabaseCopyStatus -Server em-bk-exmb01  | ? {$_.contentindexstate -eq "failed"} | update-mailboxdatabasecopy -catalogonly