active directory

How to check Hyper-V replication status automatically

Copy and paste the following into a text file and save as c:\checkrep.ps1.

*****************************************************************

Add-PSSnapin Microsoft.Exchange.Management.Powershell.Admin -erroraction silentlyContinue

##### Configuration Section Starts #####

$SMTPName = “mail.ncol.net”
$EmailMessage = new-object Net.Mail.MailMessage
$SMTPServer = new-object Net.Mail.SmtpClient($SMTPName)
$EmailMessage.From = “admin@domain.com”
$EmailMessage.To.Add(“techsupp@ncol.net”)
#$EmailMessage.To.Add(“9197021111@vtext.com”)

##### Configuration Section Ends#####

#Build a nice file name
$date = get-date -Format M_d_yyyy_hh_mm_ss
$csvfile = “.\AllAttentionRequiringVMs_”+$date+”.csv”

#Build the header row for the CSV file
$csv = “VM Name, Date, Server, Message `r`n”

#Find all VMs that require your attention
$VMList = get-vm | where {$_.ReplicationHealth -eq “Critical” -or $_.ReplicationHealth -eq “Warning”}

#Loop through each VM to get the corresponding events
ForEach ($VM in $VMList)
{
$VMReplStats = $VM | Measure-VMReplication

#We should start getting events after last successful replication. Till then replication was happening.
$FromDate = $VMReplStats.LastReplicationTime

#This string will filter for events for the current VM only
$FilterString = “<QueryList><Query Id=’0′ Path=’Microsoft-Windows-Hyper-V-VMMS-Admin’><Select Path=’Microsoft-Windows-Hyper-V-VMMS-Admin’>*[UserData[VmlEventLog[(VmId='” + $VM.ID + “‘)]]]</Select></Query></QueryList>”

$EventList = Get-WinEvent -FilterXML $FilterString  | Where {$_.TimeCreated -ge $FromDate -and $_.LevelDisplayName -eq “Error”} | Select -Last 3

#Dump relevant information to the CSV file
foreach ($Event in $EventList)
{
If ($VM.ReplicationMode -eq “Primary”)
{
$Server = $VMReplStats.PrimaryServerName
}
Else
{
$Server = $VMReplStats.ReplicaServerName
}
$csv +=$VM.Name + “,” + $Event.TimeCreated + “,” + $Server + “,” + $Event.Message +”`r`n”
}
}

#Create a file and dump all information in CSV format
$fso = new-object -comobject scripting.filesystemobject
$file = $fso.CreateTextFile($csvfile,$true)
$file.write($csv)
$file.close()

#If there are VMs in critical health state, send an email to me and my colleague
If ($VMList -and $csv.Length -gt 33)
{
$Attachment = new-object Net.Mail.Attachment($csvfile)
$EmailMessage.Subject = “[ATTENTION] Replication requires your attention!”
$EmailMessage.Body = “The report is attached.”
$EmailMessage.Attachments.Add($Attachment)
$SMTPServer.Send($EmailMessage)
$Attachment.Dispose()
}
Else
{
$EmailMessage.Subject = “[NORMAL] All VMs replicating Normally!”
$EmailMessage.Body = “All VMs are replicating normally. No further action is required at this point.”
$SMTPServer.Send($EmailMessage)
}

*****************************************************************

Change the relevant email information at the beginning of the document.

Now open Task Scheduler.

Create a Basic Task. Name it Check Replication. Next.

Set the Trigger to the frequency you want the script to run. Next.

Set the Action to Start A Program. Next.

Enter powershell.exe in the Program box.

Enter c:\checkrep.ps1 in the Add Arguments box.

Enter c:\ in the Start In box. Next.

Open the properties of the Task and on the General tab select “Run whether user is  logged in or not” and “Run with the highest privileges”.

******************************************************************

If you receive an error:

“Your script is blocked from executing due to the execution policy.”

You need to set it on the client PC to Unrestricted. You can do that by calling Invoke with

Set-ExecutionPolicy Unrestricted

within Windows Powershell (x86) app.

How to configure an internal relay connector for Exchange 2013

Go to the webpage of the exchange management page (https://exchangeserver/ecp)
Go to the Mail flow > Receive Connectors > + for add a new connector.

exchrelay1

Enter a name for the connector. If you want to relay outside your organization than you need to select Frontend Transport role instead of the Hub Transport role.

exchrelay2

Leave the setting below unchanged.

exchrelay3

Remove the IP address which are shown in the picture below.

exchrelay4

You get an error that the field is required. (click on the + to add a new range)exchrelay5

Enter a single IP address or a local LAN address which is allowed to email via the exchange server.

 

 

 

exchrelay6

The remote network settings will show the list like below.exchrelay7

When clicked on finished. You have to edit the relay connector and go to security tab.
Select the option “Anonymous users”.exchrelay8

Click on Save..

Now you have to open a powershell CLI of exchange on the exchange server ( with administrative rights ).

Get-ReceiveConnector “Receive Connector Name” | Add-ADPermission -User “NT AUTHORITY\ANONYMOUS LOGON” -ExtendedRights “Ms-Exch-SMTP-Accept-Any-Recipient”

 

Exchange 2013 mailbox move stuck at StatusDetail FailedOther

You have to remove the current move request and resubmit:

Remove-MoveRequest -Identity userID

New-MoveRequest -Identity “userID” -TargetDatabase “Mailbox Database 0422167200” -BatchName “userID” -BadItemLimit “200”

Perform a full backup on Exchange to purge logs

1. Open Command prompt as Administrator
2. Launch Diskshadow

A.Add volume d:
B.(optional, add one line for each additional drive to include) Add volume X:
C.Begin Backup
D.Create
E.End Backup

3. At this step you should notice the following events in the application log indicating that the backup was indeed successful and logs will now be deleted.

Here’s some screenshots from the process:

Command promptdiskshadow

Event Logese-event-id-2005

 

 

How to Setup a Legal Notice Before Login in Group Policy

This is a very easy setting that may also substitute for signing the computer usage agreements every year.
legal-notice-group-policy-settings
1.Open up your Group Policy Management Console (gpmc.msc)
2.Go to the Group Policy Object in your domain, right click on Default Domain Policy and select Edit…
3.Once the Group Policy Editor is up, using the treeview on on the left go to Computer Configuration > Windows Settings > Security Settings > Local Policies > Security Options
4.To edit the title of the windows change: Interactive logon:Message title for users attempting to log on
5.To edit the message text change: Interactive Logon:Message text for users attempting to log on

101 Free Network Monitoring Tools

http://www.gfi.com/blog/101-free-admin-tools/

How to add Trusted Sites

We need to go to the Computer Configuration ““> Administrative Tools ““> Windows Components ““> Internet Explorer ““> Internet Control Panel ““> Security Page and then double click to the zone assignment list in the right pane as you can see below.

iegp1

After you double click on site to the zone assignment list you will see a window to enable the settings and configure it. Click enabled. Then click show. On the show contents screen click add.

iegp2

By clicking add we can add URLs and specify what zone we want them to be placed in like so:

iegp3

The number 2 denotes the number of the zone. In this case it is the trusted zone. Microsoft breaks down the settings as follows:

  1. Intranet zone – sites on your local network.
  2. Trusted Sites zone – sites that have been added to your trusted sites.
  3. Internet zone – sites that are on the Internet.
  4. Restricted Sites zone – sites that have been specifically added to your restricted sites.

After clicking OK you can wait for your default refresh of Group Policy which is 15 minutes by default or you can run gpupdate.exe from any workstation to see if it worked. You can also restart the workstations to force the update.

 

To configure the behavior of Automatic Updates


 

  1. In Group Policy Object Editor, expand Computer Configuration, expand Administrative Templates, expand Windows Components, and then click Windows Update.
  2. In the details pane, click Configure Automatic Updates.
  3. Click Enabled and select one of the following options:
    • Notify for download and notify for install. This option notifies a logged-on administrative user prior to the download and prior to the installation of the updates.
    • Auto download and notify for install. This option automatically begins downloading updates and then notifies a logged-on administrative user prior to installing the updates.
    • Auto download and schedule the install. If Automatic Updates is configured to perform a scheduled installation, you must also set the day and time for the recurring scheduled installation.
    • Allow local admin to choose setting. With this option, the local administrators are allowed to use Automatic Updates in Control Panel to select a configuration option of their choice. For example, they can choose their own scheduled installation time. Local administrators are not allowed to disable Automatic Updates.
  4. Click OK.

How to create mapped drives in Group Policy

To create a new Mapped Drive preference item

  1. Open the Group Policy Management Console . Right-click the Group Policy object (GPO) that should contain the new preference item, and then click Edit .
  2. In the console tree under User Configuration , expand the Preferences folder, and then expand the Windows Settings folder.
  3. Right-click the Drive Maps node, point to New , and select Mapped Drive .
  4. In the New Drive Properties dialog box, select an Action for Group Policy to perform. (For more information, see “Actions” in this topic.)
  5. Enter drive map settings for Group Policy to configure or remove. (For more information, see “Drive map settings” in this topic.)
  6. Click the Common tab, configure any options, and then type your comments in the Description box. (For more information, see Configure Common Options.)
  7. Click OK . The new preference item appears in the details pane.

Disable Firewall on users using group policy in server 2008, 2012

Computer Config > Administrative Templates > Network > Network connections > Windows Firewall > Domain Profile  > Windows Firewall: Protect all network connections = Disabled

After that go to client machine;

Start > Run > CMD > Gpupdate /force

Reboot.

How To Enable Remote Desktop Via Domain Group Policy Windows Server 2012 / 2008 R2 / 2008

Open the Group Policy Management and create a new GPO, and edit.

1 – Computer Configuration > Policies > Administrative Templates > Network > Network Connections > Windows Firewall > Domain Profile > “Windows Firewall: Allow Inbound Remote Desktop Exception”

2 –  Computer Configuration > Policies > Administrative Templates > Windows Components > Remote Desktop Services > Remote Desktop Session Host > Connections > enable the policy “Allow Users to connect remotely using Remote Desktop Services” Note: this used to be  > Windows Components > Terminal Services > “Allow users to connect remotely using Terminal Services”

To deploy printers to users or computers by using Group Policy

To deploy printer connections to users or computers by using Group Policy, you must add the printer connections to a Group Policy object (GPO) as described in the procedure.

To deploy printers to users or computers by using Group Policy

  1. Open Print Management.
  2. In the left pane, click Print Servers, click the applicable print server, and click Printers.
  3. In the center pane, right-click the applicable printer, and then click Deploy with Group Policy.
  4. In the Deploy with Group Policy dialog box, click Browse, and then choose or create a new GPO for storing the printer connections.
  5. Click OK.
  6. Specify whether to deploy the printer connections to users, or to computers:
    • To deploy to groups of computers so that all users of the computers can access the printers, select the The computers that this GPO applies to (per machine) check box.
    • To deploy to groups of users so that the users can access the printers from any computer they log onto, select the The users that this GPO applies to (per user) check box.
  7. Click Add.
  8. Repeat steps 3 through 6 to add the printer connection setting to another GPO, if necessary.
  9. Click OK.

Change Windows password in Remote Desktop

CTRL-ALT-END is the key combo to send a CTRL-ALT-DEL to the remote RDP desktop. Useful for changing passwords on workstations and servers remotely.

How to clear a domain profile from a Windows 7 machine

To clear user local profile via registry:

  1. Press on Start > Run >Regedit
  2. Navigate to the following registry key :“HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList
  3. Under ProfileList navigate to binary key’s like this: S-1-5-21-3656904587-1668747452-4095529-500
  4. On the right side under ProfileImagePath you’ll see the profile path.
  5. Chose the one with the desired user and delete the long registry key like: “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList”

Permissions that need to be set to allow automate users home directory creations

share1When you configure home directory for user (from “Active directory users and computers” – in Windows 2000/2003/2008/2012 domain or “User manager for domains” – in NT4 domain), you should add root share that will contain the user home directory – \\servername\users$\%username%. To allow automatic creation of this home folder, there need to configure correct NTFS and Share permissions on home folder root share.

Right click the folder > Properties > Sharing > Advanced Sharing. Name the share and add a “$” to the end to make it a hidden share.

Click Permissions on the share.

share2

To allow automate home directory creations, please make sure to apply this security settings on the root folder that should contain the user home directory.

Administrators: Full Control
System: Full Control
Authenticated Users: Full Control

Now click OK > OK to get back to the Folder Properties.

Now we need to configure the NTFS permissions, so we need to be on the “Security” tab of the folder we created earlier.

1. Turn off inheritance on the folder and copy the permissions. You do this by:

a. Click the Advanced button found on the Security tab.
b. Clear Allow inheritable permissions to propagate to this object check box in the Advanced Security Settings dialog box.
c. Click Copy when prompted by the Security dialog box.

2. Click OK to return to the Security tab. Ensure we have the following permissions set:

Administrators: Full Control
System: Full Control
Creator Owner: Full Control
Authenticated Users: Read & Execute, List Folder Contents, Read

3. Change permissions for Authenticated Users so they cannot access other users’ folders. You do this by:

a. Click Advanced on the Security tab.
b. Click Authenticated Users, and then click Edit.
c. On the Permissions Entry for HOME dialog box, drop down the Apply onto and select This folder only.
d. Click OK twice.

Query Active Directory FSMO Roles

  • Run netdom query fsmo
  • Run ntdsutil then roles then connections then connect to server DC-name then quit then select operation target then list roles for connected server
  • Run dcdiag /knowsofroleholders /v

See how Group Policies are applied

Run gpresult /v

GPRESULT, or otherwise known as Resultant Set of Policy Queries is a tool used to provide client end information of Group Policy settings.
The utility ships with all current versions of Windows and is used to aid administrators in troubleshooting group policy problems. The policy is very similar between all versions of Windows, however Windows Vista and Windows 7 requires elevation.

The commands below are examples that i use frequently.

Windows XP

This provides verbose log of current logged on user on local PC

1 gpresult /v > gp.txt