AzureAD/Intune – Add list of systems from CSV to Group with PowerShell

My work has been moving more and more into the cloud and making use of Intune. Recently, I was tasked with adding a large list of systems to a group in AzureAD for use in Intune. No one wants to do something like that manually, so I put together a script to do it for me.

I make use of two different PowerShell modules and you will need you AzureAD tenant ID, the object ID of the group along with rights to add to groups in AzureAD, and a CVS of the systems. I labeled the first row DeviceName.

Install-Module AzureAD
Install-Module msonline

$TenentID = <AzureAD tenent ID>
$groupID = <object ID of the AzureAd group> 
Connect-AzureAD -TenantId $TenentID
Connect-MsolService

$CHGList = Import-Csv -path <path to CSV>
Foreach ($Device in $CHGList)
{
$deviceadd = Get-MsolDevice -Name $Device.DeviceName | Select-Object -ExpandProperty ObjectID 
Add-AzureADGroupMember -ObjectId $groupID -RefObjectId $deviceadd
}   

VSCode script template with logging

I recently created an alternative version of the script template. This one is for PowerShell scripts and includes additions for the logging that I do both within a log file and Event Viewer. I am including the template and the code to add to VSCode to make it a snippet. I also have the code and snippets for adding the logging within the script. Continue reading “VSCode script template with logging”

Using VSCode snippets to apply your script template

Previously I wrote about the need for standardizing scripts and showed the template that I made. The question is how to easily start your scripts from the template.  You can open the template and save it as a new file but I think that is extra work I do not want to do.  If your script editor allows for the use of code snippets, things become easier.  My editor of choice is Visual Studio Code (VSCode) and I will show you how to create a code snippet for your template.  You can use this to easily add repeatable code to your scripts.  Again, this is being done with VSCode which is what I recommend as I love the script analyzer that it has as well as the ability to expand its functionality with community created extensions. Continue reading “Using VSCode snippets to apply your script template”

PowerShell Script to Automate Running ContentLibraryCleanup.exe Against All DPs in SCCM Site

This is a rough script that automates the running of the content library cleanup tool available after SCCM Build 1702. The script will connect to a SCCM site to build a list of distribution points to run against. This needs to be ran on the primary site server under account with full admin rights in SCCM. It checks four possible locations for the PS module and the cleanup tool. The script prompts for the SCCM site code, the FQDN of the primary site server, and if you want the tool to delete orphaned content or just log to the tools default log location. Continue reading “PowerShell Script to Automate Running ContentLibraryCleanup.exe Against All DPs in SCCM Site”

SCCM Compliance Settings Scripts to Alter Service State

Previously I showed how I used SCCM Compliance Settings and Boundary Groups to apply BITS settings. This time I have a discovery and remediation script that can be used with enforce a specific state on a service. If you want to make sure a client’s App-V service stays up or Windows Defender is disabled because you are using another security suite, this could be of help. The script uses variables so someone could easily set the state of the service and start type to what they want. Continue reading “SCCM Compliance Settings Scripts to Alter Service State”

Using ConfigMgr Compliance Settings and a Boundary Group to Apply BITS Settings

The solution here makes use of a boundary group to determine if a SCCM client should use BITS to control content transfers and compliance settings set the BITS settings.  With SCCM build 1610, the boundary group IDs a client is associated with are store in WMI.  Using PowerShell, we are able to look at the boundary group ID and use it to help set BITS settings.  Fair warning with this solution.  While the boundary group ID is currently stored in WMI, I have been informed by Microsoft that this information isn’t meant to be customer facing and may go away in future SCCM builds, but it is something that is current available. Continue reading “Using ConfigMgr Compliance Settings and a Boundary Group to Apply BITS Settings”