Showing posts with label SCCM 2012. Show all posts
Showing posts with label SCCM 2012. Show all posts

Wednesday, December 16, 2015

SCCM 2012:: Powershell:: Script to get the SCCM server log files and their location details and export it to an HTML report

This script will give you the list of log files for each components installed on each server on your SCCM infrastructure.

Script can be run from CAS server.

Add your CAS Servername and CAS site code to the script.

An HTML file will be generated on your desktop which shows you the log file path and link to directly open the log file from the machine from where you are running the script.

 Powershell remoting should be enabled on all servers.

The output would be similar to the below screenshot.


  
Note: This does not cover the SMSDPProv.log and smsdpusage.log

Thursday, June 18, 2015

Initiate a machine policy or user policy on the client machine/members of a collection

Very useful command which can trigger the client machine policy/user policy action. Can be triggered for a device or a collection.

Whenever I deploy an application to a set of my test machines, I would trigger this action from the SCCM powershell console which would make the deployment available quickly on the machine.

Example: 

Invoke-CMClientNotification

 

Invoke-CMClientNotification -DeviceCollectionName "CollectionName" -NotificationType RequestMachinePolicyNow -Verbose 

Refer: https://technet.microsoft.com/en-us/library/dn472965%28v=sc.20%29.aspx



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

}













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

Wednesday, April 29, 2015

Powershell: SCCM 2012 bulk package creation script

This script is intended for those who want to create multiple packages in sccm at once.
Please test the script and make necessary changes before you use it in production.
This script is provided as is and without any warranty. Author is not responsible for any damages which might be caused by running this script without making changes prior to running it.

No error handling and minimal validations done in the script.

-----------------------------------------------------------------------------
#author lanabhat@gmail.com

#This script creates packages one by one from the details given in the CSV file,also creates programs, creates the collection.


#Package creation script, will create a package from given parameters, creates programs, creates the collection


#csv file header Package_RAW.csv

#SharePath,MsiPath,PackageName,PackageDescription,Manufacturer,Version,Lang,InstallCMD,UninstalllCMD,SpaceMB,SilentInstallCMD,CollectionName #note sometimes excel removes .0 etc ex 1.0 becomes 1

#If you are using an MSi following fields are not required PackageName,PackageDescription,Manufacturer,Version,Lang


#Run the CreateCollectionNSetDeployment.ps1 once the binary replication is enabled and package is distributed to DPs.



$list=Import-Csv $env:userprofile\desktop\Package_RAW.csv


$list | foreach{

$msipath=$_.MsiPath;

$msipackage=$false;


if($msipath -ne "")

{

$msipackage=$true

}

else

{

  $msipackage=$false

}

$pkgSrvShr=$_.SharePath; #ex: "\\myshare\software\Microsoft\Visio\VisioPro2013"

$name=$_.PackageName; #"Visio 2013 Pro"

$description=$_.PackageDescription; #"Visio 2013 Pro"

$manufacturer=$_.Manufacturer; #"Microsoft"

$ver=$_.Version;  #"2013"

$lng=$_.Lang;#"English"

$installcmdline=$_.InstallCMD;#"Install.vbs"

$SilentInstallCMDline=$_.SilentInstallCMD;

$uincommandline=$_.UninstalllCMD;#"Uninstall.vbs"

$space=$_.SpaceMB;#"450"


$lmtClctn ="CAS00001"

$clctnName=$_.CollectionName;

$rfrshScd=New-CMSchedule -RecurInterval Hours -RecurCount 4


#This is the standard query used to get the machines which are part of a ARS group. ARS group is $clctnName        

$qStmt="select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System where SMS_R_System.SystemGroupName = 'DOMAIN\\"+$clctnName+"'"

    

#This is in pipeline to copy the package to server.

#Copy-Item -Path $pkgFileSrc -Destination $pkgSrvShr -Recurse



if($msipackage -eq $false) #If MsiPath is not entered in the excel, package is considered as non definition package.

{

$mypackage=New-CMPackage -Name $name -Description $description  -Language $lng -Manufacturer $manufacturer -Path $pkgSrvShr -Version $ver

}

else #below code for package from definition

{


$mypackage=New-CMPackage -FromDefinition -PackagePath $msipath -SourceFileType AlwaysObtainSourceFile -SourceFolderPath $pkgSrvShr -SourceFolderPathType UncNetworkPath -verbose


#Code below to delete the standard programs created by Msi.

$delprogs=@("Per-system attended","Per-system unattended","Per-system uninstall","Per-user attended","Per-user unattended","Per-user uninstall")

  

foreach($pro in $delprogs)

{

  $dpgm=Get-CMPackage -Id $pkgID | Get-CMProgram -ProgramName $pro

  if($dpgm -ne $null)

  {

   Remove-CMProgram -PackageId $pkgID -ProgramName $pro -force -verbose

  }

}

}


#$pkgid=CAS00098 - cisco webex 7.3.3


$pkgid=$mypackage.PackageID;


#Find out how to enable Binary differential replication




$pgm1=Get-CMPackage -Id $pkgID | Get-CMProgram -ProgramName "InstallProgram"

$pgm2=Get-CMPackage -Id $pkgID | Get-CMProgram -ProgramName "SilentInstall"

$pg3=Get-CMPackage -Id $pkgID | Get-CMProgram -ProgramName "Uninstall"


if(($pgm1 -eq $null)-and ($installcmdline -ne ""))

{

  New-CMProgram -CommandLine $cmdline -PackageId $pkgID -StandardProgramName $stdpgmname -DiskSpaceRequirement $space -DiskSpaceUnit $dunit -Duration 720 -ProgramRunType WhetherOrNotUserIsLoggedOn -RunMode RunWithAdministrativeRights -RunType Normal -UserInteraction 1 -verbose

}

if(($pgm2 -eq $null) -and ($bincommandline -ne ""))

{

  New-CMProgram -CommandLine $bincommandline -PackageId $pkgID -StandardProgramName $binstall -DiskSpaceRequirement $space -DiskSpaceUnit $dunit -Duration 720 -ProgramRunType WhetherOrNotUserIsLoggedOn -RunMode RunWithAdministrativeRights -RunType Hidden -UserInteraction 0 -verbose

}

if(($pgm3 -eq $null) -and ($uincommandline -ne ""))

{

  New-CMProgram -CommandLine $uincommandline -PackageId $pkgID -StandardProgramName $unin -DiskSpaceRequirement "Unknown" -Duration 720 -ProgramRunType WhetherOrNotUserIsLoggedOn -RunMode RunWithAdministrativeRights -RunType Normal -UserInteraction 0 -verbose

}



read-host "Please enable Binary replication and press enter to start distribution"



#syntax

#Start-CMContentDistribution -DeploymentPackageId <String[]> [-CollectionName <String> ] [-DistributionPointGroupName <String> ] [-DistributionPointName <String> ] [-Confirm] [-WhatIf] [ <CommonParameters>]


#get all DP groups and distribute package to each group

Get-CMDistributionPointGroup | %{Start-CMContentDistribution -PackageId $pkgID -DistributionPointGroupName $_.Name -verbose}


#below two servers are not part of any DP grop si distribute separately.

Start-CMContentDistribution -PackageId $pkgID -DistributionPointName "dp1.mydomain.com" -verbose

Start-CMContentDistribution -PackageId $pkgID -DistributionPointName "dp2.mydomain.com" -verbose


#Enter N or enable read-host for enabling collection creation choice. yes or no

$a="Y" #read-host "Create collection Y or N"


if($a -eq "Y")

{


#Script below for collection creation


   write-host "Creating a collection with Name: $clctnName"  

  


    $cmnt="";


    $pkg=Get-CMPackage -Id $pkgID | select Name,Version

    if($pkg -ne $null)

    {

     $cmnt=$pkg.Name+" "+$pkg.Version

    }


    #$rfrshScd=$_.RefreshSchedule; #type <IResultObject>



    $clctn=Get-CMDeviceCollection -Name $clctnName


    if($clctn -eq $null)

    {

     write-host "Collection not found, creation collection"

     New-CMDeviceCollection -LimitingCollectionId $lmtClctn -Name $clctnName -Comment $cmnt -RefreshSchedule $rfrshScd  -RefreshType Periodic -verbose

     $clctn=Get-CMDeviceCollection -Name $clctnName

     Add-CMDeviceCollectionQueryMembershipRule -Collection $clctn -QueryExpression $qStmt -RuleName $clctn.Name -verbose

     #move to the self service folder

     Move-CMObject -FolderPath "CAS:\DeviceCollection\_Software Deployment Collections\" -InputObject $clctn -verbose

     write-host "Collection created and moved to self services folder"

    }

    else

    {

     write-host "Collection already exists, not created again"

    }

} #end of collection creation Y

else #If user selects N for collection creation.

{

  "No collection created"

}

}
























































































































































-----------------------------------------------
email: lanabhat@gmail.com
Phone: 9743289373
Please provide your suggestions and also feel free to ask your queries.
-----------------------------------------------