Showing posts with label PowerShell. Show all posts
Showing posts with label PowerShell. Show all posts

Monday, January 17, 2011

TSF + PowerShell: List all projects

This will create TFS instance and get all project from the instance.
$registryValue is an object to be displayed in the output grid of PowerGUI window.

    $tfs = get-tfs "http://TFS-URL"
    $projects = $tfs.CSS.ListAllProjects()
    
    foreach($pro in $projects) {
    $registryValue = New-Object System.Management.Automation.PSObject
    $registryValue `
        | Add-Member -Name Name -MemberType NoteProperty -Value $pro.Name -PassThru `
        | Add-Member -Name Status -MemberType NoteProperty -Value $pro.Status -PassThru `
        | Add-Member -Name URI -MemberType NoteProperty -Value $pro.Uri-PassThru `
        | Add-Member -Name BS -MemberType NoteProperty -Value $tfs.BS -PassThru

TFS + PowerShell: Create TFS instance

TFS VS 2010 and PowerShell 2

This function returns TFS instance which will be used in use cases to follow later.

function get-tfs (
    [string] $serverName = $(Throw 'serverName is required')
)
{
    # load the required dll

    [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client")

    $propertiesToAdd = (
        ('VCS', 'Microsoft.TeamFoundation.VersionControl.Client', 'Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer'),
        ('WIT', 'Microsoft.TeamFoundation.WorkItemTracking.Client', 'Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore'),
        ('BS', 'Microsoft.TeamFoundation.Build.Client', 'Microsoft.TeamFoundation.Build.Client.IBuildServer'),
        ('CSS', 'Microsoft.TeamFoundation', 'Microsoft.TeamFoundation.Server.ICommonStructureService'),
        ('GSS', 'Microsoft.TeamFoundation', 'Microsoft.TeamFoundation.Server.IGroupSecurityService')
    )

    # fetch the TFS instance, but add some useful properties to make life easier
    # Make sure to "promote" it to a psobject now to make later modification easier

    [psobject] $tfs = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer($serverName)
    foreach ($entry in $propertiesToAdd) {
        $scriptBlock = '
            [System.Reflection.Assembly]::LoadWithPartialName("{0}") > $null
            $this.GetService([{1}])
        ' -f $entry[1],$entry[2]
        $tfs | add-member scriptproperty $entry[0] $ExecutionContext.InvokeCommand.NewScriptBlock($scriptBlock)
    }
    return $tfs
}


get-tfs "http://TFS-URL"

Wednesday, December 15, 2010

Configuration of Windows Remote Management for PowerShell

1.   winrm quickconfig

PS C:\Windows\system32> Winrm quickconfig
WinRM already is set up to receive requests on this machine.
WinRM is not set up to allow remote access to this machine for management.
The following changes must be made:

Create a WinRM listener on HTTP://* to accept WS-Man requests to any IP on this machine.
Enable the WinRM firewall exception.

Make these changes [y/n]? y

WinRM has been updated for remote management.

Created a WinRM listener on HTTP://* to accept WS-Man requests to any IP on this machine.
WinRM firewall exception enabled.
PS C:\Windows\system32>

2.  winrm quickconfig -transport:https

PS C:\Windows\system32> winrm quickconfig -transport:https
WinRM already is set up to receive requests on this machine.
WinRM is not set up to allow remote access to this machine for management.
The following changes must be made:

Create a WinRM listener on HTTPS://* to accept WS-Man requests to any IP on this machine.
Configure CertificateThumbprint setting for the service, to be used for CredSSP authentication.

Make these changes [y/n]? y

WinRM has been updated for remote management.

Created a WinRM listener on HTTPS://* to accept WS-Man requests to any IP on this machine.
Configured CertificateThumbprint setting for the service.

3. Listener and WS-Management protocol Default Settings

winrm enumerates winrm/config/listener

4. Remote Admin IIS for TFS 2010 Builds

http://www.tadlockenterprises.com/2009/12/remote-admin-iis-for-tfs-2010-builds
http://msdn.microsoft.com/en-us/library/aa384372%28VS.85%29.aspx
http://blogs.msdn.com/b/powershell/archive/2008/05/10/remoting-with-powershell-quickstart.aspx

Enable IIS7 PowerShell snapin in PowerShell session


Installation: http://learn.iis.net/page.aspx/429/installing-the-iis-70-powershell-snap-in
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
Import-Module webadministration | Out-Null
Get-Website

http://www.iisworkstation.com/2009/06/troubleshooting-iis-powershell-module.html


P.S. PowerShell is installed by default on Windows Server 2008 R2

Tuesday, December 14, 2010

Set-ExecutionPolicy in PowerShell

To alllow all user to execute scripts in PowerShell:
Set-ExecutionPolicy -ExecutionPolicy Unrestricted

Powered by Blogger.