OCHbase.ps1


<#PSScriptInfo
 
.VERSION 1.0.0.4
 
.GUID 6aff7db2-0aed-480d-950f-3d65eb46244a
 
.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 ansatte hos Office-Center med en del nyttig standardoppsett, og installerer ofte brukte moduler.
 
<#
### Denne delen av koden kan redigeres og oppdateres jevnlig
#>


# Standardmoduler som skal legges inn
$modules = "MSonline","AzureAD","PowerShellCookbook","ImportExcel"

# 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
#>



 # Oppdaterer hjelp
Update-Help -ErrorAction SilentlyContinue


# 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 "Module $module is already installed. Updating module."
        Update-Module $module -Confirm:$false
         
     }
     # Hvis ikke, installer den
     else{
        Write-Warning "Installing module $module"
        Install-Module $module -AllowClobber -Confirm:$false
    }
}