Monday, November 12, 2018

Number one complaint I hear about Chocolatey and why its no big deal.

The number one complaint hear from people when I pitch them Chocolatey is:  "How do I know that what I'm installing is safe?" Let's look at why people are asking this. First, Chocolatey is downloading packages that contain installers and powershell scripts and then executing them. Second, anyone can submit a package. It's easy to see why a person might not be comfortable with this scenario. Lets keep in mind that Chocolatey uses moderation and packages are virus scanned when uploaded, but according to there docs virus scanning at runtime and during install is for (paid versions) licensed editions only. Some people I have talked to are still sceptical about using it even with virus scanning. This really boils down to wanting perfect control, or not trusting the moderation.

There is an easy way to make Chocolatey just as secure as your current manual or automated process. If you create your own packages and internally host your own Chocolatey server you will be no less secure than your current process. Creating you own packages will allow you to point to versions of installers your team has downloaded directly from the vendors. You can also control what powershell is running during install. Hosting the your own Chocolatey server is as easy as setting up a Nuget server.  

After you set up Setup a Chocolatey server, the steps to create your local and "safe" packages are.
  1. Download the package from Chocolatey.org
  2. Modify the package to point to your local binaries
  3. Verify powershell doesn't do anything you want
  4. publish the package to your local Chocolatey Server
In most cases you'll see that your really just downloading a package from Chocolatey, modifying the url to point to your local installer, then publishing it locally. It's so quick and you'll have exactly what you what perfect control. 

I would argue that you don't need perfect control and you can trust moderation. I would still set up a local Chocolatey server, but not for security. Having a local Chocolatey server allows you to make packages that are customized and faster downloads. 

The number two complaint: "so why the dumb name?", some people don't get the reference right away. 



Wednesday, November 7, 2018

Fully automated .NET developer machine setup

How to Automate the setup of a .NET development environment.  The powershell script below leverages two FREE Package Management systems: BoxStarter and Chocolatey.  I use scripts like these to set up anything I use from test servers to to my developer machine.

The script will first install both BoxStarter and Chocolatey then it will install multiple packages as well as do some configuration and uninstall some bloatware. Best part about this script is that its completely free, you can run this script and when it finishes, your ready to connect to your source server and start developing. You can even create an uninstall script to set the machine back to the original sate.

To run the sample script below, make sure your connected to the internet, then open a Powershell as Admin and paste the following script:
##### install Package Management software #####
# install choco
iwr https://chocolatey.org/install.ps1 -UseBasicParsing | iex
# install Boxstarter
. { iwr -useb http://boxstarter.org/bootstrapper.ps1 } | iex; get-boxstarter -Force

#--- Windows Settings ---
Disable-UAC
Disable-BingSearch
Disable-GameBarTips
Set-WindowsExplorerOptions -EnableShowHiddenFilesFoldersDrives -EnableShowProtectedOSFiles -EnableShowFileExtensions

###### Install #####
# install Stuff
choco install paint.net -y
choco install windirstat -y
choco install googlechrome -y
choco install firefox -y
choco install sysinternals -y
# install DEV Stuff
choco install Visualstudiocode -y
choco install visualstudio2017community -y --allow-empty-checksums
choco install nodejs -y
choco install fiddler4 -y
choco install Microsoft-Hyper-V-All -source windowsFeatures

###### Config #####
# Start Menu: Disable Bing Search Results
Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Search -Name BingSearchEnabled -Type DWord -Value 0

##### Uninstall bloatware #####
Get-AppxPackage Microsoft.BingFinance | Remove-AppxPackage
Get-AppxPackage Microsoft.BingNews | Remove-AppxPackage
Get-AppxPackage Microsoft.BingSports | Remove-AppxPackage
Get-AppxPackage Microsoft.BingWeather | Remove-AppxPackage

Enable-UAC


It should be obvious what packages are being installed in this script, I recommend you not run this script.  You should modify it to suit your specific needs before running.  You can visit the Chocolatey.org to see a full list of available packages (currently 4,665 packages) and visit BoxStarter.org to see a full list of available powershell commandlets and configuration options.

Links to open source projects for BoxStarter and Chocolatey

Friday, January 26, 2018

SSMS (SQL Server Management Studio) I ain't got time for all that...

Command-line SQL has always been easy, I have been writing sql in DOS like this from way back in
the day. The following examples are meant to be in DOS or Powershell; and funny, sorry if they aren't funny.

This example is in DOS
sqlcmd -Q "SELECT * FROM [Jokes].[Mom] WHERE type = 'Fat'" -o FatMomJokes.txt


But when you mix Powershell and SQL you can be more productive and creative.

$Jokes = Invoke-Sqlcmd -Query "Select * From [Jokes].[Mom]"
ForEach ($joke in $Jokes){
  if($joke.Name -eq "your mom"){
    Write-Host "$joke.Tell"
    $script = "Update [Jokes].[Mom] Set Status = 'Told' Where id = $dumb.Id"
    Invoke-Sqlcmd -Query $script
  }
}

$script = "INSERT INTO [Jokes].[Mom] ([Description],[InsertDateTime])
VALUES ('All night long', '$(Get-Date -Format "yyyy-MM-dd HH:mm:")')"
Invoke-Sqlcmd -Query $script -ServerInstance "localhost\sqlexpress"