This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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()) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
New-ModuleManifest -Path "C:\Program Files\WindowsPowerShell\Modules\Greetings\Greetings.psd1" | |
-RootModule 'Greetings.psm1' | |
-Author 'John Moss' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Say-Hello() { | |
write-host Hello! -ForegroundColour green | |
} | |
function Say-Goodbye() { | |
write-host Goodbye! -ForegroundColour red | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
do { | |
write-host Installing powershell 4.0... -ForegroundColor Gray | |
start-sleep -s 10 | |
} while ((get-process | where { $_.ProcessName -eq "wusa" }) -ne $Null) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} |