Monday, September 22, 2014

Live Migrating multiple VMs [HyperV 2008]

This powershell script will let you live migrate multiple virtual machines serially.
The script will ask you to select which machines do you want to migrate and to which destination node as in the below screenshots

To run the script on Windows 2008 R2, you need to install powershell 3.0





 
 
 


Import-Module FailoverClusters

$clustername = Get-Cluster


$vms = Get-ClusterGroup  -Cluster $clustername  | Out-GridView -PassThru -Title "Select VMs to live migrate"
$destination = Get-ClusterNode | Out-GridView -Title "Select destination HyperV host" -PassThru
$count = 0

foreach ($vm in $vms){
 $count += 1
 $total = $vms.count
 write-output "[$count/$total] migrating $vm to $destination..."
 Move-ClusterVirtualMachineRole -Name $vm -Node $destination
}

write-output "All Done"

Wednesday, June 25, 2014

Windows out of the box cmd send mail one liner with variables in subject/body

powershell -Command "Send-MailMessage -To to@recepient.com -Cc cc@recepient.com -From from@sender.com -SmtpServer 127.0.0.1 -Subject $('Mail from computer: ' + (hostname)) -Body $((date).ToString() + ' Mail from computer: ' + (hostname))

Tuesday, June 24, 2014

[Microsoft][ODBC SQL Server Driver][SQL Server]Cannot find the user 'AdtServer', because it does not exist or you do not have permission

I was installing SCOM ACS 2012 R2 and configuring it to use SQL authentication. This is not to collect events from an untrusted domain, I was just implementing redundant ACS collectors as described here which would require the collectors to use SQL authentication to connect to the backend database.

ACS setup completed successfully on all ACS collector servers, but the Audit Collection Services shuts down shortly after starting and logs this event

Error occured on database connection:

Status: 0x04080000

ODBC Error: 15151

ODBC State: 42000

Message: [Microsoft][ODBC SQL Server Driver][SQL Server]Cannot find the user 'AdtServer', because it does not exist or you do not have permission.

Database: SqlWriter

Connection: Maintenance

Statement:

/**********************************************************

The reason this happened was because I precreated the SQL account and gave it dbcreator role then supplied it to the ACS setup. I then discovered that the ACS installer would actually create the account itself, surprisingly it did not complain that the account already existed and completed successfully but apparently something was still broken.

I uninstalled ACS, deleted the SQL account then reinstalled ACS and now it works.

 

Sunday, September 22, 2013

The SQL Server (MSSQLSERVER) service terminated with service-specific error %%17058.

While trying to failover the SQL server to another node, it refused to start and this error was getting logged in the Event Viewer

The SQL Server (MSSQLSERVER) service terminated with service-specific error %%17058.
The problem turned out to be with ERRORLOG being set to read only.

After I cleared the read only attribute from MSSQL\LOG\ERRORLOG the service started successfully.

Tuesday, April 2, 2013

Top SQL Queries

select
highest_cpu_queries.plan_handle,
highest_cpu_queries.total_worker_time,
highest_cpu_queries.total_logical_reads,
highest_cpu_queries.total_logical_writes,
highest_cpu_queries.execution_count,
q.dbid,
q.objectid,
q.number,
q.encrypted,
q.[text]
from
(select top 20
qs.plan_handle,
qs.total_worker_time,
qs.total_logical_reads,
qs.total_logical_writes,
qs.execution_count
from
sys.dm_exec_query_stats qs
order by qs.total_worker_time desc) as highest_cpu_queries
cross apply sys.dm_exec_sql_text(plan_handle) as q
order by highest_cpu_queries.total_worker_time desc
--order by highest_cpu_queries.total_logical_reads desc
--order by highest_cpu_queries.total_logical_writes desc
--order by highest_cpu_queries.execution_count desc

--select top 10 * from sys.dm_exec_query_stats qs

Thursday, March 28, 2013

Converting IIS logs time from UTC to local time

If you notice that the time logged in IIS logs does not match your server's local time, this is because IIS logs time in UTC (GMT) to conform with the W3C log format so if you are in a different time zone for example UTC -3 you will find the time 3 hours ahead in the logs.

To change that, you can choose a different log format from the IIS manager or you can convert the log file using Log Parser.

Download and install Log Parser then run the following command

LogParser.exe "SELECT DATE,TO_LOCALTIME(time) AS time,s-ip,cs-method,cs-uri-stem,cs-uri-query,s-port,cs-username,c-ip,cs(User-Agent),sc-status,sc-substatus,sc-win32-status,time-taken INTO c:\ayman\output.log FROM c:\ayman\input.log" -i:IISW3C -o:W3C

 

Wednesday, March 27, 2013

Check for TempDB PAGELATCH waits

SELECT

session_id,

wait_type,

wait_duration_ms,

blocking_session_id,

resource_description,

ResourceType = CASE

WHEN PageID = 1 OR PageID % 8088 = 0 THEN 'Is PFS Page'

WHEN PageID = 2 OR PageID % 511232 = 0 THEN 'Is GAM Page'

WHEN PageID = 3 OR (PageID - 1) % 511232 = 0 THEN 'Is SGAM Page'

ELSE 'Is Not PFS, GAM, or SGAM page'

END

FROM ( SELECT

session_id,

wait_type,

wait_duration_ms,

blocking_session_id,

resource_description,

CAST(RIGHT(resource_description, LEN(resource_description)

- CHARINDEX(':', resource_description, 3)) AS INT) AS PageID

FROM sys.dm_os_waiting_tasks

WHERE wait_type LIKE 'PAGE%LATCH_%'

AND resource_description LIKE '2:%') AS tab;

Tuesday, March 26, 2013

This Web Part requires at least Microsoft Internet Explorer 7.0

After installing internet explorer 10, PWA broke with this error message

This Web Part requires at least Microsoft Internet Explorer 7.0. For more information, contact your Project Server Administrator.


Adding the website to the compatibility view list solves the problem. Tools -> Compatibility view settings

 

Thursday, January 10, 2013

Configuring OpenVas on BackTrack 5 R3

BackTrack is a pentest linux distribution, download live cd from here, it contains the open source security scanner OpenVAS.
Below are the configuration steps required after booting BackTrack 5 R3 to get OpenVAS running.

ERROR: The number of NVTs in the OpenVAS Manager database is too low

I was setting up OpenVas on BackTrack 5 R3 and got stuck at his error.

ERROR: The number of NVTs in the OpenVAS Manager database is too low

Sunday, January 6, 2013

SCOM ACS User Logon Report

This is a report I created for the Audit Collection Services of System Center Operations Manager that lists all successful user logons details in all servers.

Wednesday, January 2, 2013

SharePoint Project Sites appear in the navigation menu

After I edited the navigation menu in Microsoft Project Server 2010, I found new links to all the project sites.

To solve the problem I had to delete them manually from the Quick Launch page.
Since the SharePoint Publishing feature is enabled, Quick Launch link will be replaced by Navigation, access it from the url /_layouts/quiklnch.aspx

Configure HTTPS on IIS 7 and SharePoint 2010

This post is about configuring https on SharePoint 2010 web application running on multiple load balanced IIS 7 web servers.
Assuming you already have a digital certificate, follow the coming steps. If you do not have a certificate, you can either purchase or create a self signed certificate but in that case you will receive a warning in the browser when opening the website.

Monday, December 17, 2012

suspect db in SQL 2008 R2

The Central Administration website of SharePoint 2010 suddenly stopped working giving a 404 HTTP error.

The following error was showing in the ULS logs

Wednesday, December 12, 2012

This website has been configured to disallow editing with SharePoint Designer (Project Server 2010)

When trying to edit a web part in the Business Intelligence site with SharePoint Designer, I got this error



This web site has been configured to disallow editing with SharePoint Designer.

To allow editing open this file on the SharePoint server C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\SiteTemplates\PWA\XML\ONET.XML and remove this part DisableWebDesignFeatures="wdfopensite" from the line <Project Title="Project Web App" Revision="2" ListDir="$Resources:core,lists_Folder;" SiteLogoUrl="/_layouts/inc/pwa/images/SiteIcon.png" xmlns:ows="Microsoft SharePoint" DisableWebDesignFeatures="wdfopensite" UIVersion="4">

Restart IIS and repeat for all other, if any, SharePoint Servers.

Tuesday, October 9, 2012

Adding SCOM 2012 Product Key

After I installed SCOM 2012 it was showing as Evaluation version. In order to add the product key you need to run a powershell cmdlet as described in the kb article http://support.microsoft.com/kb/2699998

To check the current license, open an Operations Manager Shell and run

Get-SCOMManagementGroup | ft skuforlicense, version, timeofexpiration –a

To register your product run

Set-SCOMLicense -ProductId "Product-Key-Here"



The license got updated after I restarted the server



SCOM 2012 single server deployment

This is a simple deployment of SCOM 2012 installing all roles on a single Windows 2008 R2 server. Microsoft reommends this type of deployment for evaluation and testing purposes.

First install dotnet framekwork 3.5, 4.0 and the Microsoft Report Viewer 2010 Redistributable Package. Then Install and configure IIS web role and SQL server

I have created an active directory group ScomAdmins with local admin rights to the SCOM servers and SQL sysadmin role. I also created the following service accounts.

User
Description
ScomAction
Management server action account – used to gather information and run responses on managed servers
SCOMSDK
System Center Configuration Service and System Center Data Access Service Account – used to update the Operations Manager Database. This account needs local admin rights to the SCOM server
SCOMRead
Used by the Reporting Services to run queries against the reporting data warehouse
SCOMWrite
Reads from the operational database and updates the reporting data warehouse


I log in with a member of the ScomAdmins group: ScomAdmin and launch SCOM 2012 setup



The setup will check next for prerequisistes, installing any missing ones and proceed

Type in the name of the Management Group and proceed. Previously in SCOM 2007 you could have only 1 root management server, SCOM 2012 allows the management server role to be assigned to multiple servers making it easier to acheive high availability.




Type in the name of the SQL server and wait for setup to verify, in my case it is the same server.

Setup will probe next for available Reporting Services installations. If there is a problem hover over the red X for details. Resolve any issues and proceed, in my case the SQL Server Agent service was not running so I started and set it to automatic from the SQL Server Configuration Manager.
Next, choose the web site and authentication mode for the web console
Fill in the service accounts created earlier in the active directory and proceed










SCOM 2012 is now installed. You should then import the management packs you need and discover the devices to manage.

Wednesday, October 3, 2012

Autochk cannot run due to an error caused by a recently installed software package. Windows 2008 R2

Windows 2008 R2 is reporting NTFS file system corruption that requires a chkdsk.
I schedule a disk check and reboot, but it fails with this error

Cannot open volume for direct access.
Autochk cannot run due to an error caused by a recently installed software package.
Use system restore feature from the control panel to restore the system to a point prior to the recent software package installation.
An unspecified error occurred (766f6C756d652e63 3f1).



I suspect the antivirus software was denying disk access, but I did not want to uninstall anything.
The safest thing to do with minimal changes seemed to run chkdsk from the Windows 2008 R2 DVD, so I boot from it, start a command prompt and run

chkdsk /f d:





chkdsk runs for a while and repairs some stuff. I reboot back into windows, the drive is OK and the file system errors are gone.

Thursday, September 27, 2012

Emptying the Recycle Bin for a specific user

Suppose you want to empty the recycle bin of a different user but you do not know his password and do not want to reset it or just do not want to login with his account for any reason.

First get the SID of this account, use PsGetSid from PsTools
Then put the SID in the script below and run it. (will not delete until you uncomment the delete lines)


Const strRecycle = "\\$Recycle.Bin\\" 'Windows 2008, for Win7 use: \\Recycler\\
Set objSWbemServices = GetObject _
    ("WinMgmts:Root\Cimv2")

Dim SIDs : SIDs = Array("S-1-5-21-4040636791-1997804162-1132720628-1008",_
   "S-1-5-21-4040636791-1997804162-1132720628-1014",_
   "S-1-5-21-4040636791-1997804162-1132720628-1018")


For Each sid In SIDs

    Set colDisks = objSWbemServices.ExecQuery _
        ("Select * From Win32_LogicalDisk " &  "Where DriveType = 3")

    For Each objDisk In colDisks
        Set colDeletedFiles = objSWbemServices.ExecQuery _
        ("Select * From Cim_DataFile Where Drive = '" _
        & objDisk.DeviceId _
        & "' And Path = '" & strRecycle & sid & "
\\' " _
        & "And Hidden = False")

        For Each objDeletedFile In colDeletedFiles
            WScript.Echo objDeletedFile.Name
            'objDeletedFile.Delete
        Next
       
        Set colDeletedFolders = objSWbemServices.ExecQuery _
        ("Select * From Win32_Directory Where Drive = '" _
        & objDisk.DeviceId _
        & "' And Path = '" & strRecycle & sid & "
\\' " _
        & "And Hidden = False")

        For Each objDeletedFolder In colDeletedFolders
            WScript.Echo objDeletedFolder.Name
            'objDeletedFolder.Delete
        Next

    Next
Next