SHARE
TWEET

Untitled

a guest Jul 18th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Install-ModuleOnServer {
  2.     <#
  3.  
  4.     #>
  5.     [CmdletBinding()]
  6.     param (
  7.         [Parameter(Mandatory)]
  8.         [string] $Server,
  9.  
  10.         [Parameter()]
  11.         [string] $Module = 'Posh365'
  12.     )
  13.     End {
  14.         $Path = "\\{0}\c$\Program Files\WindowsPowerShell\Modules" -f $Server
  15.         Write-Host "Attempting to install module here: $Path." -BackgroundColor Blue -ForegroundColor White
  16.         if (Test-Path $Path) {
  17.             $SaveSplat = @{
  18.                 Name        = $Module
  19.                 Path        = $Path
  20.                 Force       = $true
  21.                 ErrorAction = 'Stop'
  22.             }
  23.             try {
  24.                 Save-Module @SaveSplat
  25.                 Write-Host "Successfully install $Module module" -BackgroundColor Blue -ForegroundColor White
  26.                 Write-Host "Please restart PowerShell on $Server" -BackgroundColor Blue -ForegroundColor White
  27.                 Write-Host "When starting PowerShell, make sure to Run As Administrator" -BackgroundColor Blue -ForegroundColor White
  28.                 $Here = @"
  29. $gci = @{
  30.     Path    = "C:\Program Files\WindowsPowerShell\Modules\$Module"
  31.     Filter  = '*.ps1'
  32.     Recurse = $true
  33. }
  34. Get-ChildItem @gci | % {try{. $_.fullname}catch{}}
  35. "@
  36.                 Write-Host "If $Server is PowerShell 2 (common with Exchange 2010)" -BackgroundColor DarkGreen -ForegroundColor White
  37.                 Write-Host "Copy and Paste this code block in PowerShell on $Server" -BackgroundColor DarkGreen -ForegroundColor White
  38.                 Write-Host "#####################################################" -BackgroundColor DarkGreen -ForegroundColor White
  39.                 Write-Host $Here -BackgroundColor Green -ForegroundColor Black
  40.                 Write-Host "#####################################################" -BackgroundColor DarkGreen -ForegroundColor White
  41.             }
  42.             catch {
  43.                 Write-Host "Failed to install $Module module." -BackgroundColor Yellow -ForegroundColor Black
  44.             }
  45.         }
  46.         else {
  47.             Write-Host "Path $Path not found." -BackgroundColor Yellow -ForegroundColor Black
  48.             Write-Host "Unable to install $Module module." -BackgroundColor Yellow -ForegroundColor Black
  49.         }
  50.     }
  51. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top