Attempting to register a remote machine on Team Services

Readus Sago
Readus Sago used Ask the Experts™
on
I am attempting to register a remote machine on team services with Powershell. When I enter the script on the remote machine and attempt to run it, I get the error below: Cannot add type. The assembly 'System.IO.Compression.FileSystem' could not be found. I have copied the registration script from the Deployment Groups section on team services online.

The server that I am using is windows server 2008 R2. The script is below:

$ErrorActionPreference="Stop";If(-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] “Administrator”)){ throw "Run command in Administrator PowerShell Prompt"};If(-NOT (Test-Path $env:SystemDrive\'vstsagent')){mkdir $env:SystemDrive\'vstsagent'}; cd $env:SystemDrive\'vstsagent'; for($i=1; $i -lt 100; $i++){$destFolder="A"+$i.ToString();if(-NOT (Test-Path ($destFolder))){mkdir $destFolder;cd $destFolder;break;}}; $agentZip="$PWD\agent.zip";(New-Object Net.WebClient).DownloadFile('https://github.com/Microsoft/vsts-agent/releases/download/v2.116.1/vsts-agent-win7-x64-2.116.1.zip', $agentZip);Add-Type -AssemblyName System.IO.Compression.FileSystem;[System.IO.Compression.ZipFile]::ExtractToDirectory($agentZip, "$PWD");.\config.cmd --deploymentgroup --agent $env:COMPUTERNAME --runasservice --work '_work' --url 'https://aaosprojects.visualstudio.com/' --projectname 'xxxxxxxProjects' --deploymentgroupname "xxxxxxxxxDeploymentGroup" ; Remove-Item $agentZip;
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2014
Commented:
Do you get an error when you run this command?
Add-Type -AssemblyName System.IO.Compression.FileSystem
You need to have .NET Framework 4.5 or newer installed.
Readus SagoWeb programmer

Author

Commented:
I have .net 4.5 installed on this server and still not working. I get an error when running this statement Add-Type -AssemblyName System.IO.Compression.FileSystem
Top Expert 2014

Commented:
What is the error?
How to Generate Services Revenue the Easiest Way

This Tuesday! Learn key insights about modern cyber protection services & gain practical strategies to skyrocket business:

- What it takes to build a cloud service portfolio
- How to determine which services will help your unique business grow
- Various use-cases and examples

Top Expert 2016
Commented:
are you getting the error on this line
Add-Type -AssemblyName System.IO.Compression.FileSystem

FYI you neeed .net 4.0
run
add-windowsfeature -name  net-framework-45-Features
and retry your script

refactored code
$VSTS = "$env:SystemDrive\'vstsagent'"
$ErrorActionPreference='Stop'
If(-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')){ throw 'Run command in Administrator PowerShell Prompt'}
If(-NOT (Test-Path -Path $VSTS)){mkdir -Path $VSTS}
 Set-Location -Path $VSTS
 for($i=1; $i -lt 100; $i++)
  {
  $destFolder='A'+$i.ToString()
    if(-NOT (Test-Path -Path ($destFolder)))
      {
      mkdir -Path $destFolder
      Set-Location -Path $destFolder
      break
      }
    }
 $agentZip=('{0}\agent.zip' -f $PWD)
(New-Object -TypeName Net.WebClient).DownloadFile('https://github.com/Microsoft/vsts-agent/releases/download/v2.116.1/vsts-agent-win7-x64-2.116.1.zip', $agentZip)
Add-Type -AssemblyName System.IO.Compression.FileSystem
[IO.Compression.ZipFile]::ExtractToDirectory($agentZip, ('{0}' -f $PWD))
.\config.cmd --deploymentgroup --agent $env:COMPUTERNAME --runasservice --work '_work' --url 'https://aaosprojects.visualstudio.com/' --projectname 'xxxxxxxProjects' --deploymentgroupname 'xxxxxxxxxDeploymentGroup' 
 Remove-Item -Path $agentZip
 

Open in new window

Top Expert 2016

Commented:
noticed that my vm was server 2012 not server 2008.
You might want to install WMF5.1 (windows management framework 5.1)

I now get as far as the agent's config
Readus SagoWeb programmer

Author

Commented:
Got it working. I also had to upgrade the version of powershell.
Top Expert 2014

Commented:
It appears that since .NET Framework 4.5+ is required, PS 3.0 or newer is needed because earlier versions of PS used .NET 2.0.
I've seen where you can add some config files to make PS 2.0 use .NET 4.0, but I haven't tried it out.
You can see the version used by looking at the CLRVersion property returned by $PSVersionTable.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial