Showing posts with label Powershell. Show all posts
Showing posts with label Powershell. Show all posts

Friday, November 16, 2012

Get Active Directory Group Members with PowerShell

I’ve not blogged for quite a while. Let’s come back with a small PowerShell script for retrieving Active Directory Group Members.

The bellow scripts retrieve all the Active Directory groups in a specific OU and count the number of members.

Import-Module ActiveDirectory

$groups = Get-ADGroup -searchbase "OU=MyOU,DC=myDC,DC=net" -filter *

$myArray = @()

foreach($g in $groups)

{

$members = Get-ADGroupMember($g)

$myObject = New-Object System.Object

$myObject | Add-Member -type NoteProperty -name Name -Value $g.Name

$myObject | Add-Member -type NoteProperty -name Count -Value $members.Length

$myArray += $myObject

}

$myArray


 

Friday, March 9, 2012

PowerGUI Error : Microsoft SharePoint is not supported with version 4.0.30319.1 of the Microsoft .Net Runtime

I’m used to work with PowerGUI script editor for developing Powershell scripts for SharePoint 2010. This time, after updating PowerGUI with version 3.2.0.2237 and running a SharePoint cmdlet, I got this error:

“Microsoft SharePoint is not supported with version 4.0.30319.1 of the Microsoft .Net Runtime."

After investigations, this issue is caused by PowerGUI itself. To fix it, open the ScriptEditor.exe.config file placed in the PowerGUI installation directory. Remove of comment this line:

image

Restart the script editor and everything works again !

Friday, February 10, 2012

How to add SharePoint snapin to Power GUI script editor

1. Open Power GUI script editor

clip_image001

2. Select: Microsoft.SharePoint.PowerShell

clip_image002

3. Now, you can use PowerShell intellisense on SharePoint module !

clip_image003

Wednesday, March 30, 2011

Start/Stop a SharePoint 2010 Service Application

Sometimes, it can be useful and more efficient to handle Sharepoint Service applications using Powershell.
The following script can be used for starting or stopping a service application instance.

A Sharepoint Service application is running behind a service application instance. This instance represents the service application on the whole Sharepoint Farm.
Stopping the instance will stop the related service application on all the servers in the farm.

First of all, we need to get all the service instances running on the farm:
Get-SPServiceInstance

From the list, select your service instance GUID and copy it.
For stopping the service instance, you just need now to run the Stop-SPServiceInstance command:
Stop-SPServiceInstance -Identity "YourServiceGUID"

Type "Y" when prompted.

Start-SPServiceInstance can be used using the same manner for starting the service again.

Attach Visual Studio to an application using Powershell

This script can be used to run the Visual Studio just in time debugger for debugging your website. It gets the name of the application pool running the website and then attach the JIT to the w3wp process.

$filter = "*MyWebsite*"

$w3wp = get-WmiObject Win32_Process -Filter "Name='w3wp.exe'"
$prid = $w3wp | where { $_.CommandLine -like $filter }

c:\Windows\System32\vsjitdebugger.exe -p $prid.ProcessId

Monday, December 20, 2010

Windows PowerShell Tips



Accessing Values in an Array
Byte Conversion
Calculating Text File Statistics
Creating Custom Tables
Displaying Version Properties of a Group Policy Object
Even More Things You Can Do With Arrays
Formatting Dates and Times
Formatting Numbers
Fun Things You Can Do With the Get-ChildItem Cmdlet
Image Mapping API 2.0 Downloads
Modifying Message Colors
Modifying a Read-Write Property Using Get-WMIObject
Reading Text Files
Referencing Variables and Variable Values
Removing Items From Arrays
The String’s the Thing
Three Things You Might Not Know About Windows PowerShell Functions
Using Windows PowerShell “Here-Strings”
Using the Range Operator in Wildcard Queries
What Is (and What Isn’t) in Our Array?
Windows PowerShell Tip: Adding a Simple Menu to a Windows PowerShell Script
Windows PowerShell Tip: Automatic Script Writing Using Get-History
Windows PowerShell Tip: Creating Formatted HTML Output
Windows PowerShell Tip: Creating a Custom Input Box
Windows PowerShell Tip: Creating a Graphical Date Picker
Windows PowerShell Tip: Creating and Modifying Environment Variables
Windows PowerShell Tip: Determining the Size of a Folder
Windows PowerShell Tip: Displaying a Message in the Notification Area
Windows PowerShell Tip: Filtering Collections With Regular Expressions
Windows PowerShell Tip: Finding All the Empty Folders in a Directory Tree
Windows PowerShell Tip: Formatting Numbers and Dates Using the CultureInfo Object
Windows PowerShell Tip: Getting Information About the Logged-On User
Windows PowerShell Tip: Getting Rid of a COM Object (Once and For All)
Windows PowerShell Tip: Listing the TrueType Fonts Installed On Your Computer
Windows PowerShell Tip: Making Progress
Windows PowerShell Tip: More Fun with Dates (and Times)
Windows PowerShell Tip: Multi-Select List Boxes – And More!
Windows PowerShell Tip: Press Any Key to Continue
Windows PowerShell Tip: Running Windows PowerShell Scripts Against Multiple Computers
Windows PowerShell Tip: Running Windows PowerShell Scripts Against Multiple Computers: Part 2
Windows PowerShell Tip: Selecting Items From a List Box
Windows PowerShell Tip: Taking Things (Like File Paths) Literally
Windows PowerShell Tip: Three Things You Might Not Know About Windows PowerShell Functions
Windows PowerShell Tip: Using Calculated Properties
Windows PowerShell Tip: Using Test-Path to Verify the Existence of an Object
Windows PowerShell Tip: Using the Switch Statement
Windows PowerShell Tip: Working With Custom Objects
Windows PowerShell Tip: Working With SIDs
Windows PowerShell Tip: Working With Security Descriptors
Working with Hash Tables
From: http://technet.microsoft.com/en-us/library/ee692948.aspx

Saturday, December 11, 2010

Remove duplicates using Powershell

This is a quick powershell script for removing duplicates files from a folder.
I used it for removing duplicates from my music library.

It is simply listing all the duplicates files from a directory and copy them to a back up folder.
$musicFolder = "c:\MyFolder"
$backupFolder = "c:\Backup"

echo "Get duplicates"
$dupmusics = ls $musicFolder -recurse | Group-Object Length, LastWriteTime | Where { $_.Count -gt 1 }

if($dupmusics.Length -gt 0)
{
echo "Move duplicates"
$dupmusics = $dupmusics | ForEach-Object { $_.Group[1..$_.Group.Count] } | Move-Item -Destination $backupFolder -Verbose
}
else
{
echo "no duplicates found"
}