Updates/UpdateModuleTechsGroup.ps1

#API key for PSgallery

Unlock-SecretVault -Password $Secret
$SecretAPI = Get-Secret -Name psgalleryapi -asplaintext 

#Publish newest module version to PSgallery
Publish-Module -Name Desktopsharedmod -NuGetApiKey $SecretAPI 


#Install new module for Desktop team.

$TechPCList = Import-Csv '\\cvfile01\Software\Apps\_NoAppScripts\Powershell\Scripts\TechPCList.txt'


foreach ($tech in $TechPCList.tech) {
  
  #Split Laptop and Tech name
  $PC, $User = $tech.split("-")

  $PingTest = Test-connection -Count 1 -TargetName $User

  if ($PingTest.status -eq 'Success') {

    $Sesh = New-PSSession -ComputerName $User

    Write-host "Asset $User belonging to $PC is reachable via network" -ForegroundColor Yellow


    Invoke-Command -Session $Sesh -ScriptBlock {
            
      Write-host "Updating Desktopsharedmod version on $Using:User" -ForegroundColor Yellow
      Update-module -Force  | where { $_.name -match 'DesktopSharedMod' }
      Write-host "Removing old modules from $Using:User" -ForegroundColor Yellow
      Remove-OldModules
      Write-host "Retrieving Desktopsharedmod from $Using:User" -ForegroundColor Yellow
      Get-module -ListAvailable | where { $_.name -match 'DesktopSharedMod' }

    }



  }
  else {
    Write-Host "Asset $User belonging to $PC could NOT be reached via the network" -ForegroundColor Red

  }

}



$TechTestPCList = Import-Csv '\\cvfile01\Software\Apps\_NoAppScripts\Powershell\Scripts\TechsTestMachines.txt'


foreach ($tech in $TechTestPCList.testpc) {
  
  #Split TestPC and Tech name
  $User,$PC = $tech.split("-")

  $PingTest = Test-connection -Count 1 -TargetName $PC

  if ($PingTest.status -eq 'Success') {

    $Sesh = New-PSSession -ComputerName $PC

    Write-host "Asset $PC belonging to $User is reachable via network" -ForegroundColor Yellow

    Invoke-Command -Session $Sesh -ScriptBlock {
            
      
      #Write-host "Updating Desktopsharedmod version on $Using:User" -ForegroundColor Yellow
      #Update-module -Force | where { $_.name -match 'DesktopSharedMod' }
      #Write-host "Removing old modules from $Using:User" -ForegroundColor Yellow
      #Remove-OldModules
      #Write-host "Retrieving Desktopsharedmod from $Using:User" -ForegroundColor Yellow
      Get-module -ListAvailable | where { $_.name -match 'DesktopSharedMod' }

    }



  }
  else {
    Write-Host "Asset $User belonging to $PC could NOT be reached via the network" -ForegroundColor Red

  }

}