Intune Initial Scripts Backup

This commit is contained in:
2025-04-21 14:21:38 -04:00
commit 71764cd10f
241 changed files with 28218 additions and 0 deletions

View File

@@ -0,0 +1,293 @@
$Location = Split-Path $MyInvocation.MyCommand.Path -Parent
$Script:ALL_Patch_Servers = @()
$Script:Responding = @()
$Script:NotResponding = @()
$Global:Collection_Name = ""
$Global:Select_Tool
$Global:Output_Type = ""
If(!(Get-PSDrive -Name SCCM-Drive -ErrorAction SilentlyContinue)) {
Import-Module 'C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1'
New-PSDrive -Name SCCM-Drive -PSProvider "AdminUI.PS.Provider\CMSite" -Root "PNCRASCCM001.ccx.carecentrix.com" -Description "SCCM Site"
}
#########################################################################################################################################################
Function Start-Form {
#$Global:Collection_Name = ""
#$Global:Select_Tool = ""
#$Global:Output_Type = ""
$Temp = ""
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$Form = New-Object System.Windows.Forms.Form
$Form.Size = New-Object System.Drawing.Size(900,500)
##############################################
#$Form_Load={ $Script:outputBox.text = "Welcome" }
############################################## Start functions
<# function pingInfo {
if ($RadioButton1.Checked -eq $true) {$nrOfPings=1}
if ($RadioButton2.Checked -eq $true) {$nrOfPings=2}
if ($RadioButton3.Checked -eq $true) {$nrOfPings=3}
$computer=$DropDownBox.SelectedItem.ToString() #populate the var with the value you selected
$pingResult=ping $wks -n $nrOfPings | fl | out-string;
$Script:outputBox.text=$pingResult
} #end pingInfo
#>
############################################## end functions
Function SCCM-Module {
If(!(Get-PSDrive).Name -eq "sccm-drive") {
Import-Module 'C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1'
New-PSDrive -Name SCCM-Drive -PSProvider "AdminUI.PS.Provider\CMSite" -Root "PNCRASCCM001.ccx.carecentrix.com" -Description "SCCM Site"
}#endIf
CD sccm-drive:
}#endFunction
##############################################
Function Run-Defaults {
$Script:textBox1.Text = "Nabil - Test Collection"
$Script:RadioButton1.Checked = $true
}
##############################################
Function temp {
$outputBox.Clear()
#$Script:outputBox.text = $textBox1.text | Out-String
$Global:Collection_Name = $textBox1.Text
#$Global:Select_Tool = $RadioButton1.Checked
$Global:Select_Tool = $DropDownBox.text
#$Global:Output_Type =
If ($RadioButton1.Checked -eq $true) { $Global:Output_Type = "Window"; $outputBox.Text = "Radio1 Checked: $($RadioButton1.Checked)" | Out-String }
ElseIf ($RadioButton2.Checked -eq $true) { $Global:Output_Type = "Gridview"; $outputBox.Text = "Radio2 Checked: $RadioButton2.Checked" | Out-String }
ElseIf ($RadioButton3.Checked -eq $true) { $Global:Output_Type = "Export"; $outputBox.Text = "Radio3 Checked: $RadioButton2.Checked" | Out-String }
If($Global:Collection_Name -and $Global:Select_Tool) {
# If($DropDownBox.text = "Tool1"){gcc}
Run-Tool
$textBox1.clear()
$DropDownBox.text = "----Select Tool----"
Clear-Variables
}#endIf
Else { #$T = { Write-Host "You must enter Collection Name ............!!" -ForegroundColor Red }
$Script:outputBox.SelectionColor = 'red'
$Script:outputBox.Text = "You must select 'Tool' and enter Collection Name............!!"
}
Run-Defaults
}#endFunction
##############################################
Function Update-Dropdown1 {
# $Collections += $textBox1.text
$Collections = @("Collection-Servers","Ping-Collection","Check_Uptime","Tool4","Tool5","Tool6","Tool7")
$Collections | % { $DropDownBox.Items.Add($_) }
}
##############################################
Function gcc {
$Script:outputBox.text = Get-Service | Out-String
}
##############################################
Function Clear-Variables {
$Global:Collection_Name = ""
$Global:Select_Tool = ""
$Global:Output_Type = ""
$Script:ALL_Patch_Servers = @()
}
#region Controls
############################################## Start group boxes
$groupBox = New-Object System.Windows.Forms.GroupBox
$groupBox.Location = New-Object System.Drawing.Size(270,20)
$groupBox.size = New-Object System.Drawing.Size(150,110)
$groupBox.text = "Select Output:"
$Form.Controls.Add($groupBox)
############################################## end group boxes
############################################## Start radio buttons
$Script:RadioButton1 = New-Object System.Windows.Forms.RadioButton
$Script:RadioButton1.Location = new-object System.Drawing.Point(15,15)
$Script:RadioButton1.size = New-Object System.Drawing.Size(130,20)
$Script:RadioButton1.Checked = $true
$Script:RadioButton1.Text = "Window"
$groupBox.Controls.Add($RadioButton1)
$Script:RadioButton2 = New-Object System.Windows.Forms.RadioButton
$Script:RadioButton2.Location = new-object System.Drawing.Point(15,35)
$Script:RadioButton2.size = New-Object System.Drawing.Size(80,20)
$Script:RadioButton2.Text = "Gridview"
$groupBox.Controls.Add($RadioButton2)
$Script:RadioButton3 = New-Object System.Windows.Forms.RadioButton
$Script:RadioButton3.Location = new-object System.Drawing.Point(15,55)
$Script:RadioButton3.size = New-Object System.Drawing.Size(80,20)
$Script:RadioButton3.Text = "Export csv"
$groupBox.Controls.Add($RadioButton3)
############################################## end radio buttons
########### Text Box ###########
############Define text box1 for input
$Script:textBox1 = New-Object System.Windows.Forms.TextBox;
$Script:textBox1.Left = 20;
$Script:textBox1.Top = 30;
$Script:textBox1.width = 200;
$Script:textBox1.Text = "Nabil - Test Collection"
$Form.Controls.Add($textBox1)
############################################## Start drop down boxes
$Script:DropDownBox = New-Object System.Windows.Forms.ComboBox
$Script:DropDownBox.Location = New-Object System.Drawing.Size(20,80)
$Script:DropDownBox.Size = New-Object System.Drawing.Size(180,20)
$Script:DropDownBox.DropDownHeight = 200
$Script:DropDownBox.text = "----Select Tool----"
$Form.Controls.Add($DropDownBox)
############################################## end drop down boxes
<############################################## Start text fields
$Script:outputBox = New-Object System.Windows.Forms.TextBox
$Script:outputBox.Location = New-Object System.Drawing.Size(10,150)
$Script:outputBox.Size = New-Object System.Drawing.Size(865,300)
$Script:outputBox.MultiLine = $True
$Script:outputBox.ScrollBars = "Vertical"
$Form.Controls.Add($Script:outputBox)
###########>
$SCRIPT:outputBox=New-Object System.Windows.Forms.RichTextBox
$outputBox.Location=New-Object System.Drawing.Size(10,150)
$outputBox.Size=New-Object System.Drawing.Size(865,300)
$outputBox.Multiline=$True
$outputBox.ReadOnly = $True
$outputBox.BackColor = [Drawing.Color]::White
$outputBox.ScrollBars = "Vertical"
$form.Controls.Add($Script:outputBox)
############################################## end text fields
############################################## Start buttons
$Button = New-Object System.Windows.Forms.Button
$Button.Location = New-Object System.Drawing.Size(450,30)
$Button.Size = New-Object System.Drawing.Size(110,80)
$Button.Text = "Go"
$Button.Add_Click({temp})
$Form.Controls.Add($Button)
#endregion Controls
############################################## end buttons
Update-Dropdown1
$Form.Add_Shown({$Form.Activate()})
[void] $Form.ShowDialog()
}
#########################################################################################################################################################
<# Function Input-Box {
[void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
$Global:Collection_Name = [Microsoft.VisualBasic.Interaction]::InputBox("Enter your name", "Name", "Enter Collection Name")
}
#>
#############################################################################################################################################################
Function Display-Results {
#Param($Global:Output_Type,$Final_Result)
Write-Host "DisplayType: $($Global:Output_Type)"
Switch ($Global:Output_Type){
Window { $Script:outputBox.Text = $Script:ALL_Patch_Servers | Out-String}
Gridview { $Script:ALL_Patch_Servers | Out-GridView }
Export { $Script:ALL_Patch_Servers | Export-Csv -Path $Location\Results.csv -NoTypeInformation; ii $Location\Results.csv }
}#endSwitch
}
#############################################################################################################################################################
Function Collection-Servers {
#Param($Coll_Name)
Write-Host "Collection:$Global:Collection_Name"
SCCM-Module
#CD sccm-drive:
$Script:DeviceCollection_MemberCount = Get-CMDeviceCollection -Name $Global:Collection_Name | select Name,MemberCount
$Script:DeviceCollection_ServerNames = Get-CMCollectionMember -CollectionName $Global:Collection_Name | select Name,IsClient #| Export-Csv "E:\SCCM-Files\SCCM-Scripts\Files\$Global:Collection_Name.csv" -NoTypeInformation
#$ServerName = $DeviceCollection_ServerNames.Name
Set-Location c:
#$Script:Temp = Get-CMCollectionMember -CollectionName $Global:Collection_Name #| select Name,IsClient
$Script:DeviceCollection_ServerNames | % {
$Obj = New-Object -TypeName PSObject
$Obj | Add-Member -MemberType NoteProperty -Name Server -Value $_.Name
$Obj | Add-Member -MemberType NoteProperty -Name ClientInstalled -Value $_.IsClient
$Obj | Add-Member -MemberType NoteProperty -Name CollectionName -Value $Global:Collection_Name
#$Obj | Add-Member -MemberType NoteProperty -Name CollectionMemberCount -Value {(Get-CMCollectionMember -Name $Global:Collection_Name).MemberCount}
$Obj
$Script:ALL_Patch_Servers += $Obj
}#end%
# $Script:outputBox.Text = $Script:ALL_Patch_Servers | Out-String
Display-Results #-Final_Result $Script:ALL_Patch_Servers
Write-Host "$Script:ALL_Patch_Servers"
}#endFunction
#############################################################################################################################################################
Function Ping_Collection {
Write-Host "Total Server Count: $($Script:ALL_Patch_Servers.count)" -ForegroundColor Green
Write-Host ""
SCCM-Module
#CD sccm-drive:
$Script:DeviceCollection_ServerNames1 = Get-CMCollectionMember -CollectionName $Global:Collection_Name | select Name
Set-Location c:
$Script:DeviceCollection_ServerNames1.Name | % {
If (Test-Connection $_ -Count 1 -ErrorAction SilentlyContinue ) {
#Write-Host "Responding:---- $_ " -ForegroundColor Green
$Script:outputBox.AppendText("Responding: $_")
$Responding += $_
}#endIf
Else {
$Script:outputBox.AppendText("NOT Responding: $_")
$NotResponding += $_ }
}#end%
write-host "-------------------------------------------------------"
Write-host "$($Responding.count) / $($DeviceCollection_ServerNames1.count) -- Responding" -foregroundcolor Green
Write-host "$($NotResponding.count) / $($DeviceCollection_ServerNames1.count) -- NOT Responding" -foregroundcolor Red
Write-Host "Servers NOT Responding: $NotResponding " -ForegroundColor Red
}#endFunction
#############################################################################################################################################################
Function Check_Uptime {
SCCM-Module
$Script:DeviceCollection_ServerNames1 = Get-CMCollectionMember -CollectionName $Global:Collection_Name | select Name
$Script:outputBox.Text = $Script:DeviceCollection_ServerNames1.name | % { gwmi win32_operatingsystem -ComputerName $_ -ErrorAction SilentlyContinue | select @{n="Server";e={$_.PSComputername}},@{n="LastBootup";e={$_.Converttodatetime($_.LastBootUpTime)}}} | sort LastBootup -descending | Out-String
}
#############################################################################################################################################################
Function Run-Tool {
Switch($Global:Select_Tool) {
Collection-Servers { Collection-Servers; Write-Host "Tool Selected: $Global:Select_Tool" }
Ping-Collection { Ping_Collection }
Check_Uptime { Check_Uptime }
}#endSwitch
#Clear-Variables
}#endFunction
#############################################################################################################################################################
Start-Form

View File

@@ -0,0 +1,130 @@
Function Restart-SCCMSyncCycle {
<#
.Synopsis
Remotely restarts sccm service cycles.
.DESCRIPTION
This function restarts all sccm policies on a remote client so that the client can immediately get any pending software updates or inventory.
.NOTES
Name: Restart-SCCMSyncCycle
Author: theSysadminChannel
Version: 1
DateCreated: 2017-02-09
.LINK
https://thesysadminchannel.com/remotely-restart-sccmsynccycle-using-powershell -
.PARAMETER ComputerName
The computer to which connectivity will be checked
.EXAMPLE
Restart-SCCMSyncCycle -Computername Pactest-1
Description:
Will restart all sccm services on a remote machine.
.EXAMPLE
Restart-SCCMSyncCycle -ComputerName pactest-1, pactest-2, pactest-3
Description:
Will generate a list of installed programs on pactest-1, pactest-2 and pactest-3
#>
[CmdletBinding()]
param(
[Parameter(
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
Position=0)]
[string[]] $ComputerName = $env:COMPUTERNAME
)
Foreach ($Computer in $ComputerName ) {
try {
Write-Host "====================================================================="
Write-Output "$Computer : Machine Policy Evaluation Cycle"
Invoke-WMIMethod -ComputerName $Computer -Namespace root\ccm -Class SMS_CLIENT -Name TriggerSchedule "{00000000-0000-0000-0000-000000000022}" -ErrorAction Stop | select -ExpandProperty PSComputerName | Out-Null
Write-Output "$Computer : Application Deployment Evaluation Cycle"
Invoke-WMIMethod -ComputerName $Computer -Namespace root\ccm -Class SMS_CLIENT -Name TriggerSchedule "{00000000-0000-0000-0000-000000000121}" | select -ExpandProperty PSComputerName | Out-Null
# Write-Output "$Computer : Discovery Data Collection Cycle"
# Invoke-WMIMethod -ComputerName $Computer -Namespace root\ccm -Class SMS_CLIENT -Name TriggerSchedule "{00000000-0000-0000-0000-000000000003}" | select -ExpandProperty PSComputerName | Out-Null
# Write-Output "$Computer : File Collection Cycle"
# Invoke-WMIMethod -ComputerName $Computer -Namespace root\ccm -Class SMS_CLIENT -Name TriggerSchedule "{00000000-0000-0000-0000-000000000010}" | select -ExpandProperty PSComputerName | Out-Null
# Write-Output "$Computer : Hardware Inventory Cycle"
# Invoke-WMIMethod -ComputerName $Computer -Namespace root\ccm -Class SMS_CLIENT -Name TriggerSchedule "{00000000-0000-0000-0000-000000000001}" | select -ExpandProperty PSComputerName | Out-Null
Write-Output "$Computer : Machine Policy Retrieval Cycle"
Invoke-WMIMethod -ComputerName $Computer -Namespace root\ccm -Class SMS_CLIENT -Name TriggerSchedule "{00000000-0000-0000-0000-000000000021}" | select -ExpandProperty PSComputerName | Out-Null
Write-Output "$Computer : Software Inventory Cycle"
Invoke-WMIMethod -ComputerName $Computer -Namespace root\ccm -Class SMS_CLIENT -Name TriggerSchedule "{00000000-0000-0000-0000-000000000002}" | select -ExpandProperty PSComputerName | Out-Null
# Write-Output "$Computer : Software Metering Usage Report Cycle"
# Invoke-WMIMethod -ComputerName $Computer -Namespace root\ccm -Class SMS_CLIENT -Name TriggerSchedule "{00000000-0000-0000-0000-000000000031}" | select -ExpandProperty PSComputerName | Out-Null
Write-Output "$Computer : Software Update Deployment Evaluation Cycle"
Invoke-WMIMethod -ComputerName $Computer -Namespace root\ccm -Class SMS_CLIENT -Name TriggerSchedule "{00000000-0000-0000-0000-000000000114}" | select -ExpandProperty PSComputerName | Out-Null
#Write-Output "$Computer : Software Update Scan Cycle"
#Invoke-WMIMethod -ComputerName $Computer -Namespace root\ccm -Class SMS_CLIENT -Name TriggerSchedule "{00000000-0000-0000-0000-000000000113}" | select -ExpandProperty PSComputerName | Out-Null
# Write-Output "$Computer : State Message Refresh"
# Invoke-WMIMethod -ComputerName $Computer -Namespace root\ccm -Class SMS_CLIENT -Name TriggerSchedule "{00000000-0000-0000-0000-000000000111}" | select -ExpandProperty PSComputerName | Out-Null
#Write-Output "$Computer : User Policy Retrieval Cycle"
#Invoke-WMIMethod -ComputerName $Computer -Namespace root\ccm -Class SMS_CLIENT -Name TriggerSchedule "{00000000-0000-0000-0000-000000000026}" | select -ExpandProperty PSComputerName | Out-Null
#Write-Output "$Computer : User Policy Evaluation Cycle"
#Invoke-WMIMethod -ComputerName $Computer -Namespace root\ccm -Class SMS_CLIENT -Name TriggerSchedule "{00000000-0000-0000-0000-000000000027}" | select -ExpandProperty PSComputerName | Out-Null
# Write-Output "$Computer : Windows Installers Source List Update Cycle"
# Invoke-WMIMethod -ComputerName $Computer -Namespace root\ccm -Class SMS_CLIENT -Name TriggerSchedule "{00000000-0000-0000-0000-000000000032}" | select -ExpandProperty PSComputerName | Out-Null
sleep 1
}
catch {
Write-Host $Computer.toUpper() "is not online or Account is locked out" -ForegroundColor:Red
Write-Host
Write-Host
}
}
}
# Restart-SCCMSyncCycle pver001
# Restart-SCCMSyncCycle
# Restart-SCCMSyncCycle $DeviceCollection_ServerNames.name
Restart-SCCMSyncCycle w2012a,w2012b