powershell
344 TopicsCan't add device member in Static Security Entra Group with powershell
Hi, With Graph, I want to add some device members in a static security Entra group using it to deploy some certificates with Intune. I do it with following command: New-MgGroupMember -GroupId $groupId -DirectoryObjectId $device.AzureAdDeviceId but I receive this error: New-MgGroupMember : Resource 'df75dfe1-8b5a-4cc6-8f99-17746bb8c07e' does not exist or one of its queried reference-property objects are not present. In C:\Users\E21996\OneDrive - Fondazione Enasarco\Lavoro\!HelpDesk\!Intune\Scripts\Set-Device-Department-Attribute.ps1:57 car:9 + New-MgGroupMember -GroupId $groupId -DirectoryObjectId $devic ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: ({ GroupId = 9fa...ferenceCreate }:<>f__AnonymousType1`2) [New-MgGroupMember_CreateExpanded], Exception + FullyQualifiedErrorId : Request_ResourceNotFound,Microsoft.Graph.PowerShell.Cmdlets.NewMgGroupMember_CreateExpanded I've checked the GroupID and Azure Device ID and are correct. If I try to add a user it works fine, with device I have this error. In the group I can add device member manually from Intune without problems. There is a known issue when add device members to groups in Graph? Can anyone help me to resolve this issue, please?110Views0likes2CommentsNew-MgBookingBusinessService | Customer Information Questions
I'm trying to turn off the stock Customer Information questions except for the customer email using PowerShell and New-MgBookingBusinessService and cannot seem to figure it out. Any assistance is much appreciated! # Prompt for Booking Business ID $bookingBusinessId = Read-Host "Enter the Booking Business ID (e.g., email address removed for privacy reasons)" # Prompt for default duration in minutes $defaultDurationMinutes = Read-Host "Enter default appointment duration in minutes (e.g., 15)" $defaultDuration = [TimeSpan]::FromMinutes([double]$defaultDurationMinutes) # Post-buffer stays at 5 minutes $postBuffer = [TimeSpan]::FromMinutes(5) # Hardcoded Excel file path $excelFilePath = "C:\Users\apettit\OneDrive - Eau Claire Area School District\Downloads\adamtestconferencedata.xlsx" # Prompt for worksheet/tab name $sheetName = Read-Host "Enter the worksheet/tab name to read data from" # Import Excel data using Import-Excel (requires ImportExcel module) if (-not (Get-Module -ListAvailable -Name ImportExcel)) { Install-Module -Name ImportExcel -Scope CurrentUser -Force } Import-Module ImportExcel $staffEmails = Import-Excel -Path $excelFilePath -WorksheetName $sheetName # Retrieve all staff members for the booking business Write-Host "Fetching all staff members for booking business ID: $bookingBusinessId" $allStaff = Get-MgBookingBusinessStaffMember -BookingBusinessId $bookingBusinessId if (-not $allStaff) { Write-Error "No staff members found for the booking business ID: $bookingBusinessId" return } # Retrieve all custom questions Write-Host "Fetching all custom questions for booking business ID: $bookingBusinessId" $allCustomQuestions = Get-MgBookingBusinessCustomQuestion -BookingBusinessId $bookingBusinessId if (-not $allCustomQuestions) { Write-Error "No custom questions found for the booking business ID: $bookingBusinessId" return } # Loop through each staff member from Excel automatically Write-Host "Creating individual booking services for each staff member..." foreach ($row in $staffEmails) { $email = $row.emailAddress.Trim().ToLower() # Automatically match staff from Booking Business $matchingStaff = $allStaff | Where-Object { $_.AdditionalProperties["emailAddress"] -and ($_.AdditionalProperties["emailAddress"].Trim().ToLower() -eq $email) } if ($matchingStaff) { $staffId = $matchingStaff.Id $displayName = $matchingStaff.AdditionalProperties["displayName"] Write-Host "Automatically creating service for: ${displayName} ($email)" -ForegroundColor Cyan try { # Prepare custom questions $customQuestions = $allCustomQuestions | ForEach-Object -Begin { $isLast = $false } -Process { $isLast = ($_.Id -eq $allCustomQuestions[-1].Id) $questionAssignment = New-Object Microsoft.Graph.PowerShell.Models.MicrosoftGraphBookingQuestionAssignment $questionAssignment.QuestionId = $_.Id $questionAssignment.IsRequired = if ($isLast) { $false } else { $true } $questionAssignment } # Prepare the reminder $defaultReminder = New-Object Microsoft.Graph.PowerShell.Models.MicrosoftGraphBookingReminder $defaultReminder.Message = "Don't forget! Family Teacher Conferences are tomorrow, and we are excited to visit with you! If you wish to change the meeting type (virtual, in-person, hybrid, or phone), please let the teacher know as soon as possible!" $defaultReminder.Offset = [TimeSpan]::FromDays(1) $defaultReminder.Recipients = @("customer") # Prepare service parameters $serviceParams = @{ BookingBusinessId = $bookingBusinessId DisplayName = "${displayName} Family Conference" Description = "Family Teacher Conference with ${displayName}" StaffMemberIds = @($staffId) # Assign specific staff member DefaultDuration = $defaultDuration DefaultPrice = 0.00 DefaultPriceType = "free" CustomQuestions = $customQuestions PostBuffer = $postBuffer IsLocationOnline = $true IsCustomerAllowedToManageBooking = $true DefaultReminder = $defaultReminder AdditionalInformation = @" Please arrive on time for your conferences as we will be sticking to a tight schedule. If you wish to change the meeting type (virtual, in-person, hybrid, or phone), please let the teacher know as soon as possible. If you require a translator, please submit a request at this form: https://forms.office.com/r/XWwBFWP7XD "@ # Appears in the customer confirmation email AdditionalProperties = @{ customerEmail = @{ isRequired = $true } # Only email field remains } } # Log service parameters Write-Host "Service Parameters for ${displayName}:" -ForegroundColor Blue $serviceParams.GetEnumerator() | ForEach-Object { Write-Host "$($_.Key): $($_.Value)" } # Create the booking service New-MgBookingBusinessService @serviceParams Write-Host "Booking service successfully created for ${displayName}!" -ForegroundColor Green } catch { Write-Error "Failed to create booking service for ${displayName}: $_" } } else { Write-Warning "No match found for email: $email" } }11Views0likes0CommentsCopy-Item -Recurse bug
We are copying files using the Copy-Item cmdlet from a local disk to a remote disk. The source folder contains around 900 files in numerous subdirectories. Copy-Item -Path "build\image\*" -Destination $output_path -Recurse -Verbose Get-Command Copy-Item | Select-Object Name, Version Name Version ---- ------- Copy-Item 3.1.0.0217Views1like3CommentsFC Target discovery
I was looking for a way to discover FC targets for each initiator. Searching on the web I found this code # Get all initiator ports (HBA ports) $initiatorPorts = Get-InitiatorPort # Loop through each initiator port and list its targets foreach ($port in $initiatorPorts) { Write-Host "Initiator Port: $($port.NodeAddress) - $($port.PortAddress)" $targets = Get-InitiatorTarget -InitiatorPortAddress $port.PortAddress foreach ($target in $targets) { Write-Host " Target: $($target.NodeAddress) - $($target.PortAddress)" } } But is not working because the Get-initiatortarget is not recognized as valid command. Is there a way I can do it thanks120Views0likes2CommentsNeed help importing user data from csv
I need to fill in the Manager Attribute for employee accounts using a CSV export from HR. I have the added bonus of the fact that SamAccountNames do not follow a consistent naming convention. So I need to use the EmployeeID attribute for finding accounts. Here is an example of the CSV. "LAST_NAME","FIRST_NAME","EmployeeID","SupervisorID" "Doe","John","12345","13324" "Jane","Laura","13456","3455" "Mclane","John","12351","11331" In this case, John Doe's Manager has an EmployeeID of 13324. So I need to search AD for a User object with the EmployeeID attribute of 13324. Then I need to pull the DistinguishedName attribute from that User Object, for example "CN=LSkywalker,OU=Department,DC=contoso,DC=com" Then I'd have to copy that data into the Manager attribute of John Doe's account. I've been trying to outline the script and so far this is what I have. Variables $User $SupervisorID $EmployeeID $DistinguishedName For each $User in CSV find $EmployeeID and $SupervisorID Search AD for Supervisor Account where EmployeeID attribute = $SupervisorID Pull $DistinguishedName Attribute value from Supervisor's account Input $DistinguishedName value into original $EmployeeID's Manager Attribute Proceed to next line of CSV and repeat Hopefully I've explained the situation well and someone can help me flesh this out more, any help would be greatly appreciated, thank you.Solved2.4KViews0likes8CommentsInstall-Package - failed to be installed: End of Central Directory record could not be found.
Hi all, Since last week I've had multiple errors in my pipelines when trying to install NuGet packages: Install-Package -Name Microsoft.PowerBi.Api -Source MyNuGet -ProviderName NuGet -Scope CurrentUser -RequiredVersion 3.18.1 -SkipDependencies This seems to be affecting multiple packages: Install-Package : Package Newtonsoft.Json failed to be installed because: End of Central Directory record could not be found. Install-Package : Package Microsoft.Rest.ClientRuntime failed to be installed because: End of Central Directory record could not be found. Install-Package : Package Microsoft.PowerBI.Api failed to be installed because: End of Central Directory record could not be found. When downloading the package I don't see any errors using nuget verify. I get these errors in microsoft hosted agents in ADO pipelines, on my laptop, or any VM I use. Doesn't seem to be related to PS or OS version or any proxies/firewalls. Any ideas? Thank you377Views1like0Commentsresolve-dnsname returns odd data
hi, appreciate your time. I am working with resolve-dnsname and I am seeing some odd results. for example: resolve-dnsname -server 10.0.20.5 -name "60.16.40.194.in-addr.arpa" -NoHostsFile -type ptr Name Type TTL Section NameHost ---- ---- --- ------- -------- 60.16.40.194.in-addr.arpa. PTR 1200 Question LNB050825-LT3 so here is what's weird about this.... when I look at my dns server with dns manager and look at the reverse zone, I do not have a record for this IP address: Also, when I look at the resolve-dnsname data, I see there is something called "Section", and it is set to "Question". Also notice that the "NameHost" is short and not a FQDN. The "Section" is interesting because on requests the return the right data, Section is set to "Answer". Equally weird is that if I pick a different IP that I also know does not exist, I get this: PS C:\Trash> resolve-dnsname -server 10.0.20.5 -name "60.1.40.194.in-addr.arpa" -NoHostsFile -type ptr Resolve-DnsName: 60.1.40.194.in-addr.arpa : DNS name does not exist. this is what I would expect if the record does not exist....so what is happening in the first example? Thanks in advance for anyone's time on this.147Views0likes2CommentsArray and array member methods
The following PowerShell code: class MyClass { } class MyClass1 : MyClass { [void] OutMsg([string] $Str) { Write-Host -Object "MyClass1: $Str" } } class MyClass2 : MyClass { [void] OutMsg([string] $Str) { Write-Host -Object "MyClass2: $Str" } } [MyClass[]] $ClassArray = @([MyClass1]::new(), [MyClass2]::new()) $ClassArray.OutMsg('TestString') outputs: MyClass1: TestString MyClass2: TestString A Get-Member -InputObject $ClassArray shows me that the array object itself has no OutMsg method. Why can I successfully call $ClassArray.OutMsg('TestString') though (looks like this calls the OutMsg method of each array member in turn)?118Views0likes3CommentsActivating a users multiple PIM groups using PowerShell
Hi All, Following on from the implementation of PIM by one of my clients. Due to the large numbers of groups for some staff, i.e. developers etc, we have looked into activating them programmatically. However, this always appears to fall over due to the syntax etc. Whether using Get-MgPrivilegedAccessGroupEligibilityScheduleInstance or Invoke-MgGraphRequest -Method POST -Uri "https://graph.microsoft.com/beta/identityGovernance/privilegedAccess/group/assignments" or New-MgRoleManagementDirectoryRoleAssignmentScheduleRequest. In various scripts, it either falls over intermittently saying '..is not recognised as the name of a cmdlet..etc etc etc. To check whether anyone else has achieved this. I am trying to avoid reworking what they have put in place over the past 3 months or so. Many Thanks MoZZaSolved148Views0likes1Comment