Copy Logs

This is my new script which wrote to copy logs to a shared location. We recently started to upgrade user devices and some failed.

To make it easy for helpdesk, i created this script they can run after failure so i could get what happened with upgrade.

 

<#
.Synopsis
   Copy sccm logs from your computer and save it a shared location
.DESCRIPTION
   This script help you copy logs when TS or any pacakge installation fails. 
   you can copy different logs like 'smsts.log','policyagent.log' ... etc just mentiong the log name
.EXAMPLE
   .\Copy_log_V2  get-log -log smsts.log 
.EXAMPLE
   .\Copy_log_V2  
   get-log -log smsts.log 

.EXAMPLE
    .\Copy_log_V2 
     get-log -log smsts.log -path c:\windows\ccm\logs -destination \\server-path\logfolder

.CREATOR
   By Hashmat Mohammadi
.VERSION
   1.0
#>
function get-log
{
    [CmdletBinding()]
    [Alias()]
    [OutputType([int])]
    Param
    (
        # Param1 help description
        [Parameter(Mandatory=$true,
                   ValueFromPipelineByPropertyName=$true,
                   Position=0)]

        [string]$log = 'smsts*.log',
        [string]$destination = '\\server.domain.local\osd\Logs\',
        [string]$path = 'c:\windows\ccm\logs',
        [string]$computername = $env:computername
      
    )

    Begin
    {
        #get default Policy
        $policy = Get-ExecutionPolicy
        #chagne execution policy to remotesidned
        Set-ExecutionPolicy bypass -Force

        #create colder on destination
        $folder = New-Item -path $destination -name $computername -ItemType directory -Force
    }
    Process
    {
        #Copy the logs to the Destination folder
        copy-item -Path $path\$log -destination $folder -Recurse

         
    }
    End
    {
        #set policy to default policy 
         Set-ExecutionPolicy $policy -Force
    }
}

 

Exit mobile version