Office Exporting a variable of objects RRS feed

  • General discussion

  • I am working on a project where I want to export specific information of Get-MsolUser which I want to choose with Select-Object. Which objects I want to export I select in my Windows Form. Same goes for the output location. For export format I am using a custom module named ImportExcel and for Office 365 connection I am using the msonline module.

    I am trying to export the objects to the excel but instead of getting just the selected objects I get all of them exported.

    Does anyone have a clue what I am missing.

    $StartExportButton_Click_1 = {
    $WorkSheetName = 'Users'
    $ExcelPath = $ExcelBestandTextBox.Text
    If ($UserPrincipalNameExButton.Checked -eq $true ) {$SelectUserObjects += "UserPrincipalName"}
    If ($DisplayNameExButton.Checked -eq $true ) {$SelectUserObjects += "DisplayName"}
    If ($FirstNameExButton.Checked -eq $true ) {$SelectUserObjects += "FirstName"}
    If ($LastNameExButton.Checked -eq $true ) {$SelectUserObjects +=  "LastName"}
    If ($CountryExButton.Checked -eq $true ) {$SelectUserObjects +=  "Country"}
    If ($IsLicensedExButton.Checked -eq $true ) {$SelectUserObjects +=  "IsLicensed"}
    Get-MsolUser |Format-Table $SelectUserObjects
    $Result = Get-MsolUser |Select-Object $SelectUserObjects
    $Result | Export-Excel -Path $ExcelPath -WorkSheetname $WorkSheetName

    The $StartExportButton_Click_1 variable is what triggers the code. (From Windows Form)
    VariableName.Checked is a checkbox status. (From Windows Form)
    The $ExcelPath is defined. (From Windows Form)

    Wednesday, March 7, 2018 10:20 AM

All replies

  • What is $SelectedObjects2.  It is not  defined anywhere.


    Wednesday, March 7, 2018 5:42 PM
  • Excuse me my bad I changed the variable names before posting it on technet to make sure they make a bit more sense then they do. Messed up changing names there.

    • Edited by Bill_Stewart Thursday, March 8, 2018 3:17 PM Remove profanity
    Thursday, March 8, 2018 3:41 AM
  • Please refrain from profanity; thanks.

    -- Bill Stewart [Bill_Stewart]

    Thursday, March 8, 2018 3:17 PM
  • Hello Bill,

    My apology, it's a matter of habit. I'll watch it better next time.

    Friday, March 9, 2018 9:26 AM