Run 64-bit PowerShell via SCCM 2007 Advertisement

A colleague came across a problem today. He could run a SCDPM PowerShell script from PowerShell console successfully but could not run it when packaged it in SCCM. We soon found out it’s because SCCM 2007 is a 32-bit app and DPM PowerShell snapin is only available for 64-bit PowerShell because we could not run the script from a 32-bit PowerShell console. When a 32-bit application tries to access %WinDir%\system32, Windows redirects it to %WinDir%\SysWOW64. In order for the 32-bit app to access %WinDir%\System32 folder, we have to use %Windir%\sysnative. So, we set the command line of the program in

Continue reading

Powershell Function: Get-AllDomains (in a forest)

I wrote this Powershell function today as part of a script I’m working on. It is to get a list of Active Directory domains within an Active Directory forest using ADSI: [sourcecode language=”Powershell”] Function Get-AllDomains { $Root = [ADSI]"LDAP://RootDSE" $oForestConfig = $Root.Get("configurationNamingContext") $oSearchRoot = [ADSI]("LDAP://CN=Partitions," + $oForestConfig) $AdSearcher = [adsisearcher]"(&(objectcategory=crossref)(netbiosname=*))" $AdSearcher.SearchRoot = $oSearchRoot $domains = $AdSearcher.FindAll() return $domains } [/sourcecode] I don’t have any child domains in my test environment, but if you run this on a domain member computer, it will list all child domains as well as the parent forest domain (I’ve tested in the production environment).

Continue reading

SCCM Health Check PowerShell Script Updated to Version 3.3

I have updated the SCCM Health Check Script again. The latest version is now 3.3. Below is what’s been updated since my last post for version 3.1: Fixed the bug where when using DOTNET sending emails to multiple recipients, it only sends to the first recipient from the list. It now zip the txt attachment to zip file before sending it. this is to improve the performance and avoid sending large attachments. Added functionality to check all current active package distribution Able to create exemptions for DNS suffix check. This can be configured in the XML. (this is required at

Continue reading

PowerShell Script to locate SCCM objects in SCCM console

There are many object types in SCCM that supports folders in the console. Even though the object can be easily located using the search function, often we need to find out which folder does a particular object (i.e. package, advertisement, etc) reside.  At work, we use folders to separate objects for different business units and differnet IT service providers. Therefore, there are many times I need to find out where exactly is the object located. I wrote this script today called Locate-SCCMObject.PS1 Syntax: .\Locate-SCCMObject <SCCM Central Site Server> <SCCM Object ID>: Example: Using the script: From SCCM Console: The output

Continue reading

PowerShell Functions: Get IPV4 Network Start and End Address

I wrote 2 PowerShell functions today: Get-IPV4NetworkStartIP and Get-IPV4NetworkEndIP. Input: Network IP address in CIDR notation Format Output: The start or end IP (System.Net.IPAddress object). Get-IPV4NetworkStartIP: [sourcecode language=”Powershell”] Function Get-IPV4NetworkStartIP ($strNetwork) { $StrNetworkAddress = ($strNetwork.split("/"))[0] $NetworkIP = ([System.Net.IPAddress]$StrNetworkAddress).GetAddressBytes() [Array]::Reverse($NetworkIP) $NetworkIP = ([System.Net.IPAddress]($NetworkIP -join ".")).Address $StartIP = $NetworkIP +1 #Convert To Double If (($StartIP.Gettype()).Name -ine "double") { $StartIP = [Convert]::ToDouble($StartIP) } $StartIP = [System.Net.IPAddress]$StartIP Return $StartIP } [/sourcecode] Get-IPV4NetworkEndIP: [sourcecode language=”Powershell”] Function Get-IPV4NetworkEndIP ($strNetwork) { $StrNetworkAddress = ($strNetwork.split("/"))[0] [int]$NetworkLength = ($strNetwork.split("/"))[1] $IPLength = 32-$NetworkLength $NumberOfIPs = ([System.Math]::Pow(2, $IPLength)) -1 $NetworkIP = ([System.Net.IPAddress]$StrNetworkAddress).GetAddressBytes() [Array]::Reverse($NetworkIP) $NetworkIP = ([System.Net.IPAddress]($NetworkIP -join ".")).Address $EndIP = $NetworkIP

Continue reading

Updated: SCCM Health Check PowerShell Script

I have updated the SCCM Health Check Script that I have originally posted here. Download Version 3.1 Here. Changes: 1. The script can now utilise Powershell Remoting to check inboxes sizes. It requires PS-Remoting to be enabled on all SCCM Site Servers. This dramatically reduced the execution time of the script in a multi-tier environment. In a production environment that I support, it reduced the execution time from 1.5 – 2 hours to around 35 minutes!  You can configure which method to use via XML file. To enable, set <PSRemoting><Value> to Enabled. Or Disabled if you want to use the

Continue reading

Problem with DNS name resolution when using System.Net.DNS class

I recently ran into a problem when writing a PowerShell script to perform DNS Name resolution using .NET class System.Net.DNS (http://msdn.microsoft.com/en-us/library/system.net.dns.aspx). I noticed when I’m using System.Net.DNS to perform reverse lookup (GetHostByAddress method), even though the PTR record is missing in DNS, it is still able to resolve the name. It looks like this method connects to the host to retrieve its host name. When the machine is powered off, GetHostByAddress method is unable to resolve the IP address to it’s name (Which is desired result because there is no PTR record in reverse lookup zone): I then powered on

Continue reading

PowerShell Script: SCCM Health Check

30/01/2012: This script has been updated to version 3.5. Details can be found HERE. The download link on this article has also been updated to version 3.5. 26/05/2011: Version 3.3 has been posted here. The download link to the script on this post is also updated to the new version 3.3. 21/04/2011: Please be advised that I have posted a newer version of the script here. The existing script download link on this page has also been updated to point to the newer version. For the chanages in newer version, please refer to my updated post. Over the last few

Continue reading

How to locate SCCM Collection Object based on the Collection ID

Often, I found it’s hard to locate the Collection object in the SCCM console if you only know the Collection ID. Couple of weeks ago I ran into a situation where I need to modify the settings of a bunch of collection objects and all I knew was the Collection ID. I wrote a script called Get-CollectionPath that identifies all possible paths to a particular collection (as a collection can be linked to multiple places). The Syntax is: .\Get-CollectionPath <SCCM Central Site Server Name> <Collection ID> Download the script here. [sourcecode language=”powershell”] param([string]$CentralSiteServer,[string[]]$CollectionID) Function Get-CollectionName ($CollectionID) { $CollectionName = (Get-WmiObject

Continue reading

Get SCCM site roles using Powershell

You can run the following on the site server to find out the servers holding each SCCM role: $SMSProvider = get-wmiobject sms_providerlocation -namespace root\sms -filter “ProviderForLocalSite = True” $SiteCode = $SMSProvider.SiteCode $ProviderMachine = $SMSProvider.Machine get-wmiobject -Class SMS_SystemResourceList -NameSpace root\sms\site_$SiteCode -Computername $ProviderMachine | format-list RoleName,ServerRemoteName,SiteCode

Continue reading
%d bloggers like this: