visual studio
13 TopicsNew-MgBookingBusinessService CustomQuestions
Hi! I'm working my way though BookingBusiness with PowerShell, so please forgive me if this is obvious. I've tried combing documentation but nothing seems to work. I have this script, and first, I think I have to create the customQuestions and have done so successfully and have the reference IDs for the questions to use in the New-MgBookingBusinessService script. I cannot seem to get the customQuestion piece to work. I'm first getting the available business staff and the custom questions I've already created. Everything works until I try the CustomQuestions piece. Here is what I have if you could please provide any assistance or guidance. Thank you! # Define the Booking Business ID $bookingBusinessId = "SCRUBBED" # Path to your CSV file $csvFilePath = "SCRUBBED" # Import CSV file $staffEmails = Import-Csv -Path $csvFilePath # Retrieve all staff members for the booking business Write-Host "Fetching all staff members for booking business ID: $bookingBusinessId" $allStaff = Get-MgBookingBusinessStaffMember -BookingBusinessId $bookingBusinessId # Ensure $allStaff is not null or empty if (-not $allStaff) { Write-Error "No staff members found for the booking business ID: $bookingBusinessId" return } # Debugging: Display all staff members retrieved (with Email and ID) Write-Host "Staff members retrieved (Email and ID):" -ForegroundColor Green $allStaff | ForEach-Object { $email = $_.AdditionalProperties["emailAddress"] $id = $_.Id $displayName = $_.AdditionalProperties["displayName"] Write-Host "DisplayName: $displayName, Email: $email, ID: $id" -ForegroundColor Yellow } # Retrieve all custom questions for the booking business Write-Host "Fetching all custom questions for booking business ID: $bookingBusinessId" $allCustomQuestions = Get-MgBookingBusinessCustomQuestion -BookingBusinessId $bookingBusinessId # Ensure $allCustomQuestions is not null or empty if (-not $allCustomQuestions) { Write-Error "No custom questions found for the booking business ID: $bookingBusinessId" return } # Debugging: Display all custom questions retrieved (with ID and DisplayName) Write-Host "Custom questions retrieved (ID and DisplayName):" -ForegroundColor Green $allCustomQuestions | ForEach-Object { $id = $_.Id $displayName = $_.DisplayName Write-Host "ID: $id, DisplayName: $displayName" -ForegroundColor Yellow } # Loop through each staff member in the CSV and create an individual service for them Write-Host "Creating individual booking services for each staff member..." $staffEmails | ForEach-Object { $email = $_.staffemail.Trim().ToLower() # Find the matching staff member by email $matchingStaff = $allStaff | Where-Object { $_.AdditionalProperties["emailAddress"] -and ($_.AdditionalProperties["emailAddress"].Trim().ToLower() -eq $email) } if ($matchingStaff) { $staffId = $matchingStaff.Id Write-Host "Match found: Email: $email -> ID: $staffId" -ForegroundColor Cyan # Create the booking service for the matched staff member try { $serviceParams = @{ BookingBusinessId = $bookingBusinessId DisplayName = "$($matchingStaff.AdditionalProperties["displayName"]) Family Conference" StaffMemberIds = @($staffId) # Create a service only for this staff member DefaultDuration = [TimeSpan]::FromHours(1) DefaultPrice = 50.00 DefaultPriceType = "free" Notes = "Please arrive 10 minutes early for your booking." CustomQuestions = $allCustomQuestions | ForEach-Object { @{ Id = $_.Id IsRequired = $true # or $false depending on your requirement } } } # Log the parameters being sent Write-Host "Service Parameters for $($matchingStaff.AdditionalProperties["displayName"]):" -ForegroundColor Blue $serviceParams.GetEnumerator() | ForEach-Object { Write-Host "$($_.Key): $($_.Value)" } New-MgBookingBusinessService @serviceParams Write-Host "Booking service successfully created for $($matchingStaff.AdditionalProperties["displayName"])!" -ForegroundColor Green } catch { Write-Error "Failed to create booking service for $($matchingStaff.AdditionalProperties["displayName"]): $_" } } else { Write-Warning "No match found for email: $email" } }91Views0likes8CommentsDoes Microsoft stop support WMIC or WMI?
Hello everyone, Nice to meet you! I heard that MS has plans to deprecate and stop supporting the VB script very soon. I have few queries, please clarify Does Microsoft stop supporting WMIC or WMI along with the VB script? Can we use WMI commands in PowerShell scripts? thanks Madhu56Views0likes1CommentError 429 when processing large documentlibrary
I'm trying to clean up all document versions above 100 on all documentlibraries in client's tenant. The smaller ones are fine and are cleaning up like a charm. But the bigger ones give problems. Is it possible to load the documents in a library in intervals of for example 5000 documents at a time, so that chance of throttling can be minimized? I have attached a photo of the script. The parameters are above (Site/document libraries/versions to keep)597Views0likes1CommentWindows (10.0.19042) debugger (VS Code vsdbg and Visual Studio) can not attach to PowerShell (7.1.3)
Hello, thank you for the new cross-platform PowerShell. Really an improvement and fun to use. However I cannot get Windows debuggers to attach to one at the moment. Attaching Visual Studio to older Windows PowerShell 5.1.19041.906 succeeds but trying to attach to 7.1.3 results in "Unable to attach to the process. A debug component is not installed.". Visual Studio version is VisualStudio.16.Release/16.9.5+31229.75 Community. When selecting a process to attach to, Visual Studio does recognizes pwsh.exe as "Automatic: Managed (.Net Core, .Net 5+) code" in the Attach to: -field. But then it just cannot attach to it. Visual Studio Code debugger vsdbg reports "Unable to attach to CoreCLR. Unknown Error: 0x80131c3c". VS Code version is 1.56.2 (user setup). vsdbg is Microsoft .NET Core Debugger (vsdbg), no version information available, at $HOME\.vscode\extensions\ms-dotnettools.csharp-1.23.11\.debugger\vsdbg.exe. vsdbg is launched with command line parameters '--interpreter=vscode' and '--connection=<a 32 character string, looks like a hash>'. The Visual Studio Code error code 0x80131c3c seems to be related to PowerShell on non-Windows platforms. Googling "debug component is not installed" for visual studio and .net5 gives an article that has both error messages mentioned: https://docs.microsoft.com/en-us/dotnet/core/deploying/single-file According to that article, these error messages are given when mscordbi.dll is not in the same folder as the executable. In my case, the dll (MS .NET Runtime Debugging Services, 5.0.421.11614) is in the same folder as pwsh.exe. Anyone have any idea about the PowerShell debug component that VS would like to have installed or why Code gives that "Unable to attach to CoreCLR. Unknown Error: 0x80131c3c"? BR and many thanks in advance, DH7.3KViews0likes1CommentPowershell from SSIS
I am attempting to run a simple Powershell command through SSIS. The caveat is that I am using Posh-SSH as an add-on module. The Powershell script connects to a server via SSH, runs a command and captures the results. It works fine when I run it manually in Powershell or from the command prompt. When I run it through SSIS, I get this error: Error: The 'New-SSHSession' command was found in the module 'Posh-SSH', but the module could not be loaded. For more information, run 'Import-Module Posh-SSH'.. I am running this in Visual Studio, so it is executing under my account. Does anyone have any idea why the Powershell configuration would be different in Visual Studio vs power shell prompt? I have tried using Cozy Roc Powershell task TaskFactory Powershell task Execute Process Task Thank you in advance894Views0likes0CommentsHelp I messed up Visual Studio Code and Connect-SPOService
Hello, Trying to connect to SPO in Powershell. It works in the ISE, does not in VSCode In VScode I tried this and got: Connect-SPOService -url https://<Tenant-admin>.sharepoint.com Connect-SPOService: The term 'Connect-SPOService' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. I have done the following Uninstalled SharePoint Online Management Shell Reinstalled it Went into VScode did an Install-Module Microsoft.Online.SharePoint.PowerShell: WARNING: Version '16.0.22111.0' of module 'Microsoft.Online.SharePoint.PowerShell' is already installed at 'C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell'. To install version '16.0.22111.12000', run Install-Module and add the -Force parameter, this command will install version '16.0.22111.12000' side-by-side with version '16.0.22111.0'. Tried this: get-module | select version,name,path and get this Version Name Path ------- ---- ---- 7.0.0.0 Microsoft.PowerShell.Management C:\program files\powershell\7\Modules\Microsoft.PowerShell.Management\Microsoft.PowerShell.Management.psd1 7.0.0.0 Microsoft.PowerShell.Utility C:\program files\powershell\7\Modules\Microsoft.PowerShell.Utility\Microsoft.PowerShell.Utility.psd1 2.6.0 MicrosoftTeams C:\Program Files\WindowsPowerShell\Modules\MicrosoftTeams\2.6.0\MicrosoftTeams.psm1 1.4.7 PackageManagement C:\program files\powershell\7\Modules\PackageManagement\PackageManagement.psm1 2.2.5 PowerShellGet C:\program files\powershell\7\Modules\PowerShellGet\PSModule.psm1 2.1.0 PSReadLine C:\program files\powershell\7\Modules\PSReadLine\PSReadLine.psm1 0.0 SetMSTeamsReleaseEnvironment C:\Program Files\WindowsPowerShell\Modules\MicrosoftTeams\2.6.0\SetMSTeamsReleaseEnvironment.ps1 In the ISE where it works: PS C:\WINDOWS\system32> get-module | select version,name,path Version Name Path ------- ---- ---- 16.0.21411.12000 Microsoft.Online.SharePoint.PowerShell C:\Users\<USER>\Documents\WindowsPowerShell\Modules\Microsoft.Online.SharePoint.PowerShell\16.0.21411.12000\Microsoft.Online.SharePoint.PowerShell.dll 3.1.0.0 Microsoft.PowerShell.Management C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.Management\Microsoft.PowerShell.Management.psd1 3.1.0.0 Microsoft.PowerShell.Utility C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.Utility\Microsoft.PowerShell.Utility.psd1 2.0.0 PSReadline C:\Program Files\WindowsPowerShell\Modules\PSReadline\2.0.0\PSReadLine.psm1 ISE PS version: Name Value ---- ----- PSVersion 5.1.19041.1320 PSEdition Desktop PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...} BuildVersion 10.0.19041.1320 CLRVersion 4.0.30319.42000 WSManStackVersion 3.0 PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1 VScode PS Name Value ---- ----- PSVersion 7.2.1 PSEdition Core GitCommitId 7.2.1 OS Microsoft Windows 10.0.19044 Platform Win32NT PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…} PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1 WSManStackVersion 3.0 Looks like have two versions of PS and only 1 that likes Connect-SPOService. Help? Thanks, V6.4KViews0likes7CommentsButtons and Event Handlers
I am trying to utilize Powershell Protools to create a windows form so that user input can be used to create an account in AD, I have the form, and want to test it. My issue is I cannot seem to find/figure out how to properly configure the buttons to do as they are labeled. See code below: $Form1 = New-Object -TypeName System.Windows.Forms.Form [System.Windows.Forms.DateTimePicker]$DateTimePicker1 = $null [System.Windows.Forms.TextBox]$PHONE_NUMBER = $null [System.Windows.Forms.TextBox]$USER_ID = $null [System.Windows.Forms.TextBox]$RANK_STATUS = $null [System.Windows.Forms.TextBox]$OFFICE = $null [System.Windows.Forms.TextBox]$JOB_TITLE = $null [System.Windows.Forms.TextBox]$EMAIL = $null [System.Windows.Forms.TextBox]$LAST_NAME = $null [System.Windows.Forms.TextBox]$USERNAME = $null [System.Windows.Forms.TextBox]$MIDDLE_INITAL = $null [System.Windows.Forms.TextBox]$FIRST_NAME = $null function InitializeComponent { $DateTimePicker1 = (New-Object -TypeName System.Windows.Forms.DateTimePicker) $PHONE_NUMBER = (New-Object -TypeName System.Windows.Forms.TextBox) $USER_ID = (New-Object -TypeName System.Windows.Forms.TextBox) $RANK_STATUS = (New-Object -TypeName System.Windows.Forms.TextBox) $OFFICE = (New-Object -TypeName System.Windows.Forms.TextBox) $JOB_TITLE = (New-Object -TypeName System.Windows.Forms.TextBox) $EMAIL = (New-Object -TypeName System.Windows.Forms.TextBox) $LAST_NAME = (New-Object -TypeName System.Windows.Forms.TextBox) $USERNAME = (New-Object -TypeName System.Windows.Forms.TextBox) $MIDDLE_INITAL = (New-Object -TypeName System.Windows.Forms.TextBox) $FIRST_NAME = (New-Object -TypeName System.Windows.Forms.TextBox) $Form1.SuspendLayout() # #DateTimePicker1 # $DateTimePicker1.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]128,[System.Int32]350)) $DateTimePicker1.Name = [System.String]'DateTimePicker1' $DateTimePicker1.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]163,[System.Int32]21)) $DateTimePicker1.TabIndex = [System.Int32]3 # #PHONE_NUMBER # $PHONE_NUMBER.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]212,[System.Int32]230)) $PHONE_NUMBER.Name = [System.String]'PHONE_NUMBER' $PHONE_NUMBER.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]161,[System.Int32]21)) $PHONE_NUMBER.TabIndex = [System.Int32]4 $PHONE_NUMBER.Text = [System.String]'Phone Number' # #USER_ID # $USER_ID.BackColor = [System.Drawing.SystemColors]::Window $USER_ID.Font = (New-Object -TypeName System.Drawing.Font -ArgumentList @([System.String]'Tahoma',[System.Single]8.25)) $USER_ID.ForeColor = [System.Drawing.SystemColors]::WindowText $USER_ID.ImeMode = [System.Windows.Forms.ImeMode]::NoControl $USER_ID.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]25,[System.Int32]230)) $USER_ID.Name = [System.String]'USER_ID' $USER_ID.RightToLeft = [System.Windows.Forms.RightToLeft]::No $USER_ID.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]161,[System.Int32]21)) $USER_ID.TabIndex = [System.Int32]4 $USER_ID.Text = [System.String]'User ID' # #RANK_STATUS # $RANK_STATUS.BackColor = [System.Drawing.SystemColors]::Window $RANK_STATUS.Font = (New-Object -TypeName System.Drawing.Font -ArgumentList @([System.String]'Tahoma',[System.Single]8.25)) $RANK_STATUS.ForeColor = [System.Drawing.SystemColors]::WindowText $RANK_STATUS.ImeMode = [System.Windows.Forms.ImeMode]::NoControl $RANK_STATUS.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]212,[System.Int32]283)) $RANK_STATUS.Name = [System.String]'RANK_STATUS' $RANK_STATUS.RightToLeft = [System.Windows.Forms.RightToLeft]::No $RANK_STATUS.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]161,[System.Int32]21)) $RANK_STATUS.TabIndex = [System.Int32]4 $RANK_STATUS.Text = [System.String]'Rank/Status CTR, CIV, NFG' # #OFFICE # $OFFICE.BackColor = [System.Drawing.SystemColors]::Window $OFFICE.Font = (New-Object -TypeName System.Drawing.Font -ArgumentList @([System.String]'Tahoma',[System.Single]8.25)) $OFFICE.ForeColor = [System.Drawing.SystemColors]::WindowText $OFFICE.ImeMode = [System.Windows.Forms.ImeMode]::NoControl $OFFICE.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]26,[System.Int32]283)) $OFFICE.Name = [System.String]'OFFICE' $OFFICE.RightToLeft = [System.Windows.Forms.RightToLeft]::No $OFFICE.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]161,[System.Int32]21)) $OFFICE.TabIndex = [System.Int32]4 $OFFICE.Text = [System.String]'Office' # #JOB_TITLE # $JOB_TITLE.BackColor = [System.Drawing.SystemColors]::Window $JOB_TITLE.Font = (New-Object -TypeName System.Drawing.Font -ArgumentList @([System.String]'Tahoma',[System.Single]8.25)) $JOB_TITLE.ForeColor = [System.Drawing.SystemColors]::WindowText $JOB_TITLE.ImeMode = [System.Windows.Forms.ImeMode]::NoControl $JOB_TITLE.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]25,[System.Int32]173)) $JOB_TITLE.Name = [System.String]'JOB_TITLE' $JOB_TITLE.RightToLeft = [System.Windows.Forms.RightToLeft]::No $JOB_TITLE.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]161,[System.Int32]21)) $JOB_TITLE.TabIndex = [System.Int32]4 $JOB_TITLE.Text = [System.String]'Job Title' # #EMAIL # $EMAIL.BackColor = [System.Drawing.SystemColors]::Window $EMAIL.Font = (New-Object -TypeName System.Drawing.Font -ArgumentList @([System.String]'Tahoma',[System.Single]8.25)) $EMAIL.ForeColor = [System.Drawing.SystemColors]::WindowText $EMAIL.ImeMode = [System.Windows.Forms.ImeMode]::NoControl $EMAIL.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]212,[System.Int32]173)) $EMAIL.Name = [System.String]'EMAIL' $EMAIL.RightToLeft = [System.Windows.Forms.RightToLeft]::No $EMAIL.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]161,[System.Int32]21)) $EMAIL.TabIndex = [System.Int32]4 $EMAIL.Text = [System.String]'Email' # #LAST_NAME # $LAST_NAME.BackColor = [System.Drawing.SystemColors]::Window $LAST_NAME.Font = (New-Object -TypeName System.Drawing.Font -ArgumentList @([System.String]'Tahoma',[System.Single]8.25)) $LAST_NAME.ForeColor = [System.Drawing.SystemColors]::WindowText $LAST_NAME.ImeMode = [System.Windows.Forms.ImeMode]::NoControl $LAST_NAME.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]25,[System.Int32]118)) $LAST_NAME.Name = [System.String]'LAST_NAME' $LAST_NAME.RightToLeft = [System.Windows.Forms.RightToLeft]::No $LAST_NAME.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]161,[System.Int32]21)) $LAST_NAME.TabIndex = [System.Int32]4 $LAST_NAME.Text = [System.String]'Last Name' # #USERNAME # $USERNAME.BackColor = [System.Drawing.SystemColors]::Window $USERNAME.Font = (New-Object -TypeName System.Drawing.Font -ArgumentList @([System.String]'Tahoma',[System.Single]8.25)) $USERNAME.ForeColor = [System.Drawing.SystemColors]::WindowText $USERNAME.ImeMode = [System.Windows.Forms.ImeMode]::NoControl $USERNAME.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]212,[System.Int32]118)) $USERNAME.Name = [System.String]'USERNAME' $USERNAME.RightToLeft = [System.Windows.Forms.RightToLeft]::No $USERNAME.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]161,[System.Int32]21)) $USERNAME.TabIndex = [System.Int32]4 $USERNAME.Text = [System.String]'Username' # #MIDDLE_INITAL # $MIDDLE_INITAL.BackColor = [System.Drawing.SystemColors]::Window $MIDDLE_INITAL.Font = (New-Object -TypeName System.Drawing.Font -ArgumentList @([System.String]'Tahoma',[System.Single]8.25)) $MIDDLE_INITAL.ForeColor = [System.Drawing.SystemColors]::WindowText $MIDDLE_INITAL.ImeMode = [System.Windows.Forms.ImeMode]::NoControl $MIDDLE_INITAL.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]212,[System.Int32]61)) $MIDDLE_INITAL.Name = [System.String]'MIDDLE_INITAL' $MIDDLE_INITAL.RightToLeft = [System.Windows.Forms.RightToLeft]::No $MIDDLE_INITAL.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]161,[System.Int32]21)) $MIDDLE_INITAL.TabIndex = [System.Int32]4 $MIDDLE_INITAL.Text = [System.String]'Middle Initial' # #FIRST_NAME # $FIRST_NAME.BackColor = [System.Drawing.SystemColors]::Window $FIRST_NAME.Font = (New-Object -TypeName System.Drawing.Font -ArgumentList @([System.String]'Tahoma',[System.Single]8.25)) $FIRST_NAME.ForeColor = [System.Drawing.SystemColors]::WindowText $FIRST_NAME.ImeMode = [System.Windows.Forms.ImeMode]::NoControl $FIRST_NAME.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]26,[System.Int32]61)) $FIRST_NAME.Name = [System.String]'FIRST_NAME' $FIRST_NAME.RightToLeft = [System.Windows.Forms.RightToLeft]::No $FIRST_NAME.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]161,[System.Int32]21)) $FIRST_NAME.TabIndex = [System.Int32]4 $FIRST_NAME.Text = [System.String]'First Name' # #Form1 # $Form1.ClientSize = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]430,[System.Int32]453)) $Form1.Controls.Add($PHONE_NUMBER) $Form1.Controls.Add($DateTimePicker1) $Form1.Controls.Add($USER_ID) $Form1.Controls.Add($RANK_STATUS) $Form1.Controls.Add($OFFICE) $Form1.Controls.Add($JOB_TITLE) $Form1.Controls.Add($EMAIL) $Form1.Controls.Add($LAST_NAME) $Form1.Controls.Add($USERNAME) $Form1.Controls.Add($MIDDLE_INITAL) $Form1.Controls.Add($FIRST_NAME) $Form1.Text = [System.String]'Account Creation' $Form1.ResumeLayout($false) $Form1.PerformLayout() Add-Member -InputObject $Form1 -Name base -Value $base -MemberType NoteProperty Add-Member -InputObject $Form1 -Name DateTimePicker1 -Value $DateTimePicker1 -MemberType NoteProperty Add-Member -InputObject $Form1 -Name PHONE_NUMBER -Value $PHONE_NUMBER -MemberType NoteProperty Add-Member -InputObject $Form1 -Name USER_ID -Value $USER_ID -MemberType NoteProperty Add-Member -InputObject $Form1 -Name RANK_STATUS -Value $RANK_STATUS -MemberType NoteProperty Add-Member -InputObject $Form1 -Name OFFICE -Value $OFFICE -MemberType NoteProperty Add-Member -InputObject $Form1 -Name JOB_TITLE -Value $JOB_TITLE -MemberType NoteProperty Add-Member -InputObject $Form1 -Name EMAIL -Value $EMAIL -MemberType NoteProperty Add-Member -InputObject $Form1 -Name LAST_NAME -Value $LAST_NAME -MemberType NoteProperty Add-Member -InputObject $Form1 -Name USERNAME -Value $USERNAME -MemberType NoteProperty Add-Member -InputObject $Form1 -Name MIDDLE_INITAL -Value $MIDDLE_INITAL -MemberType NoteProperty Add-Member -InputObject $Form1 -Name FIRST_NAME -Value $FIRST_NAME -MemberType NoteProperty } . InitializeComponent1.1KViews0likes1CommentPowerShell Automation for Verifying MST
Just finished putting together a script to Apply an MST to an MSI then read out the property table. This is for an automation process to verify a submited MSI and MST meet our packaging standards. Need a little sanity check as working with COM objects is not a strong point for me. Really want to make sure I am closing the files correctly after applying the transform then querying the database. I wasn't able to delete the temp files running in Powershell ISE until I did the ReleaseComObject. I didn't have to do that when working with the straight MSI and just pull the properties from it so I hope this is not corrupting any files. # Apply MST to an MSI # Based on Code from: https://hinchley.net/articles/update-cab-file-and-msi-transform-via-command-line/ $SourceMSI = "C:\Temp\MSI\MSI-x64.msi" $SourceMST = "C:\Temp\MSI\MSI.mst" $TempMSI = "$SourceMSI.tmp" $TempMST = "$SourceMST.tmp" Copy-Item $SourceMSI $TempMSI -Force Copy-Item $SourceMST $TempMST -Force $WindowsInstaller = New-Object -ComObject WindowsInstaller.Installer #Open the database in Direct read/write without Transaction (2) $MSIDatabase1 = $WindowsInstaller.GetType().InvokeMember('OpenDatabase' , 'InvokeMethod' , $Null, $WindowsInstaller, @($TempMSI, 2)) #$MSIDatabase1.applytransform($TempMST, 0) $MSIDatabase1.GetType().InvokeMember('ApplyTransform' , 'InvokeMethod' , $Null , $MSIDatabase1 , @($TempMST, 0)) $Query = ("SELECT Property,Value FROM Property") #Opens a data view to the MSI based on the query created. $View = $MSIDatabase1.GetType().InvokeMember('OpenView', 'InvokeMethod', $null, $MSIDatabase1, ($Query)) $null = $View.GetType().InvokeMember('Execute', 'InvokeMethod', $null, $View, $null) $hash = @{} # Add File information (Note this adds the full File information Porperties so can call with <Var>.File |Select * $hash.Add('File',$TempMSI) WHILE ($Record = $View.GetType().InvokeMember('Fetch', 'InvokeMethod', $null, $View, $null)) { $name = $Record.GetType().InvokeMember('StringData', 'GetProperty', $null, $Record, 1) $value = $hashMSIValue = $Record.GetType().InvokeMember('StringData', 'GetProperty', $null, $Record, 2) $hash.Add($name,$value) } # Push Hash table into a PSCustom object $msiProperties = [pscustomobject]$hash # I'm not sure If I have everything required to close out here properly from applying the transform. $null = $MSIDatabase1.GetType().InvokeMember('Commit' , 'InvokeMethod' , $Null , $MSIDatabase1 , $Null) $null = $view.GetType().InvokeMember('Close', 'InvokeMethod', $null, $view, $null) # Really important part to be able to release the opened files and delete $null = [Runtime.Interopservices.Marshal]::ReleaseComObject($view) $null = [Runtime.Interopservices.Marshal]::ReleaseComObject($MSIDatabase1) $null = [Runtime.Interopservices.Marshal]::ReleaseComObject($WindowsInstaller) [GC]::Collect()2.1KViews0likes0CommentsMicrosoftTeams cmdlets not working with AccessToken
I am trying to run cmdlets from powershell module MicrosoftTeams (version 2.0.0) in a C# web application. I am using Authorization code flow and code from the answer provided in this post to acquire token: Acquire AAD token using ASP.Net web forms. Note: I had changed resource in the code to graph.windows.net to acquire AAD token. Token is acquired by using AuthenticationContext.AcquireTokenByAuthorizationCodeAsync method. Once the token is acquired, I run the following lines to create a powershell instance in C# and to import MicrosoftTeams Module. PowerShell pshell InitialSessionState iss; iss = InitialSessionState.CreateDefault2(); iss.ImportPSModule(new[] { "MicrosoftTeams" }); pshell = PowerShell.Create(iss); Then to connect with MicrosoftTeams, I run the following code: var connectCmd = new Command("Connect-MicrosoftTeams"); connectCmd.Parameters.Add("AadAccessToken", AccessToken); connectCmd.Parameters.Add("AccountId", "xxxxxxx@xxxxxx.onmicrosoft.com"); pshell.Commands.AddCommand(connectCmd); var result1 = pshell.Invoke(); Code works fine till here. After this I clear the shell commands and invoke the Get-CsTeamsCallingPolicy cmdlet: pshell.Commands.Clear(); pshell.Streams.Error.Clear(); pshell.AddScript("Get-CsTeamsCallingPolicy"); var result2 = pshell.Invoke(); After Invoke, I get an exception and this dialog pops up: Pressing 'Continue' brings back the same dialogue a couple of times. Exception details from this screen are: System.Collections.Generic.KeyNotFoundException was unhandled by user code HResult=-2146232969 Message=The given key was not present in the dictionary. Source=mscorlib StackTrace: at System.Collections.Concurrent.ConcurrentDictionary`2.get_Item(TKey key) at Microsoft.TeamsCmdlets.Powershell.Connect.Models.AzureSessionProvider.GetAccessToken(String resource, IEnumerable`1 scopes) in D:\a\1\s\src\Microsoft.TeamsCmdlets.PowerShell.Connect\Models\AzureSession.cs:line 80 at Microsoft.TeamsCmdlets.Powershell.Connect.TeamsPowerShellSession.GetAccessToken(String resource, IEnumerable`1 scopes) in D:\a\1\s\src\Microsoft.TeamsCmdlets.PowerShell.Connect\TeamsPowerShellSession.cs:line 82 at Microsoft.TeamsCmdlets.PowerShell.Connect.GetCsInternalAccessToken.ProcessRecord() in D:\a\1\s\src\Microsoft.TeamsCmdlets.PowerShell.Connect\GetCsInternalAccessToken.cs:line 61 at System.Management.Automation.CommandProcessor.ProcessRecord() After pressing continue for the 3rd time, control goes back to C# code, and I receive the following runtime exception: Exception calling "GetSteppablePipeline" with "1" argument(s): "Exception calling "GetRemoteNewCsOnlineSession" with "1" argument(s): "Run either Connect-MicrosoftTeams or new-csonlinesession before running cmdlets."" Trying to run this logic from the powershell editor shows similar behavior: Running the following two lines: $AccessToken = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' Connect-MicrosoftTeams -AadAccessToken $AccessToken -AccountId 'xxxxxxx@xxxxxx.onmicrosoft.com' gives this result: Account Environment Tenant TenantId ------- ----------- ------ -------- xxxxxxx@xxxxxx.onmicrosoft.com AzureCloud xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx I then run Get-Team cmdlet: Get-Team -User xxxxxxx@xxxxxxx.onmicrosoft.com which results in this message: Get-Team : The given key was not present in the dictionary. At line:1 char:1 + Get-Team -User xxxxxxx@xxxxxxx.onmicrosoft.com + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Get-Team], KeyNotFoundException + FullyQualifiedErrorId : System.Collections.Generic.KeyNotFoundException,Microsoft.TeamsCmdlets.PowerShell.Custom.GetTeam Running cmdlet Get-CsTeamsCallingPolicy yields this: Exception calling "GetSteppablePipeline" with "1" argument(s): "Exception calling "GetRemoteNewCsOnlineSession" with "1" argument(s): "Run either Connect-MicrosoftTeams or new-csonlinesession before running cmdlets."" At C:\Program Files\WindowsPowerShell\Modules\MicrosoftTeams\2.0.0\net472\SfBORemotePowershellModule.psm1:11369 char:13 + $steppablePipeline = $scriptCmd.GetSteppablePipeline($myI ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : CmdletInvocationException If I run Connect-MicrosoftTeams directly from powershell without providing access token and accountid, I get the login screens and after login everything works fine i.e. I can run Get-Team and Get-CsTeamsCallingPolicy cmdlets successfully but I don't get this behavior when working with AadAccessToken. All the above code works fine if connecting to AzureAD module via Connect-AzureAD cmdlet like this both in web application and powershell editor: Connect-AzureAD -AadAccessToken $AccessToken -AccountId 'xxxxxxx@xxxxxxx.onmicrosoft.com' If someone has faced and successfully resolved this issue or have some tips on how to resolve this, please help. I have already tried a lot of things including searching for the specific exception messages and any possible solutions but found nothing that could help in this particular scenario, installed the latest version of MSTeams module, the previous version was old and did not have all the cmdlets that I am looking to work with. I installed the preview version of MSTeams module also to see if this issue is fixed in the upcoming release. Uninstalled the deprecated SkypeForBuisnessOnline Connector module, updated windows and so on. If you look at Example 4 in the Microsoft documentation for Connect-MicrosoftTeams, this is what I am trying to achieve.2.1KViews1like5Comments