New Blog Site

December 6, 2011 Leave a comment

I recently setup a new blog site at http://blog.codygros.com/blog. I will be adding new blog posts on that site now.

Thanks,

-CG

Categories: Uncategorized

SQL Saturday 28

August 2, 2010 Leave a comment

SQL Saturday is only two weeks away! I’ll be presenting “SharePoint 2010 Management with PowerShell”.  There are two other PowerShell sessions. One is “A PowerShell Cookbook for DBAs” and the other is “SSIS and PowerShell: A winning combination”.  The event lasts all day and is full of great speakers speaking on awesome topics. If you are in the Baton Rouge area, you should definitely attend SQL Saturday on August 14. For more information check out http://sqlsaturday.com/28/eventhome.aspx and follow SQL Saturday 28 on twitter at #sqlsat28.

Categories: Events, PowerShell

SharePoint 2010, PowerShell what’s the deal?

June 21, 2010 2 comments

If you love PowerShell as much as I do, you should be aware of  how SharePoint 2010 takes full advantage of PowerShell. Over the past few months, I’ve been giving a presentation on managing SharePoint 2010 with PowerShell. It surprised me that the majority of people aren’t taking advantage of PowerShell or they don’t realize the benefits of learning PowerShell. I know there are thousands of blogs posts on the internet giving an introduction to PowerShell, but I’ve decided I would start writing a series of blog posts on using PowerShell to manage SharePoint 2010. Chances are if you are some type of IT administrator and your company decides to implement SharePoint, you will be stuck with managing the environment. So if you are in this position and you are looking around on the internet for resources for SharePoint 2010, chances are every resource you find somehow mentions PowerShell or gives you some type of PowerShell example. My goal for these blog posts is to  help SharePoint administrators learn PowerShell to manage their SharePoint environment. Many administrators will ask why should I take time to learn PowerShell to manage SharePoint. My answer to that is once you learn PowerShell to manage one product, you can take those skills and use PowerShell to manage other Microsoft and non Microsoft Products. We will start off with the basics of PowerShell from a SharePoint perspective and then each post we will dive into using PowerShell to perform every day SharePoint tasks.  In this blog post we will go over some terms that you will need to know when learning PowerShell. First lets login to our SharePoint server and open up the SharePoint Management Shell.

image

Now that we have PowerShell open, type the following command

image

Don’t worry about the exact syntax of the command, we will go into this later. The above command will return all Cmdlets that are available for managing SharePoint 2010. So at this point if you are new to PowerShell, you may be asking what are Cmdlets. Cmdlets are the powerful commands you use to do some specific function within PowerShell.  PowerShell has hundreds of cmdlets included by default for you to use to manage computers and other products. Cmdlets are always in the form of Verb-Noun, for example Get-SPFarm, Set-SPSite, Remove-SPWebApplication, Backup-SPFarm. One thing to note is that the noun portion of cmdlets are always singular. So now that we know what Cmdlets are, lets look at some important Cmdlets that will help you on your journey to becoming more comfortable with PowerShell. The first cmdlet is Get-Command. The Get-Command cmdlet will return all Cmdlets that are loaded in your current PowerShell session. An easy way to start exploring PowerShell, is to type Get-Command and start looking at the different Cmdlets available. Now that you typed Get-Command and you found a cmdlet that you want to know more about, lets figure out how to use that cmdlet. In this example, we are interested in the Get-SPSite cmdlet. To learn how to use this cmdlet, we will use the Get-Help cmdlet.

To use the Get-Help cmdlet, you type Get-Help and then the Cmdlet you want to learn more about.

image

The information provided by Get-Help is very useful . By default the above will return a description, the syntax, and some related cmdlets. So now we know that the Get-SPSite cmldet will return site collections that are currently in your SharePoint farm.  At this point you may still want to know how to use the cmdlet without reading all this additional information. Ok so type this into your shell

image

The above command is using the “examples” parameter to return examples on how to use the Get-SPSite cmdlet.  Believe it or not, the examples provided with most cmdlets are very useful. Not only does it give you an example, it gives you a description of the what the example will do. Another parameter to use with Get-Help is the “Full” parameter.

image

The above command will give us the tons and tons of information on the Get-SPSite cmdlet. It includes the description, examples, and also information on all the parameters included with the cmdlet.  Don’t worry if you don’t understand all the parameters or the concept of parameters now, I will dive deeper into parameters in a future blog post.

So now you know some basics of using PowerShell with Sharepoint, login to your SharePoint server and open the SharePoint Management Shell and use the cmdlets we covered so far to find some cmdlets that interests you. In the next blog post we will learn a couple more important cmdlets and actually start using some of these SharePoint cmdlets. If anyone is actually reading my blog and you have any questions shoot me an email at codygros@gmail.com or leave a comment. Also, if you want to learn how to do something specific with PowerShell or SharePoint let me know.

Retrieve Stale Active Directory Computer Accounts

January 11, 2010 2 comments

I wrote a simple function using the Active Directory cmdlets to retrieve stale computer accounts. The Get-AD* cmdlets have a parameter called “Filter” The filter parameter allows you to specify a query string to narrow down your search results. I’m not going to go into too much detail on the syntax for the filter parameter, but I will show you how I used it in my function. Here is the function i wrote:

function Get-StaleComputer {
param(
[int] $days=120,
[switch] $lastReset
)
$date=$(Get-Date).AddDays(-$days)
IF ($lastReset){
Get-ADComputer -filter {(passwordLastSet -le $date) } -properties 'passwordLastSet' | Select Name, @{Name="DaysSinceLastReset";Expression={$(New-TimeSpan $_.passwordLastSet (Get-Date)).Days}}
}# End IF

ELSE{
Get-ADComputer -filter {(passwordLastSet -le $date) }
} #End IF

}

I used the filter parameter to retrieve computer accounts whose passwords haven’t been reset in at least 120 days. You can call the function and use the days parameter to change the amount of time. For example:

Get-StaleComputer –days 365

This will retrieve all computer accounts that haven’t reset their passwords in at least a year. If you don’t use the days parameter it will use the default value of 120. The parameter “lastReset” is a switch parameter that will return computer objects with a property named “DaysSinceLastReset”. The value of this property will be the number of days since each computer account reset their password.

You can also pipe the results from this command to another cmdlet, for example:

Get-StaleComputer –days 365 | Move-ADObject –TargetPath “OU=DisabledComputers,DC=codygros,DC=com”

The above example will get all computers that haven’t reset their password in at least a year and move the computers to a Disabled OU.

Using PowerShell on Windows Server 2008 R2 Server Core

October 20, 2009 1 comment

 

The past few days at work I’ve been working on a Windows Server 2008 R2 Server Core server. The coolest addition to Windows Server 2008 R2 Server Core is the ability to install PowerShell as a feature. Once I installed PowerShell, I was able to do all the administration on the box without having to use the native commands that are included with Server Core.

Before you install PowerShell you can view the available features on the server by running the following command:

Dism /online /get-features /format:table

Before you install PowerShell you have to install the .NET Framework 2.0 using the following command:

Dism /online /enable-feature /featurename:NetFx2-ServerCore

Now you can install PowerShell using the following command:

Dism /online /enablefeature /featurename:MicrosoftWindowsPowerShell

There are also two modules included with Server Core R2 that you can install. The modules are ServerManager and BestPractices. Use the following commands to install the modules:

Dism /online /enable-feature /featurename:ServerManager-PSH-Cmdlets

Dism /online /enable-feature /featurename:BestPractices-PSH-Cmdlets

 

To start PowerShell use the following command:

c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe

 

Now that PowerShell is installed and running, I renamed the computer using the following command:

$comp=Get-WMIObject –class win32_ComputerSystem

$comp.Rename(“NewName”)

 

I also want PowerShell to start automatically when I start the server. I will use the following command to add a key in the registry for PowerShell to start automatically:

New-ItemProperty –Path “HKLM:\Software\Microsoft\Windows\CurrentVersion\Run” –Name “PowerShell” –Value “C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe”

 

If you need to install any roles or features, you can use the Server Manager module. First you need to load the module using the following command:

Import-Module ServerManager

This module includes the following three cmdlets:

  • Get-WindowsFeature
  • Add-WindowsFeature
  • Remove-WindowsFeature

Get-WindowsFeature provides you with a list of features and roles that are available on the server. If you want to view just the roles or features that are installed you can use the following command:

Get-WindowsFeature | Where {$_.installed –eq $true}

 

Add-WindowsFeature allows you to install a feature or role on the server. For example, to install the Hyper-V role:

Add-WindowsFeature Hyper-V

 

Remove-WindowsFeature allows you to remove any roles or features you currently have installed.

Remove-WindowsFeature Hyper-V

Categories: PowerShell

Using the new Active Directory cmdlets- Part 3: Installing and loading the Active Directory Module.

October 19, 2009 Leave a comment

 

In this blog post I will discuss the Active Directory module that is included with Windows 7 and Windows Server 2008 R2. In the previous blogs, I discussed Active Directory Web Services (ADWS) and Active Directory Management Gateway Service (ADMGS). Remember, if you don’t have at least one domain controller running one of these services you won’t be able to use the Active Directory cmdlets.

Lets talk about the Active Directory module and how to use it in PowerShell. The Active Directory module is only available on Windows 7 and Windows 2008 R2 after you install the Remote Server Administration Tools (RSAT).  When installing RSAT, make sure you drill down into, AD DS and AD LDS Tools, then Active Directory Module for Windows PowerShell.

image

Now that the module is installed, we have to load the module into PowerShell. To load the module start PowerShell and type the following command:

Import-Module ActiveDirectory

 

Once the module is loaded, you can type the following to display the cmdlets loaded with the module:

(Get-Module ActiveDirectory).ExportedCmdlets

Categories: PowerShell

Using the new Active Directory cmdlets- Part 2: Installing Active Directory Management Gateway Service.

October 12, 2009 Leave a comment

In this blog post I will show you how to install Active Directory Management Gateway Service (ADMGS) on a down level domain controller. In Part 1 of this series, I wrote about the new Active Directory Web Services (ADWS) included with Windows Server 2008 R2. This service is installed automatically when you add the AD DS role on a Windows Server 2008 R2 server. I also mentioned that if you don’t have a Windows Server 2008 R2 domain controller you can install ADMGS on a down level server. You can install ADMGS on the following Operating Systems:

  • Windows Server 2003 R2 w/SP2
  • Windows Server 2003 w/SP2
  • Windows Server 2008
  • Windows Server 2008 w/SP2

 

Requirements for installing ADMGS:

 

If you are running Windows Server 2003 R2 w/SP2 or Windows Server 2003 w/SP2 install the following hotfixes:

  • kb96929 (You have to request this hotfix and a link to it will  be emailed to you)
  • kb969166

 

If you are running Windows Server 2008 without SP2 install the following hotfixes:

  • kb969166
  • kb967574 (You have to request this hotfix and a link to it will  be emailed to you)

 

If you are running Windows Server 2008 with SP2 install the following hotfix:

 

When you have  finished installing the requirements for the Operating System you are running, you can download ADMGW here.  On the download page, make sure you pick the correct file that matches your Operating System and processor architecture. Once the file is downloaded, the install of ADMGS is very straightforward. Run the file and accept the defaults. That’s it, you now have a domain controller running ADMGS.

 

In my next blog post,we will finally discuss and start using the new Active Directory cmdlets.

Categories: PowerShell
Follow

Get every new post delivered to your Inbox.