jueves, 16 de septiembre de 2010

BITS + PowerShell: Get the power!

Share it Please

Following with the methods to work with BITS, if your machine is running Windows 7 or you are uploading/downloading files from a Windows 2008 Server, you can use PowerShell commands to work with BITS in the same that we have used the bitsadmin.exe tool.

In this case, we will download an installer file stored in a BITS server to our Windows 2008 server, so the first step is to open the PowerShell window an import the Bits Transfer module:

Import-Module BitsTransfer

Now, a good way to know all the command (or cmdlets) we can use to work with Bits is to run the following command:

Get-Command –Module BitsTransfer

All commands and definitions are displayed:

clip_image002

It seems that the cmdlet that we need is Start-BitsTransfer. If you are not sure, you can run the following command to get a complete description about this cmdlet:

Get-Help Start-BitsTransfer

A complete description including syntax is displayed:

clip_image004

As you can see on the REMARKS section you can use other commands to get more information about this cmdlet. One of these commands is the –examples one:

Get-Help Start-BitsTransfer –examples

You can see 8 different examples about how to use this command to create a Bits job and download/upload files. We will use the following one to download our installer:

Start-BitsTransfer -Source https://myserver.domain.com/SQL2008R2.iso -Destination D:\Installers\SQL2008R2.iso

A green box will appear while you connect with BITS server and download the file:

clip_image006

And a status bar will appear between [ and ] symbols. Evidently, if you are trying to upload/download a file to a protected BITS server, you have to specify your credentials and authentication method in the PowerShell command. You can do it in the following way:

Start-BitsTransfer -Source https://myserver.domain.com/SQL2008R2.iso -Destination D:\Installers\SQL2008R2.iso -Authentication NTLM -Credential "domain\myID"

When you click Enter an authentication window will appears requesting you your password.

As a summary, we need to execute just two PowerShell commands to download a file from a BITS server:

Import-Module BitsTransfer

Start-BitsTransfer -Source <url or path> -Destination <url or path> -Authentication [NTLM, Basic, etc.] -Credential "domain\myID" -TransferType [Upload/Download]

If we want to upload a file the command to use is very similar to the download one but adding the parameter TransferType:

Start-BitsTransfer -Source <url or path> -Destination <url or path> -TransferType <Upload>

As you can see on the examples, you can do the same in many ways playing with the 8 commands that BitsTransfer module offers to us and the rest of commands included in PowerShell.

Next post…How to work with BITS using a GUI tool.

No hay comentarios:

Publicar un comentario

Project Mgmt. Professional

Project Mgmt. Professional

AWS Architect

AWS Architect

ITIL Fundamentals

ITIL Fundamentals