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

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"

Thursday, December 16, 2010

Map Network Drive with a users credentials


Three quick and easy ways to Map a UNC path to a local drive. The samples below (DOS, VBS, PowerShell) map the Q: drive to a network path using different credentials. you can also remove the parameters for credentials and it will create the connection with the current logged-on user.

DOS
NET USE Q: \\MyUnc\Path /USER:MyUser MyPassword

VBS

strDrive = "Q:"
strUNC = "\\MyUnc\Path"
strProfile = "False"   ' Mapping (not) stored in user Profile
strUser = "MyUser"
strPassword = "MyPassword"
Set objNetwork = CreateObject("WScript.Network") 
objNetwork.MapNetworkDrive strDrive, strUNC, strProfile, strUser, strPassword 

Powershell

$Drive = "Q:"
$UNC = "\\MyUnc\Path"
$Profile = "False"
$User = "MyUser"
$Password = "MyPassord"
$Network = New-Object -com WScript.Network; 
$Network.mapnetworkdrive($Drive,$Unc, $Profile, $User, $Password)

The code above is basically the same as done in VBS, You can also make the DOS call in Powershell.