Thursday, April 30, 2015

SCCM 2012: Powershell: Copy SCCM logs from client machine

Script to pull sccm logs from the client machine.
Need to enter the hostname/ip and local administrator password on the csv file.
Powershell version required 3.0
------------------------------------------------------
This script is provided as is and with no warranties, it's the sole responsibility of the user to ensure it is tested prior to running on prod environment. 

-----------------------------------------------------------------------------------------------


$basefolder="C:\SCCM_Troubleshooting\" #Local machine folder where logs will be copied to "machinename_log" folder
#remove space from hostname field from excel
$csvpath="C:\SCCM_Troubleshooting\hostnames.csv"

if (-not(Test-Path $csvpath))

{
write-host "Hostname file not found, please place the csv file with hostnames and passwords at $csvpath"
exit 0;
}


$list=Import-Csv -Path $csvpath

$list | ForEach-Object{


$machine=$_.Hostname;
$machine=$machine.trim();
#Write-Host $machine
#read-host "Pause"
$PWord = ConvertTo-SecureString –String $_.Password –AsPlainText -Force
$user="$machine`\administrator"

$Creds = New-Object –TypeName System.Management.Automation.PSCredential –ArgumentList $User, $PWord

New-PSDrive -Name cli2 -PSProvider FileSystem -Root \\$machine\C$ -Credential $creds


mkdir "$basefolder$machine`_logs"

Copy-Item cli2:\Windows\CCM\logs\ "$basefolder$machine`_logs" -Recurse -Verbose

remove-psdrive cli2

}













-----------------------------------------------------------------

No comments:

Post a Comment