topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Friday December 13, 2024, 11:03 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: intune device management + powershell  (Read 4980 times)

Target

  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 1,832
    • View Profile
    • Donate to Member
intune device management + powershell
« on: April 25, 2023, 08:28 PM »
hoping someone here can help out  :-[

I have a few hundred devices that I need to retire + delete from intune but the portal doesn't cater for bulk deletions.

I've been googling solutions and it appears it can be done via powershell, but none of the scripts (or the associated 'explanations') I've found are particularly helpful

I'm not familiar with powershell, but I can understand the intent of the commands (its plain english, not rocket surgery!).  Trouble is I can't understand why they're not working (presumably there's some component or action thats assumed by the authors but not stated)

TIA

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,644
    • View Profile
    • Donate to Member
Re: intune device management + powershell
« Reply #1 on: April 26, 2023, 06:05 AM »
NOTE: I can't test this not having Intune but when I ran it I was prompted to input MS credentials which I assume it needs for admin functions.

Needless to say, try a test first.

May help, may not.

This information is from these URLs:
https://smsagent.blo...mgr-with-powershell/
https://social.techn...he-list-of-computers

You need to install dependencies which you can do as follows in a PowerShell Admin console.

For Intune you need: Microsoft.Graph.Intune
For AzureAD you need: AzureAD

Below is the commands with the output you can expect:
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
Try the new cross-platform PowerShell https://aka.ms/pscore6

PS C:\Users\ItsMe> Install-Module -name Microsoft.Graph.Intune
NuGet provider is required to continue
PowerShellGet requires NuGet provider version '2.8.5.201' or newer to interact with NuGet-based repositories. The NuGet
 provider must be available in 'C:\Program Files\PackageManagement\ProviderAssemblies' or
'C:\Users\ItsMe\AppData\Local\PackageManagement\ProviderAssemblies'. You can also install the NuGet provider by running
'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force'. Do you want PowerShellGet to install and import
 the NuGet provider now?
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"): Y

Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its
InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from
'PSGallery'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): Y

PS C:\Users\ItsMe> Install-Module -name AzureAD

Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its
InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from
'PSGallery'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): Y
PS C:\Users\ItsMe>


With the code from the site you create the Delete-AutopilotedDeviceRecords.ps1 script in a dir, (I've attached the script but you'll probably need to change it's security properties for it to run).

Then, in theory, you should be able to: .\Delete-AutopilotedDeviceRecords.ps1 -ComputerName <computer name> -Intune

For multiple computers, create a CSV with one per line, for example:
Code: Text [Select]
  1. computername
  2. pc01
  3. pc02
  4. pc03
  5. pc04

And then this short script should run through them all:
Code: PowerShell [Select]
  1. $computer = Import-Csv .\test.csv
  2. $computer | ForEach-Object {
  3.   ./Delete-AutopilotedDeviceRecords.ps1 -ComputerName $_.computername -Intune
  4. }


Target

  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 1,832
    • View Profile
    • Donate to Member
Re: intune device management + powershell
« Reply #2 on: April 26, 2023, 04:12 PM »
thanks!  I'd got thru the addins part already, but getting a working script has been the challenge

I'll have a play with it later today  :Thmbsup: :Thmbsup: :Thmbsup: