locked
Thaught on copy-item, deployment RRS feed

  • Question

  • Hi everyone,

    I deploy software with SCCM but i need to give servers an configuration file based on network.

    So i've made a script. At first i would use Invoke-command but that gave a Kerberos HOP and i got an access denied. Now there are a lot of solutions i've tried but i keep on getting the Access denied error.

    Then i solved it this way:

    $servers = (get-content d:\temp\servers.txt)              
    
    #DMZ
    $network1 = "ip1"
    $network1Path = '\\server1\Software\Deploy\App\network1\'
    $network2 = "ip2"
    $network2Path = '\\server1\Software\Deploy\App\network2\'
    $network3 =  "ip3"
    $network3Path = '\\server1\Software\Deploy\App\network3\'
    $network4 = "ip4"
    $network4Path = '\\server1\Software\Deploy\App\network4\'
    $file1  = 'deploymentclient.conf'
    $file2 = 'outputs.conf'
    
    
         foreach ($server in $servers) {
                 $destinationPath= '\\'+$server+'\c$\Program Files\App\etc\system\local'
                 $gateway = (Get-wmiObject Win32_networkAdapterConfiguration -cn $server | Where-Object { $_.DefaultIPGateway -ne $null }).DefaultIPGateway   
                 $IPByte = $gateway.Split(".")
                 $Networkid = ($IPByte[0]+"."+$IPByte[1]+"."+$IPByte[2]) 
                 $Networkid
                
                #Vaak is het zo dat er een vertraging optreed
             
               switch ($Networkid) {
                   {$Networkid -eq $network1}
                         
                         {
                            $server
                            copy-item -Path $network1Path$file1  -Destination $destinationPath -force -Recurse
                            copy-item -Path $network1Path$file2  -Destination $destinationPath -force -Recurse
                            Get-Service -Name appservice  -ComputerName $server | Stop-Service
                            #Timeout on service
                            Start-Sleep -s 30
                            Get-Service -Name appservice  -ComputerName $server | Start-Service
                         }
                    {$Networkid -eq $network2}
                        {
                            $server
                           copy-item -Path $network2Path$file1  -Destination $destinationPath -force -Recurse
                            copy-item -Path $network2Path$file2  -Destination $destinationPath -force -Recurse
                            Get-Service -Name appservice  -ComputerName $server | Stop-Service
                            #Timeout on service
                            Start-Sleep -s 30
                            Get-Service -Name appservice  -ComputerName $server | Start-Service
                        }
                   {$Networkid -eq $network3} 
                        {
                            $server
                            copy-item -Path $network3Path$file1  -Destination $destinationPath -force -Recurse
                            copy-item -Path $network3Path$file2  -Destination $destinationPath -force -Recurse
                            Get-Service -Name appservice  -ComputerName $server | Stop-Service
                            #Timeout on service
                            Start-Sleep -s 30
                            Get-Service -Name appservice  -ComputerName $server | Start-Service
                        }
                   {$Networkid -eq $network4} 
                        {
                            $server
                            copy-item -Path $network4Path$file1  -Destination $destinationPath -force -Recurse
                            copy-item -Path $network4Path$file2  -Destination $destinationPath -force -Recurse
                            Get-Service -Name appservice  -ComputerName $server | Stop-Service
                            #Timeout on service
                            Start-Sleep -s 30
                            Get-Service -Name appservice  -ComputerName $server | Start-Service
                       }
                }
                                       
                   
            } 

     

    This works great and i bypass the hop. But are there any other was to get the copy-item done?

    Kind regards,

    André Borgeld

    Wednesday, September 6, 2017 9:48 AM

All replies

  • Hi everyone,

    I deploy software with SCCM but i need to give servers an configuration file based on network.

    So i've made a script. At first i would use Invoke-command but that gave a Kerberos HOP and i got an access denied. Now there are a lot of solutions i've tried but i keep on getting the Access denied error.

    Then i solved it this way:

    $servers = (get-content d:\temp\servers.txt)              
    
    #DMZ
    $network1 = "ip1"
    $network1Path = '\\server1\Software\Deploy\App\network1\'
    $network2 = "ip2"
    $network2Path = '\\server1\Software\Deploy\App\network2\'
    $network3 =  "ip3"
    $network3Path = '\\server1\Software\Deploy\App\network3\'
    $network4 = "ip4"
    $network4Path = '\\server1\Software\Deploy\App\network4\'
    $file1  = 'deploymentclient.conf'
    $file2 = 'outputs.conf'
    
    
         foreach ($server in $servers) {
                 $destinationPath= '\\'+$server+'\c$\Program Files\App\etc\system\local'
                 $gateway = (Get-wmiObject Win32_networkAdapterConfiguration -cn $server | Where-Object { $_.DefaultIPGateway -ne $null }).DefaultIPGateway   
                 $IPByte = $gateway.Split(".")
                 $Networkid = ($IPByte[0]+"."+$IPByte[1]+"."+$IPByte[2]) 
                 $Networkid
                
                #Vaak is het zo dat er een vertraging optreed
             
               switch ($Networkid) {
                   {$Networkid -eq $network1}
                         
                         {
                            $server
                            copy-item -Path $network1Path$file1  -Destination $destinationPath -force -Recurse
                            copy-item -Path $network1Path$file2  -Destination $destinationPath -force -Recurse
                            Get-Service -Name appservice  -ComputerName $server | Stop-Service
                            #Timeout on service
                            Start-Sleep -s 30
                            Get-Service -Name appservice  -ComputerName $server | Start-Service
                         }
                    {$Networkid -eq $network2}
                        {
                            $server
                           copy-item -Path $network2Path$file1  -Destination $destinationPath -force -Recurse
                            copy-item -Path $network2Path$file2  -Destination $destinationPath -force -Recurse
                            Get-Service -Name appservice  -ComputerName $server | Stop-Service
                            #Timeout on service
                            Start-Sleep -s 30
                            Get-Service -Name appservice  -ComputerName $server | Start-Service
                        }
                   {$Networkid -eq $network3} 
                        {
                            $server
                            copy-item -Path $network3Path$file1  -Destination $destinationPath -force -Recurse
                            copy-item -Path $network3Path$file2  -Destination $destinationPath -force -Recurse
                            Get-Service -Name appservice  -ComputerName $server | Stop-Service
                            #Timeout on service
                            Start-Sleep -s 30
                            Get-Service -Name appservice  -ComputerName $server | Start-Service
                        }
                   {$Networkid -eq $network4} 
                        {
                            $server
                            copy-item -Path $network4Path$file1  -Destination $destinationPath -force -Recurse
                            copy-item -Path $network4Path$file2  -Destination $destinationPath -force -Recurse
                            Get-Service -Name appservice  -ComputerName $server | Stop-Service
                            #Timeout on service
                            Start-Sleep -s 30
                            Get-Service -Name appservice  -ComputerName $server | Start-Service
                       }
                }
                                       
                   
            } 

     

    This works great and i bypass the hop. But are there any other was to get the copy-item done?

    Kind regards,

    André Borgeld

    • Merged by jrv Wednesday, September 6, 2017 1:55 PM duplicate
    Wednesday, September 6, 2017 9:47 AM
  • Duplicate post

    https://social.technet.microsoft.com/Forums/windowsserver/en-US/935e8b0c-8320-4933-bb98-d983d287f857/thaught-on-copyitem-deployment?forum=winserverpowershell


    If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful. (99,108,97,121,109,97,110,50,64,110,121,99,97,112,46,114,114,46,99,111,109|%{[char]$_})-join''

    Wednesday, September 6, 2017 11:39 AM