OCHdev.ps1


<#PSScriptInfo
 
.VERSION 1.0.0.6
 
.GUID 1a6da1b8-1fef-45ce-8abc-5d67f65e73a1
 
.AUTHOR kristoffer@office-center.no
 
.COMPANYNAME
 
.COPYRIGHT
 
.TAGS
 
.LICENSEURI
 
.PROJECTURI
 
.ICONURI
 
.EXTERNALMODULEDEPENDENCIES
 
.REQUIREDSCRIPTS
 
.EXTERNALSCRIPTDEPENDENCIES
 
.RELEASENOTES
 
 
#>
 

<#
.DESCRIPTION
Base PowerShell config for Office Center employees. Installs handy PowerShell tools, particularly for MSPs (but also others).
#>
 

Param()
# Base config for utviklere hos Office-Center med en del standardoppsett, og installerer ofte brukte moduler.

<#
### Denne delen av koden kan redigeres og oppdateres jevnlig
#>


# Standardmoduler som skal legges inn
$modules = "MSonline","AzureAD","PowerShellCookbook","AzureAutomationAuthoringToolkit","AzureRM","ImportExcel","Pester","Plaster","PsISEProjectExplorer","ISEModuleBrowserAddon"

# Standard innhold i alle profiler
$content = @"
function h50 { Get-History -Count 50 }
 
function h10 { Get-History -Count 10 }
 
function which($cmd) { (Get-Command $cmd).Definition }
 
function whoami { (get-content env:\userdomain) + "\" + (get-content env:\username ) }
"@



<#
### Denne delen av koden skal normalt ikke trenge endringer
#>

# Oppretter fellesprofil hvis den ikke eksisterer
if((test-path $PsHome\profile.ps1) -eq $false){
    New-Item -Type file -Path $PsHome\profile.ps1 -Force
    
    # Setter innholdet i filen.
    Set-Content -Path $PsHome\profile.ps1 -Value $content    
}
# Oppdaterer og installere evt. manglende moduler
 foreach ($module in $modules){
    # Tester for installerte moduler
    $m = Get-InstalledModule -Name $Module -ErrorAction SilentlyContinue
        
    # Hvis modulen er installert, oppdater den:
    if(!$m){
        Write-Warning "Installing module $module"
        Install-Module $module -AllowClobber -SkipPublisherCheck
     }
     # Hvis ikke, installer den
     else{ 
        Write-Warning "Module $module is already installed. Updating module."
        Update-Module $module -Confirm:$false
    }
}

 # Oppdaterer hjelp
 Update-Help -ErrorAction SilentlyContinue