@@ -368,86 +368,6 @@ Function Test-rsManaged {
368368 }
369369}
370370
371- Function Update-rsKnownHostsFile {
372- $sshPaths = @ (" C:\Program Files (x86)\Git\.ssh" , " C:\Windows\SysWOW64\config\systemprofile\.ssh" , " C:\Windows\System32\config\systemprofile\.ssh" )
373- foreach ($sshPath in $sshPaths ) {
374- if (! (Test-Path - Path $sshPath )) {
375- try {
376- New-Item - Path $sshPath - ItemType container
377- }
378- catch {
379- Write-EventLog - LogName DevOps - Source BasePrep - EntryType Error - EventId 1002 - Message " Failed to create directory $sshPath `n $ ( $_.Execption.Message ) "
380- }
381- }
382- New-Item $ ($sshPath , " known_hosts" -join ' \' ) - ItemType File - Force
383- Add-Content $ ($sshPath , " known_hosts" -join ' \' ) - Value " github.com,192.30.252.129 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ=="
384- Add-Content $ ($sshPath , " known_hosts" -join ' \' ) - Value " 192.30.252.128 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ=="
385- Add-Content $ ($sshPath , " known_hosts" -join ' \' ) - Value " 192.30.252.131 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ=="
386- Add-Content $ ($sshPath , " known_hosts" -join ' \' ) - Value " 192.30.252.130 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ=="
387- }
388- }
389-
390- Function New-rsSSHKey {
391- if ((Get-rsRole - Value $env: COMPUTERNAME ) -eq " Pull" ) {
392- Start-Service Browser
393- if (Test-Path - Path " C:\Program Files (x86)\Git\.ssh\id_rsa*" ) {
394- Remove-Item " C:\Program Files (x86)\Git\.ssh\id_rsa*"
395- }
396- Write-EventLog - LogName DevOps - Source rsCommon - EntryType Information - EventId 1000 - Message " Generating ssh Key"
397- try {
398- Start - Wait - NoNewWindow " C:\Program Files (x86)\Git\bin\ssh-keygen.exe" - ArgumentList " -t rsa -f 'C:\Program Files (x86)\Git\.ssh\id_rsa' -P """" "
399- }
400- catch {
401- Write-EventLog - LogName DevOps - Source rsCommon - EntryType Error - EventId 1002 - Message " Failed to generate SSH Key `n $ ( $_.Exception.Message ) "
402- }
403- Stop-Service Browser
404- }
405- return
406- }
407-
408- Function Push-rsSSHKey {
409- if ((Get-rsRole - Value $env: COMPUTERNAME ) -eq " pull" ) {
410- start-service Browser
411- $keys = Invoke-rsRestMethod - Uri " https://api.github.com/user/keys" - Headers @ {" Authorization" = " token $ ( $d.git_Oauthtoken ) " } - ContentType application/ json - Method GET
412- $pullKeys = $keys | ? title -eq $ ($d.rs_DDI , " _" , $env: COMPUTERNAME -join ' ' )
413- if ((($pullKeys ).id).count -gt 0 ) {
414- foreach ($pullKey in $pullKeys ) {
415- Invoke-rsRestMethod - Uri $ (" https://api.github.com/user/keys" , $pullKey.id -join ' /' ) - Headers @ {" Authorization" = " token $ ( $d.git_Oauthtoken ) " } - ContentType application/ json - Method DELETE
416- }
417- }
418- $sshKey = Get-Content - Path " C:\Program Files (x86)\Git\.ssh\id_rsa.pub"
419- $json = @ {" title" = " $ ( $d.rs_DDI , " _" , $env: COMPUTERNAME -join ' ' ) " ; " key" = " $sshKey " } | ConvertTo-Json
420- Invoke-rsRestMethod - Uri " https://api.github.com/user/keys" - Headers @ {" Authorization" = " token $ ( $d.git_Oauthtoken ) " } - Body $json - ContentType application/ json - Method POST
421- Stop-Service Browser
422- }
423- return
424- }
425-
426- Function Install-rsCertificates {
427- if (! (Test-Path - Path $ (" C:\DevOps" , $d.mR , " Certificates" -join ' \' ))) {
428- New-Item $ (" C:\DevOps" , $d.mR , " Certificates" -join ' \' ) - ItemType Container
429- }
430- if ((Get-rsRole - Value $env: COMPUTERNAME ) -eq " Pull" ) {
431- Start-Service Browser
432- Start - Wait " C:\Program Files (x86)\Git\bin\git.exe" - ArgumentList " pull origin $ ( $d.branch_rsConfigs ) "
433- Remove-Item - Path $ (" C:\DevOps" , $d.mR , " Certificates\id_rsa*" -join ' \' ) - Force
434- Write-Log - value " Installing Certificate"
435- Copy-Item - Path " C:\Program Files (x86)\Git\.ssh\id_rsa" - Destination $ (" C:\DevOps" , $d.mR , " Certificates\id_rsa.txt" -join ' \' ) - Force
436- Copy-Item - Path " C:\Program Files (x86)\Git\.ssh\id_rsa.pub" - Destination $ (" C:\DevOps" , $d.mR , " Certificates\id_rsa.pub" -join ' \' ) - Force
437- chdir $ (" C:\DevOps" , $d.mR -join ' \' )
438- Start - Wait " C:\Program Files (x86)\Git\bin\git.exe" - ArgumentList " add $ ( " C:\DevOps" , $d.mR , " Certificates\id_rsa.txt" -join ' \' ) "
439- Start - Wait " C:\Program Files (x86)\Git\bin\git.exe" - ArgumentList " add $ ( " C:\DevOps" , $d.mR , " Certificates\id_rsa.pub" -join ' \' ) "
440- Start - Wait " C:\Program Files (x86)\Git\bin\git.exe" - ArgumentList " commit -a -m `" pushing ssh keys`" "
441- Start - Wait " C:\Program Files (x86)\Git\bin\git.exe" - ArgumentList " push origin $ ( $d.branch_rsConfigs ) "
442- Stop-Service Browser
443- }
444- if ((Get-rsRole - Value $env: COMPUTERNAME ) -ne " Pull" ) {
445- Copy-Item - Path $ (" C:\DevOps" , $d.mR , " Certificates\id_rsa.txt" -join ' \' ) - Destination ' C:\Program Files (x86)\Git\.ssh\id_rsa'
446- Copy-Item - Path $ (" C:\DevOps" , $d.mR , " Certificates\id_rsa.pub" -join ' \' ) - Destination ' C:\Program Files (x86)\Git\.ssh\id_rsa.pub'
447- powershell.exe certutil - addstore -f root $ (" C:\DevOps" , $d.mR , " Certificates\PullServer.crt" -join ' \' )
448- }
449- }
450-
451371Function Update-rsGitConfig {
452372 param (
453373 [string ][ValidateSet (' global' , ' system' )]$scope = ' system' ,
@@ -542,4 +462,19 @@ Function Set-rsHash
542462 [String ] $hash
543463 )
544464 Set-Content - Path $hash - Value (Get-FileHash - Path $file | ConvertTo-Csv )
465+ }
466+ Function Invoke-DSC
467+ {
468+ do {
469+ Write-EventLog - LogName DevOps - Source rsCommon - EntryType Information - EventId 1000 - Message " Installing DSC $ ( " C:\DevOps" , $d.mR , " rsPullServer.ps1" -join ' \' ) "
470+ taskkill / F / IM WmiPrvSE.exe
471+ try {
472+ $rstime = Measure-Command {Invoke-Expression $ (' C:\DevOps' , $d.mR , ' rsPullServer.ps1' -join ' \' )}
473+ }
474+ catch {
475+ Write-EventLog - LogName DevOps - Source rsCommon - EntryType Error - EventId 1002 - Message " Error in rsPullServer`n $ ( $_.Exception.message ) "
476+ }
477+ }
478+ while (! (Test-Path - Path " C:\Windows\System32\Configuration\Current.mof" ))
479+ Write-EventLog - LogName DevOps - Source rsCommon - EntryType Information - EventId 1000 - Message " PullServer DSC installation completed in $ ( $rstime.TotalSeconds ) seconds"
545480}
0 commit comments