Blogs

Uninstall windows update based on given date

Windows update removal during the test phase became hectic for Administrator. each update needs to be removed manually and it is time consuming.

This script will remove the update based on the specified date where windows update is installed.

$update = new-object -ComObject Microsoft.update.Session

$Collection = New-Object -ComObject Microsoft.Update.UpdateColl

$Searcher = $update.CreateUpdateSearcher()

$Installer = $Session.CreateUpdateInstaller()

$pending = $Searcher.Search("IsInstalled=1")

foreach($entry in $pending.Updates)

$installeddate= $entry.LastDeploymentChangeTime 

   $installeddate= $installeddate.ToShortDateString()

    if ($installeddate -eq "7/10/2017" ) {  

    $Kb="KB",""

  $B= $Kb -join $entry.KBArticleIDs

   #$a+=$entry.KBArticleIDs

    $TitlePattern=$B

    $Searcher.QueryHistory(0, $Searcher.GetTotalHistoryCount()) |

    Where-Object { $_.Title -match $TitlePattern } |

    ForEach-Object {

        Write-Verbose "Found update history entry $($_.Title)"

        $SearchResult = $Searcher.Search("UpdateID='$($_.UpdateIdentity.UpdateID)' and RevisionNumber=$($_.UpdateIdentity.RevisionNumber)")

        Write-Verbose "Found $($SearchResult.Updates.Count) update entries"

        if ($SearchResult.Updates.Count -gt 0) {

            $Installer.Updates = $SearchResult.Updates

            $Installer.Uninstall()

            $Installer | Select-Object -Property ResultCode, RebootRequired, Exception

                    }

    }   

    }

}


Be the first to comment

Trouble shooting the Application Catalog

Trouble shooting the Application Catalog

Issue Identification: http://<sccm servername>/CMApplicationCatalog is not displaying the Catalog Content

Site Roles involved: Application catalog web service point and application catalog website point

Site Status Critical: Application Catalog website point

Component Status Critical: SMS_PORTALWEB_CONTROL_MANAGER

Error Found: http://localhost/CMApplicationCatalog/default.aspx is displaying error in default website in SCCM Server

Log files: smsportalwebsetup.log

XHF96C.jpeg 


Solutions which didn’t work 

       Reference from internet:

Browse to the Windows\Microsoft.NET\Framework\v4.0.30319 folder DOS.

Run the following command:

aspnet_regiis.exe -i

HdqrzS.jpeg 

After that restarted the sccm services but still component in critical state and log shows the same error

Note: Latest one dot net version should be used for the above command ( ex: 4.0 in my case)

So reference from internet didn’t helped here

       Removing the role application catalog website point(which is critical in site status)  and readding the role also didn’t help

 

Solution did worked 

So thought of doing the manual installation with all parameters to track the error in GUI Mode

Command line used is d:\Program Files\Microsoft Configuration Manager\bin\x64\portlweb.msi

PORTALNAME="CMApplicationCatalog" SMSSSLSTATE=0 PORTALLANGPACKFLAGS=0

PORTALLANGPACKFOLDER="d:\Program Files\Microsoft Configuration Manager\bin\x64\catalog\"

PORTALPATH="d:\Program Files\SMS_CCM" PORTALLOGMAXSIZE=8000000 

Yg24tp.jpeg

vA1Krh.jpeg

0LzLcn.jpeg

After this checked the url http://localhost/CMApplicationCatalog/default.aspx in SCCM Server , I can see it loads the application catalog web page but no application were listed with permission error info.

One main thing is Patience. Log will display as installation was successful but if you look at the task manager still rolesetup.exe is still running. Once rolesetup.exe is exit from task manager we can check the url again

Bingo it starts working now

gMut9l.jpeg 

Be the first to comment

Check Machines in SCCM not in AD

Get all the computer in SCCM put them in a variable do a for each and ask AD if the computer is found and active. If not delete it form SCCM.

import-module ActiveDirectory

Import-Module $env:SMS_ADMIN_UI_PATH.Replace(“\bin\i386″,”\bin\configurationmanager.psd1”)
$computers = (get-cmdevice).name
foreach ($computer in $computers)
{
try
{
Get-ADComputer -Identity $computer -ErrorAction Stop >$null
}
catch
{
write-host “$computer is not in AD”
}

}

Be the first to comment

How to Re-run a failed deployment on multiple machines(SCCM)

Prerequisites:

  1. Sccm Client Center

  2. Deployment id , package id ,program

  3. Windows PowerShell(by default)

  4. List of machines.

When there is a scenario where 15 percentages of machines where applications failed due to run time exceed error. The application uninstalled the older version but it doesn’t install the latest versions and throw error as Run time exceed even though the maximum Run time was extended to 45 mins.

The 15 percentage is almost 800 machines but rest of the machines was able to receive and get the application deployed successfully.

While the deployment\advertisement was re-run via sccm client center, the application was successfully deployed. Hence planned to automate the re-run task for 800 machines and it works like a charm

Solutions:

Hope most of us have seen the dll file in SCCM Client Center folder which is core for this application.

Powershell has the capability of working with dll files.

Sou61p.png

Script:

Add-Type -Path 'C:\SCCM Client Center\smsclictr.automation.DLL'

$strcomp=Get-Content "C:\computers.txt"

$strcomp | where{test-connection $_ -quiet -count 1} |ForEach-Object{

 $ReRun = New-Object -TypeName smsclictr.automation.SMSClient($_)

 $ReRun.SoftwareDistribution.RerunAdv("<Deploymentid>", "<PackageID>", "<PROGRAMNAME>")

 }

 

Exceptions:

This script will fail to execute on below scenarios

  1. WMI Corrupted

  2. Access denied on target machines

  3. RPC issues

  4. When deployment is not targeted

Be the first to comment

Quote for the day in Email Signature

Automating the outlook signature involves many things by gathering information from AD, environmental variable and so on.

We have seen people using inspirational quotes in bottom of their signature and periodically they change the quotes. How about every day new quote in their signature that too automated.

This blog is about the automation of quotes in to signature.

I am getting quotes from http://www.eduro.com/ Thanks to Eduro


$AppData=$env:appdata

$SigPath = '\Microsoft\Signatures'

$LocalSignaturePath = $AppData+$SigPath

 

Signature information will be available in C:\Users\<username> \AppData\Roaming\Microsoft\Signatures

if (!(Test-path "$LocalSignaturePath\signaturecustom.txt")){

@"

First and Last Name

Title | Group

CompanyName| Direct phone | Mobile phone | firstname.lastname@company.com 

"@ | out-file "$LocalSignaturePath\signaturecustom.txt"

 

}

 

It will create a text file in the C:\Users\<username> \AppData\Roaming\Microsoft\Signatures\signaturecustom.txt for the first time

This file needs to be changed as per user data.

Here comes the web scrapping

$url = "http://www.eduro.com/"

$r1= Invoke-WebRequest -Uri $url

$r4=@{}

$r2=($r1.ParsedHtml.getElementsByTagName('p') )[0]

$r4[1]=$r2.innerText

$r3=($r1.ParsedHtml.getElementsByTagName('p') )[1]

$r4[0]=$r3.innerText

 

 uJX2Mp.jpeg

 

N9edXw.jpeg 

Note: signaturecustom.txt text needs to be modified as per your signature.

Once signaturecustom template is selected from signature Ribbon Button from outlook.it will display the output like this.

At last you can schedule it in task scheduler.

Full Script.

$AppData=$env:appdata 

$SigPath = '\Microsoft\Signatures' 

$LocalSignaturePath = $AppData+$SigPath 

if (!(Test-path "$LocalSignaturePath\signaturecustom.txt")){

@"

First and Last Name

Title | Group

CompanyName| Direct phone | Mobile phone | firstname.lastname@company.com  

"@ | out-file "$LocalSignaturePath\signaturecustom.txt"


}

$url = "http://www.eduro.com/"

$r1= Invoke-WebRequest -Uri $url

$r4=@{}

$r2=($r1.ParsedHtml.getElementsByTagName('p') )[0]

$r4[1]=$r2.innerText

$r3=($r1.ParsedHtml.getElementsByTagName('p') )[1]

$r4[0]=$r3.innerText

$r4.Values 

$input= Get-content  "$LocalSignaturePath\signaturecustom.txt"

$stream = [System.IO.StreamWriter] "$LocalSignaturePath\Signaturecustom.htm"

$stream.WriteLine("<!DOCTYPE HTML PUBLIC `"-//W3C//DTD HTML 4.0 Transitional//EN`">")

$stream.WriteLine("<HTML><HEAD><TITLE>Signature</TITLE>")

$stream.WriteLine("<META http-equiv=Content-Type content=`"text/html; charset=windows-1252`">")

$stream.WriteLine("<BODY>")

$stream.WriteLine("<SPAN style=`"FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: `'Trebuchet MS`'`">")

$stream.WriteLine("<BR><BR>")

$stream.WriteLine("<B><SPAN style=`"FONT-SIZE: 9pt; COLOR: gray; FONT-FAMILY: `'Trebuchet MS`'`">" + ($input[0].ToUpper()).Substring(0,$input[0].Length) + "</SPAN></B>")

$stream.WriteLine("<SPAN style=`"FONT-SIZE: 9pt; COLOR: gray; FONT-FAMILY: `'Trebuchet MS`'`">")

$stream.WriteLine("<BR><BR>")

$input=(Get-content  "C:\Users\raviregi\Desktop\Test.txt" )| Select-Object -Skip 1

foreach( $value in  $input) {

$stream.WriteLine("<SPAN style=`"FONT-SIZE: 9pt; COLOR: gray; FONT-FAMILY: `'Trebuchet MS`'`">" + $value +"</SPAN>")

$stream.WriteLine("<BR><BR>")

}

$stream.WriteLine("<SPAN style=`"FONT-SIZE: 7pt; FONT-STYLE: 'italic';COLOR: gray; FONT-FAMILY: `'Trebuchet MS`'`">" + $r4.Values +"</SPAN>")

$stream.WriteLine("<BR>")

$stream.WriteLine("</BODY>")

$stream.WriteLine("</HTML>")

$stream.close()


Script Posted in TechNet

Be the first to comment
Showing 1 - 5 of 3113 results