Cannot connect to WMI provider. You do not have permission or the server is unreachable

This error usually happens if you have two SQL Server instances on the same box and someone removed one at some point.

http://support.microsoft.com/kb/956013

To work around this problem, open a command prompt, type the following command, and then press ENTER:

mofcomp "%programfiles(x86)%\Microsoft SQL Server\number\Shared\sqlmgmproviderxpsp2up.mof"

Note For this command to succeed, the Sqlmgmproviderxpsp2up.mof file must be present in the %programfiles(x86)%\Microsoft SQL Server\number\Shared folder.

The value of number depends on the version of SQL Server:nnn

 Collapse this tableExpand this table
Microsoft SQL Server 2012 110
Microsoft SQL Server 2008 R2 100
Microsoft SQL Server 2008 100
Microsoft SQL Server 2005 90

After you run the Mofcomp tool, restart the WMI service for the changes to take effect. The service name is Windows management Instrumentation.

How to determine what version of PowerShell is installed

Use $PSVersionTable.PSVersion to determine the engine version. If the variable does not exist, it is safe to assume the engine is version 1.0.

Note that $Host.Version and (Get-Host).Version are not reliable - they reflect the version of the host only, not the engine. PowerGUI, PowerShellPLUS, etc. are all hosting applications, and they will set the host's version to reflect their product version, which is entirely correct.

Log on as a Batch Job permissions Removed

Note: This issue is also related to -> An exception occurred when trying to issue security token: The HTTP service located at http://localhost:32843/SecurityTokenServiceApplication/securitytoken.svc/actas is too busy

Recently I had a client where their virtual environment failed due to a hardware failure. After they brought everything up and fixed the hardware issue SharePoint was not working. Specifically SharePoint Central Administration, Security Token Service App Pool, the main SharePoint web application and My Site web application would not start.

Based on numerous blog posts and my experience with IIS I started down the typical fixes:

  • Manually start the individual web application
  • Make sure the Identity on the web application was correct and the right credentials were in place
  • Even running the SharePoint Configuration Wizard to fix any issues

After each one of these I would try hitting SharePoint Central Administration and would get a Server Not Available 503 error then go back into IIS and the web application would be stopped.

I then started looking into the ULS and Event Viewer to dig a little deeper.I started to see a pattern of something did not have permissions across these multiple web applications. Finally I searched the webs on a Application Event ID error of 5059 that basically said that “Windows Process Activation Service (WAS) encountered a failure when it started a worker process to serve the application pool.” Luckily this error pointed me to the follow SharePoint Forum post that got me on the right direction.

In essence there was a specific permission needed by SharePoint to allow the Identity for the web application to work. The local security policy of “log on as a batch job” user permission needs to be in place. My theory is when the domain went down a older version of the domain policy was pushed out and removed those permissions.

I ended up going into Group Policy Management console and had to find the policy where this was set. In this case the Domain Default Policy. The Log on as a batch job setting is found in Computer Configuration > Policies > Windows Settings > Security Settings > Local Policies > User Rights Assignment > Log on as a batch job. Add the SP Admin accounts to the list and also add the IIS_IUSRS local Group as ith should contain the accounts for all the SP Application Pools. Afterwards I did a gpupdate /force and restarted the SharePoint server and everything was happy.

Hope this helps somebody else!

Thanks to Don Donais http://talesfromitside.wordpress.com/2011/12/06/log-on-as-a-batch-job-permissions-removed/

ASP.NET MVC5 Identity

Here are FOUR fantastic tutorials on MVC5 Identity i.e. Forms Based Authentication (FBA). It's not like the old version when you had to create an ASPNETDB database! The .NET 4.5 Framework has a lot of built in code so these well written aticles help show this.

ONE:
http://typecastexception.com/post/2013/10/27/Configuring-Db-Connection-and-Code-First-Migration-for-Identity-Accounts-in-ASPNET-MVC-5-and-Visual-Studio-2013.aspx

TWO:
http://typecastexception.com/post/2013/11/11/Extending-Identity-Accounts-and-Implementing-Role-Based-Authentication-in-ASPNET-MVC-5.aspx

THREE:
http://typecastexception.com/post/2014/02/13/ASPNET-MVC-5-Identity-Extending-and-Modifying-Roles.aspx

FOUR:
http://typecastexception.com/post/2014/02/19/ASPNET-MVC-5-Identity-Implementing-Group-Based-Permissions-Management-Part-I.aspx

Excellent work Jon Atten!

I can't use email as Username with MVC5 Microsoft.AspNet.Identity

Problem:

I want to use email (or a dot in the username!) as the username with Microsoft.AspNet.Identity in MVC 5 application. But when I do I get the following error:

User name ... is invalid, can only contain letters or digits.

Solution:

In the AccountController constructor that takes a userManager as a parameter add the following code:

UserManager.UserValidator = new UserValidator<ApplicationUser>(UserManager)
 { AllowOnlyAlphanumericUserNames = false };

Error When renaming ASP.NET MVC 5 applciation

I had this issue a few times already, so I will write down the procedure I follow also as a reminder for myself:

  1. Replace all of the old solution name with the new one.
  2. Navigate to Properties under each project and change the Assembly Name and Default Namespace fields to new solution name.
  3. Go to solution folder and rename all project folders with the new solution name.
  4. Remove all files under bin and obj folders.
  5. Solution will not be able to load projects. Remove all projects and add them again.
  6. Re-build the project.

Source: http://stackoverflow.com/questions/21701297/error-when-renaming-asp-net-mvc-5-applciation

Capture a User’s Domain\UserName

When developing your Excel or Access application, it’s not uncommon to need to capture your user’s domain/username for one reason or another. A user’s domain/username combination is the traditional unique identifier for a user - often captured by programmers to do things in like:

  • Help manage user login and permissions
  • Create a history of who used the application
  • Capture the name of each user who made the changes to data
  • Personalize outputs and program messages for users

.
There are literally half a dozen ways to capture a user’s domain name and user name. In this post, I’ll give you a very easy method using the Environ function.

Environ stands for Environment, and refers to environment variables in an operating system. Environment variables are specially named aliases for specific system properties, exposed as a kind of shortcut for system administrators and programmers.

Although majority of these Environment variables are useless to your average Excel/Access developer. There are a few that can prove to be useful. Two of these are the UserDomain and UserName variables. We can use these to capture a user’s Domain\UserName.

To demonstrate this, I’ve entered the following function into a standard module. You can call this from a form or query!

Function getReturnUName()
       getReturnUName = Environ(“UserDomain”) & “\” & Environ(“Username”)
End Function

  •  

  • Sub EnvironListing()
  •  Dim I As Integer
  •  I = 1
  •   Do Until environ(I) = ""
  •     Debug.Print environ(I)
  •     I = I + 1
  •   Loop
  • End Sub
  • PowerShell Backup from Local folder to FTP location

    Here is a script that I wrote for backing up some very important files to an off-site ftp location. It backs up only files that are new OR have changed in the last 24 hours. That number of days could be a parameter based on when the backup last ran, however this is the base code that you can start using right away. Just add it to a Task Schedule that runs one a day.


    # ==============================================================================================
    #Set the Date/Time
    # ==============================================================================================
    $BackUpdateTime  = (Get-Date).Year.ToString()
    $BackUpdateTime += (Get-Date).Month.ToString()
    $BackUpdateTime += (Get-Date).Day.ToString()
    $BackUpdateTime += (Get-Date).Hour.ToString()
    $BackUpdateTime += (Get-Date).Minute.ToString()
    $BackUpdateTime += (Get-Date).Second.ToString()
    $today = (Get-Date -Format yyyy-MM-dd)

    try {
     $ftp = "ftp://ftp.mysite.ca/"
     $user = "ftpuser"
     $pass = "ftppassword" 
     
     $webclient = New-Object System.Net.WebClient
     $webclient.Credentials = New-Object System.Net.NetworkCredential($user,$pass) 

     #we specify the directory where all files that we want to upload 
     $Dir="Y:\LocalDirectory\"
     $LogFile="I:\PowerShell\MyBackup_"+$today+".txt"
     Clear-Host
     #Write-Host $LogFile
     "From:"+$Dir+" (on server01) To:"+$ftp | Out-File $LogFile -Append
     "Start: "+(Get-Date) | Out-File $LogFile -Append

     $files = @(Get-ChildItem -Path  $Dir -Recurse | ?{ !$_.PSIsContainer } |Where-Object { $_.lastwritetime -gt (get-date).AddDays(-1)} | Select-Object -ExpandProperty FullName )
     foreach($item in $files)
     {
         if($item -ne $null)
      {
       $uri = New-Object System.Uri($ftp+$item.Substring(3))
       $webclient.UploadFile($uri, $item)
       #Write-Host (Get-Date)$item
       "$(Get-Date): "+$item | Out-File $LogFile -Append
      }
     }
     $webclient.Dispose()

     "End:"+(Get-Date) | Out-File $LogFile -Append
     
     $msg = new-object Net.Mail.MailMessage
     
     # Edit the From Address as per your environment. 
     $msg.From = "Backup (server01) <my.email@mysite.ca>"

     # Edit the mail address to which the Notification should be sent. 
     $msg.To.Add("my.email@mysite.ca")

     # Subject for the notification email. The + “$today” part will add the date in the subject. 
     $msg.Subject = "Backup was Successful for " + "$today"

     # Body or the notification email. The + “$today” part will add the date in the subject. 
     $msg.Body = "Backup was Successful for " + $today + "`r`n`r`n" 
     
     $att = new-object Net.Mail.Attachment($LogFile)
     $msg.Attachments.Add($att)
     
     # IP address of your SMTP server.
     $smtpServer = "smtp.mysite.ca" 
     $smtp = new-object Net.Mail.SmtpClient($smtpServer) 

     $smtp.Send($msg)
     $msg.Dispose()
    }
    Catch { 
     $ErrorMessage = $_.Exception.Message 

     # Configure the below parameters as per the above. 
     $msg = new-object Net.Mail.MailMessage
     $msg.From = "Backup (server01) <my.email@mysite.ca>" 
     $msg.To.Add("my.email@mysite.ca") 
     $msg.Subject = "Backup Job failed on " + "$today" 
     $msg.Body = "Job failed on " + "$today and the reason for failure was $ErrorMessage." 
     
     $att = new-object Net.Mail.Attachment($LogFile)
     $msg.Attachments.Add($att)
     
     $smtpServer = "smtp.mysite.ca" 
     $smtp = new-object Net.Mail.SmtpClient($smtpServer) 
     
     $smtp.Send($msg)
     $msg.Dispose()
    }