it:ad:windows:howto:automate_the_configuration:home

IT:AD:Windows:HowTo:Automate the Configuration

Summary

You can spend all day doing it by hand, or work smart, using IT:AD:Powershell, IT:AD:Chocolatey, IT:AD:NPM, etc. to download and install the tools you will need.

Usage:

Remove-Module "initialize-tools"
Import-Module "./initialize-tools.ps1"
cls
Initialize-Tools

The instructions are pretty straightforward:

PS C:\tmp\Scripts> Initialize-Tools
--------------------------------------------------------------------------------
INSTRUCTIONS:
Work with the following flags to change what is installed:
eg: Initialize-Tools -go -isWorkstation -isDevWorkstation

Flags:
-isWorkstation: False
-isDevWorkstation: False
-isMediaWorkstation: False
-isServer: False
-isCIServer: False
-visualServerVersion: Professional [Universal|Professional|Community]
-ciServiceAccountName: Svc-CI
-ciServiceAccountPassword:  (Must be set, or step skipped)

When ready, set the 'go' flag to actually install, rather than dry run:
-go: False
--------------------------------------------------------------------------------



	function EnsureAppsDirectory(){
	  md -Force c:\APPS 
	}
	function CreateLinuxHOMEEnvironmentVariable(){
	  if (!$Env:HOME)
	  {
		echo "Creating HOME Env variable.fsenv  "
		[Environment]::SetEnvironmentVariable("HOME", $Env:UserProfile, "User")
	  }
	}
	function InstallChocolatey(){
	  if (!$Env:path.ToLower().Contains("chocolatey".ToLower()))
	  {
		iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))
		$tmpPath = [Environment]::GetEnvironmentVariable("TestVariable","Path","User");
		[Environment]::SetEnvironmentVariable("Path", $tmpPath + ";%ALLUSERSPROFILE%\chocolatey\bin", "User")
	  }
	  RefreshEnvironmentVariables
	}

	function Initialize-Tools([switch]$go, [switch]$isWorkstation, [switch]$isDevWorkstation,  [switch]$isMediaWorkstation, [switch]$isServer, [switch]$isCIServer, [string]$visualServerVersion="Professional", [string]$ciServiceAccountName="Svc-CI", [string]$ciServiceAccountPassword){

	  Write-Host "--------------------------------------------------------------------------------"
	  Write-Host "INSTRUCTIONS:" 
	  Write-Host "Work with the following flags to change what's installed:"
	  Write-Host "eg: Initialize-Tools -go -isWorkstation -isDevWorkstation"
	  Write-Host ""
	  Write-Host "Flags:"
	  Write-Host "-isWorkstation: $isWorkstation"
	  Write-Host "-isDevWorkstation: $isDevWorkstation"
	  Write-Host "-isMediaWorkstation: $isMediaWorkstation"
	  Write-Host "-isServer: $isServer"
	  Write-Host "-isCIServer: $isCIServer"
	  Write-Host "-visualServerVersion: $visualServerVersion [Universal|Professional|Community]"
	  Write-Host "-ciServiceAccountName: $ciServiceAccountName"
	  Write-Host "-ciServiceAccountPassword: $ciServiceAccountPassword (Must be set, or step skipped)"
	  Write-Host ""
	  Write-Host "When ready, set the 'go' flag to actually install, rather than dry run:"
	  Write-Host "-go: $go"
	  Write-Host "--------------------------------------------------------------------------------"
	  
	  CreateGlobalSpecs -go:$go -isWorkstation:$isWorkstation -isDevWorkstation:$isDevWorkstation -isMediaWorkstation:$isMediaWorkstation -isServer:$isServer -isCIServer:$isCIServer -visualServerVersion:$visualServerVersion  -ciServiceAccountName:$ciServiceAccountName -ciServiceAccountPassword:$ciServiceAccountPassword 
	  
	  LogicalChecksForGlobalSpecs

	  if ($specs.InstallCommonTools -eq $false){
		return;
	  }

	  EnsureAppsDirectory
	  
	  Install_Workstation_Containers
	  Install_Common_Runtimes
	  RefreshEnvironmentVariables
	  Install_Common_CompressionTools
	  Install_Common_PackageManagementTools
	  Install_Common_PackageDeploymentTools
	  Install_Common_SourceControlTools
	  Install_Common_DiagnosticsTools
	  Install_Common_NetworkClientTools
	  Install_Common_WindowsServiceTools
	  Install_Common_BasicDesktopTools
	  Install_Common_ProductivityTools
	  Install_Workstation_Productivity_Tools
	  Install_Workstation_Browsers
	  Install_Workstation_RemoteAccessTools
	  Install_Workstation_DevTools
	  Install_Workstation_Misc
	  Install_Server_OpenSourceCITools
	  Install_Server_CIServiceAccount
	  
	  RefreshEnvironmentVariables
	  
	  #from : githum/msysgit...
	}

	function RefreshEnvironmentVariables(){
	  # after installing some applications
	  # we need to re-import the PATH so that
	  # subsequent operations work correctly.
	  RefreshEnv
	}


	function CreateGlobalSpecs([switch]$go, [switch]$isWorkstation, [switch]$isDevWorkstation, [switch]$isMediaWorkstation, [switch]$isServer, [switch]$isCIServer, [string]$visualServerVersion="Professional", [string]$ciServiceAccountName="Svc-CI", [string]$ciServiceAccountPassword){

	  if (Test-Path variable:global:specs){
		[hashtable]$global:specs = @{}
		# Array to track what is to be installed/excluded from installation:
		$specs.Install = @{};
	  }
	  
	  $specs.TestRun = !$go;

	  #Array to keep track of what's been installed.
	  $specs.Installed = @{};
		
	  # if you install VS, use the following license:
	  $specs.VisualStudioVersion = $visualServerVersion; #[Ultimate|Professional|Community] 
	  
	  $specs.InstallCommonTools = $false;
	  $specs.InstallWorkstationTools = $isWorkstation;
	  $specs.InstallWorkstationDevTools = $isDevWorkstation;
	  $specs.InstallWorkstationMiscTools = $isMediaWorkstation;

	  $specs.InstallServerTools = $isServer;
	  $specs.InstallServerCITools = $isCIServer;

	  $specs.Accounts = @{};
	  $specs.Accounts.CIServiceAccountName = $ciServiceAccountName;
	  $specs.Accounts.CIServiceAccountPassword = $ciServiceAccountPassword;
	  #TODO:
	  #SET JAVA_HOME:C:\Program Files (x86)\Java\jre6
	  #And that it the path to java is part of the PATH Environment Variable:
	  #Append to PATH:%JAVA_HOME%\bin\
	}

	function LogicalChecksForGlobalSpecs(){
	  if (($specs.InstallWorkstationMiscTools -eq $true) -or ($specs.InstallWorkstationDevTools -eq $true)) { $specs.InstallWorkstationTools=$true;}
	  if ($specs.InstallServerCITools -eq $true) { $specs.InstallServerTools=$true;}
	  if (($specs.InstallWorkstationTools -eq $true) -or ($specs.InstallServerTools -eq $true)){ $specs.InstallCommonTools = $true;}
	}

	function Install_Package ([string]$packageName, [string]$flagName, [string]$version){
	  if (!$flagName){
		$flagName = $packageName -replace "\W", "";
	  }

	  if ($specs.Install.$flagName -ne $false){
		if ($specs.TestRun -eq $true){
		  Write-Host("TestRun: would install $packageName (flagName: $flagName)")
		}
		else {
		  choco install $packageName -y -version $version
		}
		$specs.Installed.$flagName = $true;
	  }else{
		  Write-Host("Skipping $packageName")
	  }
	}


	function Install_Workstation_Containers(){
	  if ($specs.InstallCommonTools -eq $false){
		return;
	  }
	  Install_Package -packageName:"vagrant";
	}

	function Install_Common_Runtimes(){
	  if ($specs.InstallCommonTools -eq $false){
		return;
	  }
	  Install_Package -packageName:"dotnet4.5" -flagName:"net";

	  # maybe a bit controversial. 
	  # Does everybody need the full 
	  # versus just the RTE?  Probably not. But it's
	  # easier to manage one install than two (RTE, 
	  # and also JDK)
	  Install_Package -packageName:"jdk8" -flagName:"java";

	  # Not just for devs -- many admin tools 
	  # are moving to/adding Node
	  Install_Package -packageName:"nodejs";
	  Install_Package -packageName:"python";

	  # Not as common as NodeJS, but 
	  # required by front end developers and build
	  # engines for Compass, etc.
	  Install_Package -packageName:"ruby";
	}

	function Install_Common_CompressionTools(){
	  if ($specs.InstallCommonTools -eq $false){
		return;
	  }
	  # Windows Zip features have improved over the years.
	  # But still have to deal with packages that are not 
	  # *.zip.
	  Install_Package -packageName:"7zip.install" -flagName:"sevenzipinstall";
	}

	function Install_Common_PackageManagementTools(){
	  if ($specs.InstallCommonTools -eq $false){
		return;
	  }
	  Install_Package -package:"nugetpackageexplorer";
	  Install_Package -package:"chocolateypackageupdater";
	  Install_Package -package:"chocolateygui";
	  Install_Package -package:"nuget.commandline" -flagName:"nuget.commandline";
	}

	function Install_Common_PackageDeploymentTools(){
	  if ($specs.InstallCommonTools -eq $false){
		return;
	  }
	  #msdeploy is the only official microsoft deployment mechanism at present:
	  Install_Package -packageName:"webdeploy";
	}

	function Install_Common_SourceControlTools(){
	  if ($specs.InstallCommonTools -eq $false){
		return;
	  }
	  # although it may seem at first strange to install source control
	  # tools on servers, more and more packaging solutions are directly
	  # retrieving script files from remote stable repositories.
	  Install_Git
	  Install_Package -packageName:"hg";
	  RefreshEnvironmentVariables
	}

	function Install_Git(){
	  if ($specs.InstallCommonTools -eq $false){
		return;
	  }
	  #hack due to: http://stackoverflow.com/a/29305866
	  Install_Package -packageName:"git.install" -flagName:"gitinstall" -version:"1.9.5.20150114";
	}

	function Install_Common_DiagnosticsTools(){
	  if ($specs.InstallCommonTools -eq $false){
		return;
	  }
	  Install_Package -packageName:"linqpad";
	  Install_Package -packageName:"fiddler";
	  Install_Package -packageName:"wireshark";
	  #takes surprisingly long to download:
	  Install_Package -packageName:"microsoft-message-analyzer" -flagName:"microsoftmessageanalyzer";
	  Install_Package -packageName:"logparser";
	  Install_Package -packageName:"logparser.lizardgui" -flagName:"lizardgui";
	  Install_Package -packageName:"sysinternals";
	}

	function Install_Common_NetworkClientTools(){
	  if ($specs.InstallCommonTools -eq $false){
		return;
	  }
	  # ssh:
	  Install_Package -packageName:"putty.install" -flagName:"putty";
	  # ftp:
	  Install_Package -packageName:"filezilla";
	  # installation scripts on servers, and developer testing on workstations:
	  Install_Package -packageName:"curl";
	  Install_Package -packageName:"wget";
	  Install_Package -packageName:"wput";
	}

	function Install_Common_WindowsServiceTools(){
	  if ($specs.InstallCommonTools -eq $false){
		return;
	  }
	  # Build servers use services. 
	  # Configuring services in Windows
	  # is unnecessarily difficult.
	  Install_Package -packageName:"nssm";
	}

	function Install_Common_BasicDesktopTools(){
	  if ($specs.InstallCommonTools -eq $false){
		return;
	  }
	  # Window's notepad sucks. 
	  # Whether you're a developer or not.
	  Install_Package -packageName:"notepadplusplus.install" -flagName:"notepadplusplus";
	  Install_Package -packageName:"paint.net" -flagName:"paintnet";
	  Install_Package -package:"foxitreader";
	}

	function Install_Common_ProductivityTools(){
	  if ($specs.InstallCommonTools -eq $false){
		return;
	  }
	  Install_Package -package:"wincommandpaste";
	}

	function Install_Workstation_Productivity_Tools(){
	  if ($specs.InstallWorkstationTools -eq $false){
		return;
	  }
	  #virtual kvm for developers managing
	  # multiple stations (eg, personal laptop and client workstation):
	  Install_Package -packageName:"synergy";
	}

	function Install_Workstation_Browsers(){
	  if ($specs.InstallWorkstationTools -eq $false){
		return;
	  }
	  Install_Package -packageName:"google-chrome-x64" -flagName:"chrome";
	}

	function Install_Workstation_RemoteAccessTools(){
	  if ($specs.InstallWorkstationTools -eq $false){
		return;
	  }
	  #nobody seems to agree which one is the best, so since they're all
	  #pretty lightweight, install them all:
	  Install_Package -packageName:"teamviewer";
	  Install_Package -packageName:"mremoteng";
	  Install_Package -packageName:"terminals.app" -flagName:"terminalsapp";
	}

	function Install_Workstation_DevTools(){
	  if ($specs.InstallWorkstationTools -eq $false -or $specs.InstallWorkstationDevTools -eq $false){
		return;
	  }
	  Install_Workstation_DevBrowsers
	  Install_Workstation_NETDevTools
	  Install_Workstation_FrontEndDevTools
	}

	function Install_Workstation_DevBrowsers(){
	  if ($specs.InstallWorkstationTools -eq $false -or $specs.InstallWorkstationDevTools -eq $false){
		return;
	  }
	  Install_Package -packageName:"google-chrome-x64" -flagName:"chrome";
	  Install_Package -packageName:"firefox";
	  Install_Package -packageName:"opera";
	}

	function Install_Workstation_NETDevTools(){
	  if ($specs.InstallWorkstationTools -eq $false -or $specs.InstallWorkstationDevTools -eq $false){
		return;
	  }
	  if ($specs.VisualStudioVersion -eq "Ultimate"){
		Install_Package "visualstudio2013ultimate" -flagName:"visualstudio";
	  }
	  if ($specs.VisualStudioVersion -eq "Professional"){
		Install_Package "visualstudio2013professional" -flagName:"visualstudio";
	  }
	  if ($specs.VisualStudioVersion -eq "Community"){
		Install_Package "isualstudiocommunity2013" -flagName:"visualstudio";
	  }

	  #always installs the latest (may force you to update your licensing)
	  Install_Package -packageName:"resharper";
	  Install_Package -packageName:"resharper-clt.portable" -flagName:"resharpercltportable";
	  Install_Package -packageName:"nunit";
	  # the current version is too stale -- commenting out:
	  #Install_Package -packageName:"stylecop";
	  # local dev mail servers (ie null MTAs) allow dev'ing and testing smtp services:
	  Install_Package -packageName:"papercut";
	  Install_Package -packageName:"smtp4dev";
	  # Within Resharper, there's a tool to disassembling and looking at source code
	  # of assemblies on which your apps have dependencies, but for investigating other products/assemblies,
	  # this is more appropriate:
	  Install_Package -packageName:"dotpeek";
	  #With webdeploy(actually, msdeploy), this is rarely needed now,
	  #but still adding it until MSI's are really really history.
	  Install_Package -packageName:"wixtoolset";
	}

	function Install_Workstation_FrontEndDevTools(){
	  if ($specs.InstallWorkstationTools -eq $false -or $specs.InstallWorkstationDevTools -eq $false){
		return;
	  }
	  Install_Git
	  Install_Package -packageName:"hg";
	  Install_Package -packageName:"sublimetext3";

	  if ($specs.TestRun -eq $true){
		Write-Host("TestRun: Would Install yo bower and grunt...")
	  }
	  else{
		RefreshEnvironmentVariables
		#$tmp=$env:AppData + "\NPM\" +'npm'
		$tmp = $env:ProgramFiles + "\NodeJS\NPM"  
		&$tmp update -g npm
		&$tmp install --global yo bower grunt-cli

		&yo --version
		&bower --version
		&grunt --version
	  }
	}

	function Install_Workstation_Misc(){
	  if ($specs.InstallWorkstationTools -eq $false -or $specs.InstallWorkstationMiscTools -eq $false){
		return;
	  }
	  Install_Package -packageName:"vlc";
	  Install_Package -packageName:"handbrake";
	  Install_Package -packageName:"shotcut";
	}

	function Install_Server_OpenSourceCITools(){
	  if ($specs.InstallServerTools -eq $false -or $specs.InstallServerCITools -eq $false){
		return;
	  }

	  Install_Package -packageName:"jenkins";
	  #for ci if vs is not installed
	  Install_Package -packageName:"microsoft-build-tools" -flagName:"microsoftbuildtools";
	}

	function Install_Server_CIServiceAccount(){
	  if ($specs.InstallServerTools -eq $false -or $specs.InstallServerCITools -eq $false){
		return;
	  }
	  if (!$specs.Accounts.CIServiceAccountPassword){
		Write-Host "No CI Service Account password provided. Step Skipped."
		return;
	  }
	  if (!$specs.go){
		Write-Host "TestRun: would create account for ${specs.Accounts.CIServiceAccountName} [${specs.Accounts.CIServiceAccountPassword}]"
	  }else {
		$hostname = $env:Computername;
		$username = $specs.Accounts.CIServiceAccountName;
		Ensure-LocalUser -userName:$username -password:$specs.Accounts.CIServiceAccountpassword
		#Add to a group:
		net localgroup Administrators $hostname\$username /ADD
	  }
	}

	function Ensure-LocalUser(){
	  [CmdletBinding()]
	  param(
		[Parameter(Mandatory=$true)]
		[string] $userName,
		[Parameter(Mandatory=$true)]
		[string] $password
		[Parameter()]
		[string] $description=""
	  )
	  process{

		$objOu = [ADSI]"WinNT://${env:Computername}"
		$localUsers = $objOu.Children | where {$_.SchemaClassName -eq 'user'}  | % {$_.name[0].ToString()}

		if($localUsers -NotContains $userName)
		{
		  $objUser = $objOU.Create("User", $userName)
		  $objUser.setpassword($password)
		  $objUser.SetInfo()
		  $objUser.description = description
		  $objUser.SetInfo()

		  return $true
		}
		else
		{
		  return $false
		}

	  }
	}

	CreateLinuxHOMEEnvironmentVariable
	InstallChocolatey

  • /home/skysigal/public_html/data/pages/it/ad/windows/howto/automate_the_configuration/home.txt
  • Last modified: 2023/11/04 02:33
  • by 127.0.0.1