Skip to content

Instantly share code, notes, and snippets.

Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
Install-Module vim-x64 -y
Install-Module -Name PowerShellForGitHub
Test-path $profile # if false then we create the profile file
// CsvHelper.CsvReader:- https://joshclose.github.io/CsvHelper/
var result = new List<OrderRow>();
using (TextReader fileReader = File.OpenText(_fileName))
{
var csvReader = new CsvReader(fileReader);
csvReader.Configuration.HasHeaderRecord = false;
while (csvReader.Read())
{
# Add TFS Package Management Source for Nuget
nuget.exe sources add -name Powershell -source http://url/to/package/repo/index.json -username VSTS -password "pat-from-tfs" -storePasswordInClearText
# Register the PowershellGet source
Register-PSRepository -Name Powershell -SourceLocation http://url/to/package/repo/index.json -PackageManagementProvider NuGet -PublishLocation http://url/to/package/repo/index.json -InstallationPolicy Trusted -Credential Get-Credential
# Finally we can push the loaded module to our TFS Repository
Publish-Module -Name Greetings -Repository Powershell -NuGetApiKey "pat-from-tfs" -Credential Get-Credential
New-ModuleManifest -Path "C:\Program Files\WindowsPowerShell\Modules\Greetings\Greetings.psd1"
-RootModule 'Greetings.psm1'
-Author 'John Moss'
function Say-Hello() {
write-host Hello! -ForegroundColour green
}
function Say-Goodbye() {
write-host Goodbye! -ForegroundColour red
}
# Register a new Repository
Register-PSRepository
-Name PSRepository
-PackageManagementProvider NuGet
-InstallationPolicy Trusted
-Credential Get-Credential
-SourceLocation https://<project-name>.pkgs.visualstudio.com/_packaging/<repo-name>/nuget/v3/index.json
-PublishLocation https://<project-name>.pkgs.visualstudio.com/_packaging/<repo-name>/nuget/v3/index.json
@johnmmoss
johnmmoss / dotnetcore-test-modelstate.cs
Created October 16, 2017 12:49
Unit Test the model state in dotnet core
var controller = new CustomerController(_customerService.Object);
var newModel = new CreateModel();
var validationContext = new ValidationContext(newModel, null, null);
var validationResults = new List<ValidationResult>();
Validator.TryValidateObject(newModel, validationContext, validationResults, true);
foreach (var validationResult in validationResults)
{
controller.ModelState.AddModelError(validationResult.MemberNames.FirstOrDefault() ?? string.Empty, validationResult.ErrorMessage);
do {
write-host Installing powershell 4.0... -ForegroundColor Gray
start-sleep -s 10
} while ((get-process | where { $_.ProcessName -eq "wusa" }) -ne $Null)
$currentPsVersion = (get-host).Version.Major;
if ((get-host).Version.Major -ge 4) {
write-host Powershell version $currentPsVersion is already installed -ForegroundColor Red
return;
}
$ps4DownloadUrl = "http://download.microsoft.com/download/3/D/6/3D61D262-8549-4769-A660-230B67E15B25/Windows6.1-KB2819745-x64-MultiPkg.msu"
$ps4LocalPath = "$env:temp\ps4.msu"
$wusaPath = "$env:windir\System32\wusa.exe"
gci -Path E:\Code -Filter *.sln -Recurse | % {
$exists = (select-string "^Project.*`"$ProjectName`"" $_.FullName).Matches.Count
if ($exists -gt 0) {
write-host $_.FullName -ForegroundColor green
} else {
write-host $_.FullName -ForegroundColor gray
}
}