Showing posts with label scripting. Show all posts
Showing posts with label scripting. Show all posts

Tuesday, October 22, 2013

Export the task sequence SCCM 2012 to XML format (legacy format of sccm 2007)

Export the task sequence SCCM 2012 to XML format (legacy format of sccm 2007)

SCCM 2012 task sequences can be exported in .zip format and when we handle/extract it will not work.

Below is only applicable from sccm 2012 SP1 and above

With help of Power shell we can extract this in XML format. 
 
Import-Module "C:Program Files (x86)Microsoft Configuration ManagerAdminConsolebinConfigurationManager.psd1"
(Get-CMTaskSequence | Where-Object {$_.Name -eq "TEST_TS"}).Sequence | Out-File c:tempTSsequence.txt


For Importing
 
param (
[string]$SiteCode,
[string]$TaskSequenceName,
[string]$InputFile
)
#########
# What does it do?
# Script imports a previously "exported" TaskSequence from CM12 to CM12
#
# Howto: Extract the TaskSequence with the following command:
# (Get-CMTaskSequence | where-object {$_.Name -eq $NameOfTaskSequence}).Sequence | Out-File $PathToExportFile
# This will be your $InputFile
#
# Author: David O'Brien, david.obrien@sepago.de
# Created: 28.09.2012
# Prerequisites:
#               - Microsoft System Center Configuration Manager 2012 SP1 (beta)
#               - ConfigMgr Powershell to get your existing TaskSequence
#
#########
$Class = "SMS_TaskSequencePackage"
$Instance = $null
$TS = $null
$NewSequence = $null
$TS = [wmiclass]"\.rootsmssite_$($SiteCode):$($Class)"
$Instance = $TS.CreateInstance()
$SequenceFile = Get-Content $InputFile
$NewSequence = $Ts.ImportSequence($SequenceFile).TaskSequence
$Instance.Name = "$TaskSequenceName"
$NewTSPackageID = $TS.SetSequence($Instance, $NewSequence).SavedTaskSequencePackagePath



Tuesday, March 26, 2013

Delete all packages from Distrubution Point


Did you get ever a situation to delete all the Packages from one Specific DP ?

There are few tools/Scripts are available

-          ConfigMgr 2007 Distribution Point Package Utility


-          Vbscript I like this tool as it is very quick


'Rslaten 03/2005
'http://blogs.msdn.com/b/rslaten/archive/2006/03/01/removing-a-retired-dp-from-all-your-packages.aspx
On Error Resume Next

WScript.Echo ""
WScript.Echo "SMSDPClean v1.3"
WScript.Echo "Usage: cscript.exe SMSDPClean "
WScript.Echo "Example: cscript.exe SMSDPClean.vbs myCentralSiteServer myDistributionPoint"
WScript.Echo ""

Dim SMSSiteServer, SMSNameSpace, oLocator, oServices, bDone

'Get Args, add error checking here if needed
SMSSiteServer = WScript.Arguments(0)
DP = WScript.Arguments(1)

'Get SMS namespace
SMSNameSpace = GetSMSNameSpace(SMSSiteServer)

'Connect to SMS namespace
Set oLocator = CreateObject("WbemScripting.SWbemLocator")
Set oServices = oLocator.ConnectServer(SMSSiteServer, SMSNameSpace,,,,,128)
If Err.number <> 0 Then
WScript.Echo "Error connecting to " &SMSNameSpace& " on " &SMSSiteServer& ": " &Err.Number
Set oLocator = Nothing
Set oServices = Nothing
WScript.Quit
End If

'Call main procedure
PackageLoop

'Loop until async task is done
Do While not bDone
WScript.Sleep 1000
Loop

Set oLocator = Nothing
Set oServices = Nothing
WScript.Quit


'Functions
'''''''''''''''''''''''''''''''''''''''''
'
'GetSMSNameSpace Function
'
'''''''''''''''''''''''''''''''''''''''''

Function GetSMSNameSpace(SiteServer)
On Error Resume Next
Dim
colNameSpaceQuery, refitem, refWMI
Set refWMI = GetObject("winMgmts:\\" &SiteServer&"\root\sms")
If Err.number <> 0 Then
WScript.Echo "Error connecting to SMS namespace on " &SiteServer
WScript.Quit
End If
Set
colNameSpaceQuery = refWMI.ExecQuery("select * from SMS_ProviderLocation")
For Each refitem in colNameSpaceQuery
GetSMSNameSpace = refitem.NamespacePath
Next
Set colNameSpaceQuery = Nothing
Set refitem = Nothing
Set refWMI = Nothing
End Function

'''''''''''''''''''''''''''''''''''''''''
'
'ValidDP Function
'
'''''''''''''''''''''''''''''''''''''''''

Function ValidDP(DP, SiteCode)
On Error Resume Next
Dim
SysRes, start, finish, tempDP
ValidDP = False
Set SysRes = oServices.ExecQuery("select * from sms_sci_sysresuse where SiteCode = '" &SiteCode& "'")
For each res in SysRes
start = InStr(res.NALPath,"=\\") + 3
finish = InStr(res.NALPath,"]MSWNET") - 2
tempDP = mid(res.NALPath,start,finish-start)
If (UCase(tempDP) = UCase(DP)) and (res.RoleName = "SMS Distribution Point") Then
Set SysRes = Nothing
ValidDP = True
Exit Function
End If
Next

Set SysRes = Nothing
End Function

'''''''''''''''''''''''''''''''''''''''''
'
'PackageLoop SubRoutine
'
'''''''''''''''''''''''''''''''''''''''''

Sub PackageLoop
On Error Resume Next
Dim
sinkcol, retValuecol
bDone = False
Set sinkcol = wscript.CreateObject("WbemScripting.SWbemSink","SINKCOL_")
retValuecol = oServices.ExecQueryAsync(sinkcol,"SELECT * FROM SMS_DistributionPoint")
If Err.Number <> 0 Then
WScript.Echo "Error running query:" &err.description
WScript.Quit
End If
End Sub
Sub
SINKCOL_OnObjectReady(objDP, objAsyncContext)
On Error Resume Next
Dim
start, finish, tempDP
start = InStr(objDP.ServerNALPath,"=\\") + 3
finish = InStr(objDP.ServerNALPath,"]MSWNET") - 2
tempDP = mid(objDP.ServerNALPath,start,finish-start)
If UCase(tempDP) = UCase(DP) Then
WScript.Echo "Found " &DP& " on "& objDP.SiteCode& " linked to package " &objDP.PackageID
If ValidDP(DP, objDP.SiteCode) Then
WScript.Echo "Validated " &DP& " for site " &objDP.SiteCode
objDP.Delete_()
If Err.number <> 0 Then
WScript.Echo "Failed to delete " &DP& " from package " &objDP.PackageID& " on site " &objDP.SiteCode
WScript.Echo "Error = " &Err.number& " - " &Err.Description
Else
WScript.Echo "Successfully deleted " &DP& " from package " &objDP.PackageID& " on site " &objDP.SiteCode
End If
Else

WScript.Echo DP& " is not specified as a distribution point on site " &objDP.SiteCode
End If
End If
End Sub
Sub
SINKCOL_OnCompleted(iHResult, objErrorObject, objAsyncContext)
bDone = True
End Sub

Monday, March 11, 2013

PowerShell script to check WDS Service status against of List of servers.

Below is a PowerShell script, this will list WDS Service status against of List of servers.

Below is a powershell script will list WDS Service status againest of List of servers.

$InPutComputersList = get-content "c:\MyScripts\list.txt"
$OutPutFile = "c:\MyScripts\WDS_ServiceStatus.csv"
$NotReachble = "c:\MyScripts\NonPingSystems.csv"
$listResult = @()
foreach($ForEverComputerIntheTextFilelinebyLine in $InPutComputersList) {
if (test-path \$ForEverComputerIntheTextFilelinebyLine\c$\windows\write.exe)
{
$objService = Get-Service WDSServer -ComputerName $ForEverComputerIntheTextFilelinebyLine | select machinename, status, name, displayname

$objResult = New-Object PSObject -Property @{
ComputerName = $ForEverComputerIntheTextFilelinebyLine
ServiceStatus = $objService.Status
ServiceDisplayName = $objService.DisplayName
ServiceName = $objService.Name

}
$listResult += $objResult
}
Else
{
Write-Output "$ForEverComputerIntheTextFilelinebyLine,NotReachable" | out-file $NotReachble -append
}
}
$listResult| Export-Csv -Path $OutPutFile