Wednesday, December 24, 2008

What Can I Do With Windows PowerShell?

What Can I Do With Windows PowerShell?
Windows PowerShell Tips
Scripting with Windows PowerShell
MSDN Virtual Lab: Creating Windows PowerShell V2 Script Cmdlets -now advanced functions
TechNet Virtual Lab: Introduction to Windows PowerShell

ad groups -duplicate ad group structure in testdom

ADSearch Group Property Attributes:

How to enumerate active directory groups using .Net Directory Services

 Scripts to manage Active Directory Groups

 

get groups that are members of other groups



Set objGroup = GetObject _
("LDAP://CN=Finance Department,OU=Finance,DC=fabrikam,DC=com")

For Each strUser in objGroup.Member
Set objMember = GetObject("LDAP://" & strUser)
If objMember.Class <> "group" Then
objGroup.Remove(objMember.ADsPath)
End If
Next

Set objGroup = GetObject _
("LDAP://cn=Finance Managers, ou=Finance, dc=fabrikam, dc=com")

For Each strUser on objGroup.Member
Set objMember = GetObject("LDAP://" & strUser)
Wscript.Echo objMember.CN & ", " & objMember.Class
Next


Set objGroup = GetObject _
("LDAP://cn=Finance Managers, ou=Finance, dc=Fabrikam, dc=com")
Select Case objGroup.GroupType
Case 2
Wscript.Echo "This is a global distribution group."
Case 4
Wscript.Echo "This is a domain local distribution group."
Case 8
Wscript.Echo "This is a universal distribution group."
Case -2147483646
Wscript.Echo "This is a global security group."
Case -2147483644
Wscript.Echo "This is a domain local security group."
Case -2147483640
Wscript.Echo "This is a universal security group."
End Select







ctp3

get it here

Download WinRM 2.0 CTP3 (required for PowerShell remoting)

?s
Discussions in microsoft.public.windows.powershell

changes
Changes of particular interest

PowerShell 2.0 CTP3 has arrived!

Monday, December 22, 2008

Effective PowerShell from http://keithhill.spaces.live.com/

Effective PowerShell Item 1: The Four Cmdlets That are the Keys to Finding Your Way Around PowerShell, Effective PowerShell, 

Effective PowerShell Item 2: Use the Objects Luke. Use the Objects 

 Effective PowerShell Item 3: Know Your Output Formatters

 Effective PowerShell Item 4: Commenting Out Lines in a Script File

 Effective PowerShell Item 6: Know What Objects Are Flowing Down .the pipe

 Effective PowerShell Item 7: Understanding "Output"

Effective PowerShell Item 8: Output Cardinality - Scalars .

 Effective PowerShell Item 9: Regular Expressions 

 Effective PowerShell Item 10: Understanding PowerShell Parsing 

 

 

 

Simple and effective PowerShell scripts for Exchange

Simple and effective PowerShell scripts for Exchange

The first one is the one-liner he wrote to help him out of the "Incredible Growing Logs" problem, which lists out the users connected to a particular mailbox store and which client they're using (Outlook versions or HTTP for OWA)
A one line script which checks the free disk space on every logical local drive on every computer in a specific OU:
The PowerShell that they use the most at the university is this script, which returns some mailbox details, including SMTP addresses, quota and usage for a user on Exchange 2003 or 2007:
The last Exchange-related PowerShell stuff is entitled "How much space are orphaned mailboxes taking up on my Exchange servers?" and does what it says on the tin.

array compare

This article was Previously posted on Ying Li' 


$arrFirst = get-content First.txt
$arrSecond = get-content Second.txt

New-Item "C:\Myworkplace\ps\FirstInSecond.txt" -Type file
New-Item "C:\Myworkplace\ps\FirstNotInSecond" -Type file

Foreach ($First in $arrFirst)
{
If ($arrSecond -contains $First)
{Add-content "C:\Myworkplace\ps\FirstInsecond.txt" $First}
Else
{Add-content "C:\Myworkplace\ps\FirstNotInSecond.txt" $First}



===

PS> $a1 = 1,1,2
PS> $a2 = 1,2,1


You could force "sequence equality" by setting SyncWindow to 0:
Compare-Object $a1 $a2 -SyncWindow 0
 

f5 powershell bigIP

F5 has integrated the BIG-IP system with Microsoft PowerShell using the iControl API/SDK. The iControl PowerShell Cmdlets and scripts make use of the iControl .NET Assembly available from F5, and can be used to manage F5 devices

Saturday, December 20, 2008

ws-management - posh remoting

 Enabling WS-Management through Group Policy


Installation and Configuration for Windows Remote Management




Configuring WS-Management

about_remote_requirements 
about_remote_faq 




Out of the box; Vista WS-Man e xposes WMI information as well as Windows Remote Shell capabilities. What this means is that with WS-Man it's much easier to get instrumentation from remote machines as well as use that info in scripts.

ctp2 summary

ctp2 summary from http://www.scribd.com

Monday, December 15, 2008

snap-ins

To determine which snap-ins you can add to the standard Windows PowerShell console, type the following command at the command prompt:

Get-PSSnapin -Registered

to add a snap-in

add-pssnapin [-name]

To see the installed snapins use



Get-PSSnapin


Removes Windows PowerShell snap-ins from the current console.


Remove-PSSnapIn [-name]

Saturday, December 6, 2008

PowerShellASP


From their site: 
PowerShellASP is an ASP-like template language for Web Applications; templates contain a mixture of markup (HTML, XML or whatever you want to generate) and inline PowerShell code. At runtime, templates/pages are fully translated to PowerShell code and executed as a single unit inside a PowerShell pipeline, with the results sent to the client browser.
PowerShellASP runs off the ASP.NET platform, implemented as a custom IHttpHandler mapped to *.ps1x files. Because of this, you can mix PowerShellASP pages alongside any ASP.NET application. This provides a great way to leverage PowerShellASP inside your existing applications as needed or you can create complete applications from scratch based only on *.ps1x pages.

map ad

Get-ADMapObject   


Map Active Directory objects using the Show-NetMap script



needs
Microsoft Research .NetMap and PowerShell

using posh to get-sqldata

 Accessing SQL Server Data from PowerShell, Part 1

Accessing SQL Server Data from PowerShell, Part 2 Use ADO.NET to insert, update, and delete data



Parse SQL DataSet to variables in Windows Powershell - scrool 2 end 

Getting Powershell output into a sql table in Windows Powershell  

PowerShell Mini SQL Query Analyzer


how to connect to a SQL database, query the Employees table of the Northwind database, and write those results to the screen.  


Using Powershell to Generate Table-Creation Scripts

Create Your First SQL Server Database in 3 Quick Steps

Accessing SQL Server Data from PowerShell, Part 1



SQL Server PowerShell Overview
get-data from sql start-sql

Quick and Dirty Software Inventory with PsInfo and PowerShell


 executing SQL queries from Powershell in Windows Powershell 


Check your SQL Server using Windows PowerShell –series

If you install the SQL Server 2008 client software, you get a SQL Server
PowerShell snap-in. You can run the sqlps.exe utility that loads the snapin
into a PowerShell environment, or start PowerShell and load in the snap-in
yourself. With the snap-in, you can get a list of the instances on a
computer by:

cd SQLSERVER:\SQL\MyComputerName
dir

Running SQL Server PowerShell:
http://msdn.microsoft.com/en-us/library/cc281954.aspx
Using the SQL Server PowerShell Provider:
http://msdn.microsoft.com/en-us/library/cc281947.aspx

NOTE: the Running SQL Server PowerShell topic still uses the old names for
the snap-in. The next update to Books Online includes an update to the topic
that uses the released names: SqlServerProviderSnapin100 and
SqlServerCmdletSnapin100.
-- 



poshOUT-2-sqlIN 


parse results - scroll 2 end

sharepoint&posh

SharePoint and PowerShell Demo - Part 1
SharePoint and PowerShell Demo - Part 2

Karine Bosch > posh & sharepoint entries

Powershell to control SharePoint

Taming SharePoint -powerGUI

Manipulating remote SharePoint Lists with PowerShell

PowerShell & the SharePoint object model

SharePoint and PowerShell - practical tips


Presention Slides and PowerShell code from UK SharePoint User Group Thursday 26'th October

PowerShell for Flexible Iterative SharePoint-based Development



articles on setting up a sharepoint dev environment:

Using Tools to make SharePoint Development Easier



Powershell + SharePoint

Automating Common SharePoint Tasks with PowerShell





Wednesday, December 3, 2008

profile load issue solved

File C:\Users\Gaurav\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see “get-help about_signing” for more details.
At line:1 char:2
+ .  <<<< ‘C:\Users\Gaurav\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1′
This is because PowerShell does not allow the execution of scripts by default. To fix this open PowerShell in Admin mode and set the execution policy to unrestricted by running the following command:

Set-ExecutionPolicy remotesigned
 
Notepad $profile 
Add-PSSnapin Quest.ActiveRoles.ADManagement
Set-ExecutionPolicy remotesigned