Posts

Showing posts from 2018

Machine collection based on user AD group

In general I don't recommend anyone do this unless you have to. Especially in environments where a user has more than one machine. Now I know you're thinking 'why not just target users' well that is a good question. In this case I needed to add an exclude collection to the machine collection to prevent installation on certain machines. But if you ever find yourself in such a predicament. Here you go. 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 inner join SMS_G_System_SYSTEM_CONSOLE_USER on SMS_G_System_SYSTEM_CONSOLE_USER.ResourceID = SMS_R_System.ResourceId inner join SMS_R_User on SMS_R_USER.UniqueUserName = SMS_G_System_SYSTEM_CONSOLE_USER.SystemConsoleUser Where SMS_R_User.UserGroupName = "Domain\\ADGroup"

Hard to reach Registry Hive

Had an instance of needing to reach HKEY_CLASSES_Root with powershell and found it doesn't have an HKCR built in. Ended up finding a post that had a simple solution and wanted to pass it along. For full details see: https://blogs.msdn.microsoft.com/lior/2009/06/18/what-no-hkcr-in-powershell/ Otherwise here is the important bit that I used: New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT

Additional Information using COM object to send email from Powershell

So I found that if you happen to be in an environment were you have more than one mailbox and you have permissions to send from that other mailbox. You might think that just using the From attribute in the object would send your email from that other mailbox. Well if you thought that you would find you are mistaken (or at least I was). You have to use the "SentOnBehalfOfName" attribute to be able to make your email send from that other mailbox. Here is a handy little function to give you a hand. function Send-Email ( [string] $ Address , [string] $ CCAddress , [string] $ BCCAddress , [string] $ Subject , [string] $ HTMLBody , [string] $ FromAddress) { $ Outlook = New-Object - ComObject Outlook.Application $ Mail = $ Outlook .CreateItem ( 0 ) If(!( [string] ::IsNullOrWhiteSpace ($ FromAddress ))) { $ Mail .SentOnBehalfOfName = $ FromAddress } If (!( [string] ::IsNullOrWhiteSpace ($ CCAddress ))) { $ Mail .CC = $ CCAddress