Chris and Daves SharePoint and Tech Blog

All about SharePoint and Technology
  • rss
  • Home
  • About Dave
  • About Chris
  • Links and Resources

Use Powershell to delete Outlook offline address book remotely.

Chris McKinley | September 2, 2010

Over the summer we moved mail to Exchange 2010 sp1 and being a school we also have new members of staff joining.
The result is that a few people are having trouble finding certain people in their outlook address book when they get back after their summer break.
I’ve done a quick powershell script to remove the offline address book files remotely. Make sure the user has closed outlook*, fire up Powershell ISE as administrator and then run this:

$comp = read-host “Computer Name”

$user = read-host “Login Name”

cd \\$comp\c$\Users\$user\AppData

dir -Recurse -Filter *.oab | remove-item


It will prompt for a computer name and a login name of the user you want to remove the files for. Obviously you will need appropriate network permissions.
When the reopen outlook they will have no problems finding all the new staff members they need to send to!

*If you want to go power(shell) crazy you could script the closing of the outlook process.

Comments
No Comments »
Categories
Exchange 2010, Office 2010, Outlook, Powershell
Tags
Exchange 2010, Office 2010, Powershell, Twynham
Comments rss Comments rss
Trackback Trackback

Getting HyperV Statistics Using PowerShell

Darren White | August 19, 2010

Guest Post By Darren White

  Today myself and Dave where working on a customer site when the question of HyperV statistics came up, it would be good to be able to see what free memory was available on the host machine and also what memory was being used by the guest OS’s, now as has been pointed out in previous posts Dave is no expert with PowerShell but very much a newbie, whereas I am a past master (I do my best). So after searching codeplex I found the PowerShell Management Library for Hyper-V.

  After downloading and extracting please remember to unblock the zip file as illustrated below or you may encounter errors when trying to install and run the commands.

Once installed the obvious first step was to see the output of the commands, this proved to be very extensive and perfect for the job. The command we were most interested in was Get-VMSummary as illustrated below.  

As you can see the output is in list format for each item and this makes it hard to get an overview of data so the next step was to pipe it into Format-Table; Get-VMSummary | Format-Table. As illustrated below the formatted table makes it easier to read.

As you can see there is a lot of information presented that we do not need, so by using the format-table command we can specify the columns we wish to output to the screen. The main information we needed was:-

Hostname (Host), Virtual Machine Name (VMElementName), Installed Operating System (GuestOS), Number of Allocated CPU’s (CPUCount), Allocated Memory (MemoryUsage), Current State i.e. Running/Stopped (EnabledState)

Get-VMSummary | Format-Table Host, VMElementName, GuestOS, CPUCount, MemoryUsage, EnabledState

The next step was to output the information to a CSV file; this was achieved by replacing Format-Table with Select-Object and then piping this into the Export-Csv command. We also used the Sort-Object command to order the output by virtual machine name.

Get-VMSummary | Sort-Object VMElementName | Select-Object Host, VMElementName, GuestOS, CPUCount, MemoryUsage, EnabledState | Export-Csv VMInfo.csv -NoTypeInformation

The next step was to get the information from all the HyperV servers in the current domain this was achieved by using the Get-VMHost command as can be seen in the illustration below.

To continue writing our PowerShell script we included the parameter –server for the Get-VMSummary command. We passed this parameter from the Get-VMHost inside a foreach loop.

Get-VMHost | Sort-Object | foreach {
Get-VMSummary -server $_ | Sort-Object Name | Select-Object Host, VMElementName, GuestOS, CPUCount, MemoryUsage, EnabledState | Export-Csv “$_ VMInfo.csv” –NoTypeInformation
}

This will create a new CSV file for each hyperV server with the virtual machine information we have asked for.

The next step we needed to achieve was to merge the individual CSV files into one master CSV file containing the desired information on all the virtual machines in your domain. To do this we need to store to output in an array for each HyperV server instead of outputting to the CSV file. Once the array is populated we output this to the master CSV file.

$content = @();
Get-VMHost | Sort-Object | foreach {
$content += Get-VMSummary -server $_ | Sort-Object Name | Select-Object Host, VMElementName, GuestOS, CPUCount, MemoryUsage, EnabledState
}
$content | Export-Csv VMInfo.csv –NoTypeInformation

This script we saved as a PS1 file and then ran from within PowerShell, the CSV output you can see below.

This gives a great overview of all the virtual machines you have running on your HyperV server and will be a great aid when it comes to balancing the load across your HyperV servers.

A trick we used to balance the server load was, once we opened our CSV file in Excel you can use the function sumif to create the following formula, =SUMIF($A:$A,H1,$E:$E).

In our CSV column A we have the HyperV Hostname and Column E is the Virtual Machine Memory allocation. Cell H1 is next to the formula containing a HyperV hostname. We then copied this formula to the cells below for each HyperV (i.e. H2 will contain the hostname for the second HyperV and so on)

This will show the amount of Ram used on each HyperV server by the virtual machines and we hope it helps with balancing your HyperV implementation. As you can see from the illustration above our HyperV server will need balancing but that is the point of the post so we can now live migrate our virtual Servers and rerun the script until we are happy with the spread on across all of our HyperV host servers.

I hope you enjoyed this post and any questions please submit via comments on the blog or by going to http://twitter.com/whitefern and asking me there.

Darren

Comments
1 Comment »
Categories
HyperV, Powershell, Server 2008 R2
Tags
HyperV, Powershell, Server 2008 R2
Comments rss Comments rss
Trackback Trackback

PowerShell ISE in Server 2008 R2 With SharePoint Modules

Chris McKinley | February 16, 2010

Some of you may have noticed that the ISE environment is not there as a default for Server 2008 R2. This post will go through adding it and also loading the SharePoint modules to enable you to script all your sharepoint bit’s and pieces in a nice environment.

The ISE is just a windows feature. So  click server manager:

Features, Add features:

Tick The Windows Powershell ISE Feature, Click next then install.

It will say that the server may require a restart. The server does not require a restart to add the ISE.

That’s it! It’ll now be on your start menu. If you want to do it all via script then I found this blog from Shay Levy

One thing I found with the ISE was that the Modules and Snapins for SharePoint are not loaded. This means that you can’t run the good old New-SPWeb command! If anyone finds a better way of doing this please let me know but this is how I work so far:

Load PS with modules (As Admin):

Then in the console type “ise” (no quotes) and the ISE will load up – the magic of an Alias!

Run this command from the ISE:

Add-PSSnapin Microsoft.SharePoint.Powershell

And you are good to go with all the SharePoint cmdlets.

Like I said, please let me know if you know a better way of loading the Powershell ISE with all the modules and snapins ready to go!

Comments
2 Comments »
Categories
Powershell, Server 2008 R2, Sharepoint 2010
Tags
Powershell, Server 2008 R2, SharePoint2010
Comments rss Comments rss
Trackback Trackback

SharePoint 2010 Powershell Commands Help

Dave Coleman | February 14, 2010

 Yesterday i did a post The first steps to SharePoint 2010 Powershell heaven after which Chris McKinley who is a clever coder added a foot note to the post, so i thought today i would give it a try to see what the output was like and fantastic it all worked and turned out to be a great resource for me so i thought i would share with you the script.

1. Create a folder on your SharePoint 2010 server (I called mine c:\SharePointHelp)

2. Open SharePoint 2010 Management Shell as an Administrator

3. Navigate to the folder you created from within PowerShell

4. Run- foreach($i in Get-Command -module Microsoft.SharePoint.PowerShell) { if($i.CommandType -eq “Cmdlet”){ Get-help $i.Name -full | out-file $i”.txt”}}

 You end up with 549 text files each giving you a breakdown and syntax of all Cmdlets available in SharePoint 2010 powershell.

Thanks Chris and i think i may be changing to loving PowerShell. Dave

Comments
No Comments »
Categories
Powershell, Sharepoint 2010
Tags
Powershell, SharePoint2010
Comments rss Comments rss
Trackback Trackback

The first steps to SharePoint 2010 PowerShell Heaven

Dave Coleman | February 13, 2010

As Chris showed in his post last week Create SharePoint 2010 Sites Using PowerShell PowerShell in SharePoint 2010 is going to be a very useful tool to master over  500 commands as compared to less than 200 with STSADM so I thought I would share with you beginners in the whole PowerShell world a very good starting point on your journey to SharePoint 2010 PowerShell heaven. This simple command will output to a text file a list of all the cmdlets (Command-Lets) available to use with SharePoint 2010. First of all I created a folder on the C drive called PSCmd next start “SharePoint Management Shell” as an Administrator and run the command -

Get-Command  –PSSnapin “Microsoft.SharePoint.PowerShell” | format-table name > C:\PSCmd\SP2010PowershellCommands.txt

OutPut SharePoint 2010 PS Commands

This will output a list of all the available cmdlets to your text file giving you the opportunity to look through them at your leisure.

Output TXT

You can also find a great video on using PowerShell with SharePoint 2010 by Todd Klindt SharePoint MVP here Technet

Dave

Hi Dave, just a quick addition from me.

If you create a new blank folder on the sharepoint server called ‘SharePointHelp’ and then navigate to that with powershell and run this command:

foreach($i in Get-Command -module Microsoft.SharePoint.PowerShell) { if($i.CommandType -eq "Cmdlet"){ Get-help $i.Name -full | out-file $i".txt"}}

You will get a text file for each command containing the full help documentation of each Cmdlet!

Chris.

Comments
5 Comments »
Categories
Powershell, Sharepoint 2010
Tags
Powershell, SharePoint2010
Comments rss Comments rss
Trackback Trackback

Create SharePoint 2010 sites using PowerShell reading an XML file

Chris McKinley | February 12, 2010

Just a quick post to show how easy it is to create some sites in SharePoint 2010 using PowerShell by reading an XML file. I’m sure there are some powershell experts out there that can improve the code, but if you need to create a revision gateway during lunch this is the place to start.

Lets start by opening PowerShell with modules on the sharepoint server.

Create a sample xml file:

"<Setup>
 <Sites>
 <TopSiteName>Site1</TopSiteName>
 </Sites>
 <Sites>
 <TopSiteName>Site2</TopSiteName>
 <SubSiteName>Subsite2a</SubSiteName>
 <SubSiteName>Subsite2b</SubSiteName>
 </Sites>
 <Sites>
 <TopSiteName>Site3</TopSiteName>
 <SubSiteName>Subsite3a</SubSiteName>
 <SubSiteName>Subsite3b</SubSiteName>
 <SubSiteName>Subsite3c</SubSiteName>
 </Sites>
</Setup>" | out-file sample.xml

Now we have some data to work with we can create the sites. Three top sites will be created with 2 and 3 subsites below Site2 and Site3. They can be created using:

[xml]$s = get-content sample.xml
foreach ($e in $s.Setup.Sites){
$v = $e.TopSiteName
$b = $e.SubSiteName
new-SPWeb http://sp2010rc/$v -template "STS#0" -addtotopnav -useparenttopnav -name $v
if($b.Length -gt 0) {
foreach ($b in $b){
new-SPWeb http://sp2010rc/$v/$b -template "STS#0" -name $b -AddToQuickLaunch -useparenttopnav
}
}
}

The bit that creates the site is the new-SPWeb command. For information about the command switches run:

get-help new-SPWeb -full

It’s as easy as that! You will now have some SharePoint 2010 sites created in a matter of seconds.

To remove sites you can just use the remove-SPWeb command. This can be scripted in the same way:

[xml]$s = get-content sample.xml
foreach ($e in $s.Setup.Sites){
$v = $e.TopSiteName
$b = $e.SubTopSiteName
if($b.Length -gt 0) {
foreach ($b in $b){
remove-SPWeb http://sp2010rc/$v/$b
}
}
remove-SPWeb http://sp2010rc/$v

}

The xml file can then be deleted with “Remove-Item sample.xml”

If you really wan’t to get stuck in run “Get-Command -module Microsoft.SharePoint.PowerShell” This will output all the cmdlets that you can use with PowerShell to do great things with SharePoint 2010 combine this with get-help and there is no limit to where you can go!!

So there we have it; One XML file with a site structure creating all the SharePoint 2010 sites in just a few seconds!

Happy site creating. Comments and experiences welcome.

Comments
7 Comments »
Categories
Powershell, SharePoint, Sharepoint 2010
Tags
Powershell, SharePoint2010, XML
Comments rss Comments rss
Trackback Trackback

Teaching an old dog new tricks. Using PowerShell to make life better.

Chris McKinley | February 8, 2010

PowerShell has been around for a while now and I use it quite a lot. I’m a programmer so I like to be able to run scripts with loops etc so I get excited that using PowerShell I can display my 8 times tables with this code:

foreach ($num in 1..12 ) { $num * 8}

I also like using the keyboard so am quite happy diving into PowerShell rather than using a GUI. Dave on the other hand is not at all bothered that he can easily solve maths problems, he also often jokes that “it’s called Windows – not typees”. This results in much banter in the office with me often saying that “you could do that in PowerShell” and Dave ignoring me.

I finally thought something had to be done when Dave was installing SharePoint 2010 and FAST search. He had to restart the FAST services. This resulted in a lot of clicking, waiting and more clicking. Time for me to step in with the ever helpful comment of ‘you could do that in Powershell!’.

Dave is not afraid of code views and is often seen firing up a cmd prompt to ping a server or perform an iisreset so I needed to demonstrate how powershell could make his life better and not be something to avoid. I started with ISE.

The Integrated Scripting Environment (ISE) is, in my opinion, is the way powershell should be used. It’s all part of the default PowerShell stuff you get on a normal install of Windows 7 or the like.

With this you get a Notepad style area to write you code (well formatted and colour coded). This also has multiple tabs so you can work on several things at once. There is no point me trying to explain how much easier this is to use than just the powershell window, you need to try it out and see.

The other thing I pointed out to Dave was how easy it was to restart services on a server. So for all thoes SharePoint 2010 FAST services;

Restart-Service -displayname FAST* -whatif

Just like that. The -whatif switch just outputs what will be done, remove the switch and the command will run. So I can run  this code without fear of my browser closing!

From the ISE the commands can be saved, ready for use next time.

Go on, give PowerShell a chance, you’d be barking mad not too.

Comments
1 Comment »
Categories
FAST Search, Powershell, Sharepoint 2010, Windows 7
Tags
FAST, Powershell
Comments rss Comments rss
Trackback Trackback

SharePoint Products



Sponsor

ShareNews, ShareEvents, ShareIdeas, ShareCV or ShareCoffee

Tags

  • Active Directory Analytics BCS BETT BETT 2010 branding Case Study Central Admin Cognitive Community CSS DHCP DocIcon Drop Folder Evolution Exchange 2007 Exchange 2010 Exchange Service Pack 1 Expression blend FAST Forefront Gmail GodMode Google HyperV IC Technology IE9 iFilter Knowledge base Learning Gateway Conference LGCUK10 Licencing master page MDT Media Streaming Microsoft Migration Mind Manager Monitoring Tools Office 2010 Outlook 2010 Patch Levels pdf PowerPoint PowerPoint 2010 Powershell RDP Revision RTM SCVMM Server 2008 R2 SharePoint Sharepoint 2010 SharePoint Conference Sharepoint Designer SharePoint EDU SharePoint Foundation 2010 SharePoint Saturday SharePoint2010 SharePoint2010; Social SketchFlow SPD SPEDU SPS SPSUK SQL SQL 2008 STSADM SUGUK Supplier TechDays Themes Topologies Twynham Versions VHD Volcano WebApps WebParts Windows 7 Windows Live Windows Update Word 2010 WordPress WSUS XML XML-RPC XSLT Zevenseas
Powered by Postrank

Blogroll

  • Alan Richards
  • Alex Pearce's SharePoint Blog
  • Brandon & George
  • End User SharePoint
  • Get The Point
  • Meet Dux
  • Planet SharePoint
  • SharePoint Comic
  • SharePoint Dev Wiki
  • SharePoint In Education
  • SharePoint Joel
  • The SharePoint Mechanic
  • Top SharePoint Sites
  • We Know Nothing


rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox