none
Passing A Variable In PowerShell That Contains Parentheses RRS feed

  • General discussion

  • I'm using a drop down list to select Display Names from AD. I then need the samAccountName

    This is working well for everyone except one user who has parentheses in the AD display name

    I made some changes to allow for an apostrophe i.e. John O'Doyle, but I now have a user who likes to have their full and preferred name in there. i.e. Virginia (Ginny) Doe

    Here is my code:

    $PersonOnLeaveValue = $PersonOnLeave.SelectedItem

    #Write-Host $PersonOnLeaveValue <- Correct value is shown here 'Virginia (Ginny) Doe'

    $PersonOnLeaveUsername = (Get-ADUser -Filter {Name -like $PersonOnLeaveValue} -Properties *).samAccountName

    #Write-Host $PersonOnLeaveUsername <- Blank. So I guess no match?

    Any ideas would be greatly appreciated :)

    Wednesday, May 13, 2015 11:34 PM

All replies

  • You have to escape all special characters.

    Virginia \(Ginny\) Doe


    \_(ツ)_/

    Thursday, May 14, 2015 12:08 AM
  • Hint -  load the listbox with user objects and set displaymember.  That way you do not have to go back and get the user a second time.


    \_(ツ)_/

    Thursday, May 14, 2015 12:09 AM
  • Hint -  load the listbox with user objects and set displaymember.  That way you do not have to go back and get the user a second time.


    \_(ツ)_/

    I'm not using a second list. I'm actually writing the samAccountName ($PersonOnLeaveUsername) to a csv file along with some other info. I could have the list of samAccountNames in the drop down list but its I find it better to have the display name to avoid any confusion.
    Thursday, May 14, 2015 12:24 AM
  • You have to escape all special characters.

    Virginia \(Ginny\) Doe


    \_(ツ)_/

    But I am getting that from AD so I can't add them in like that
    Thursday, May 14, 2015 12:25 AM
  • The "(" and ")" characters do not need to be escaped in Active Directory, or PowerShell. They do need to be escaped in LDAP filters (replaced by "\28" and "\29"), but you are not using LDAP here. I was able to use the following in my domain with no problem:

    Get-ADUser -Filter {Name -Like "James (Junior) Smith"}

    It also worked with the -eq operator, which makes more sense in this case. So, something else is going on.

    Richard Mueller - MVP Directory Services

    Thursday, May 14, 2015 12:25 AM
    Moderator
  • # load combo
    $combobox.Datasource=[system.collections.arraylist](Get-Aduser -filter *)
    $combobox.DisplayMember='Name'

    # onselecteditem changed event
    $samaccountname=$combobox.SelectemItem.SamAccountName

    That is all you have to do.  That is how the system is designed to work.


    \_(ツ)_/

    Thursday, May 14, 2015 12:33 AM
  • If you would use the combobox correctly you wouldn't have this issue at all.  The combobox would contain the user object that was selected.  As I noted above this is how list controls in Windows are designed to work.


    \_(ツ)_/

    Thursday, May 14, 2015 12:42 AM
  • You can add as many use properties to the Get-AdUser properties and they will all be available on SelectedItem.


    \_(ツ)_/

    Thursday, May 14, 2015 12:58 AM
  • Did you try:

    $PersonOnLeaveUsername = (Get-ADUser -Filter {Name -like "Virginia (Ginny) Doe"}).samAccountName

    I have a user with cn equal to "James (Junior) Smith", I assume you do not. If you have a user with cn equal to "Virginia (Ginny) Doe", then the above will work. Note, no need to retrieve all attribute values with the -Properties parameter, the sAMAccountName is a default property, so you will always have it.

    If the combo box has a reference to all user objects, as I think jrv's suggestion does, then all of this is unnecessary, but my point is that the parentheses are not the problem.

    Or, is the problem that the string "Virginia (Ginny) Doe" is not assigned to the cn attribute, but to the displayName attribute? The "Name" property is the Relative Distinguished Name of the object, which for user objects is the value of the cn (Common Name) attribute.


    Richard Mueller - MVP Directory Services


    Thursday, May 14, 2015 1:04 AM
    Moderator
  • Did you try:

    $PersonOnLeaveUsername = (Get-ADUser -Filter {Name -like "Virginia (Ginny) Doe"}).samAccountName

    I have a user with cn equal to "James (Junior) Smith", I assume you do not. If you have a user with cn equal to "Virginia (Ginny) Doe", then the above will work. Note, no need to retrieve all attribute values with the -Properties parameter, the sAMAccountName is a default property, so you will always have it.

    If the combo box has a reference to all user objects, as I think jrv's suggestion does, then all of this is unnecessary, but my point is that the parentheses are not the problem.

    Or, is the problem that the string "Virginia (Ginny) Doe" is not assigned to the cn attribute, but to the displayName attribute?


    Richard Mueller - MVP Directory Services

    Yeah, I tried your suggestion and it still came back blank.

    The cn=Ginny Doe, displayName=Virginia (Ginny) Doe. Maybe I could just update the cn?

    Thursday, May 14, 2015 1:09 AM
  • Try this:

    $Users=Get-ADUser -Filter * -SearchBase "ou=People,dc=domain,dc=local" -Properties *
    # no need to sort as you can set the sort property of the combobox.

    $PersonOnLeave .DataSource=[system.collections.arraylist]$users
    $PersonOnLeave .DispalyMember='Name'

    Now you can reference all of the properties in Selecteditem which is the full user object.

    Learning this can cut the amount of code in half or better.



    \_(ツ)_/

    Thursday, May 14, 2015 1:13 AM
  • Try this:

    $Users=Get-ADUser -Filter * -SearchBase "ou=People,dc=domain,dc=local" -Properties *
    # no need to sort as you can set the sort property of the combobox.

    $PersonOnLeave .DataSource=[system.collections.arraylist]$users
    $PersonOnLeave .DispalyMember='Name'

    Now you can reference all of the properties in Selecteditem which is the full user object.

    Learning this can cut the amount of code in half or better.



    \_(ツ)_/

    Sorry. Still not sure where I'm entering this info.

    I changed the start to:

    $Users=Get-ADUser -Filter * -SearchBase "ou=People,dc=nci,dc=local" -Properties *
    $Select=ForEach ($Name in $Users) {Write-Output $Name.DisplayName}

    $PersonOnLeave = New-Object System.Windows.Forms.ComboBox
    $PersonOnLeave.Location = New-Object System.Drawing.Size(110,40)
    $PersonOnLeave.Size = New-Object System.Drawing.Size(220,30)
    $PersonOnLeave.DataSource=[system.collections.arraylist]$Users
    $PersonOnLeave.DispalyMember='Name'
    $Form.Controls.Add($PersonOnLeave)

    The property 'DispalyMember' cannot be found on this object. Verify that the property exists and can be set.
    At S:\Email\MailboxSharingMaintenance-GinnyFix.ps1:69 char:1
    + $PersonOnLeave.DispalyMember='Name'
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
        + FullyQualifiedErrorId : PropertyAssignmentException

    The form opens with as list of cn in the drop down sorted by the date they were created

    Thursday, May 14, 2015 1:29 AM
  • You spelled it wrong:

    $PersonOnLeave.DispalyMember='Name' ?????


    \_(ツ)_/

    Thursday, May 14, 2015 2:14 AM
  • You spelled it wrong:

    $PersonOnLeave.DispalyMember='Name' ?????


    \_(ツ)_/

    I actually copied and pasted what you typed :)

    Ok, I'm getting somewhere now.

    $PersonOnLeaveUsername = $PersonOnLeave.SelectedItem.SamAccountName

    Looks good now!

    Just a couple things now. Can I set the combo box to a blank first item? Also it's sorted by the date the account was created.

    Thursday, May 14, 2015 2:24 AM
  • This will sort by the displayed member

    $PersonOnLeave.Sorted=$true

    Combobox should be unselected by default,

    $PersonOnLeave.SelectedIndex=-1


    \_(ツ)_/


    • Edited by jrv Thursday, May 14, 2015 2:47 AM
    Thursday, May 14, 2015 2:44 AM
  • This will sort by the displayed member

    $PersonOnLeave.Sorted=$true

    Combobox should be unselected by default,

    $PersonOnLeave.SelectedIndex=-1


    \_(ツ)_/


    The sorting didn't seem to work. Gave the following error:

    Exception setting "Sorted": "ComboBox that has a DataSource set cannot be sorted. Sort the data using the underlying data model.

    So I added the Sorting at the input again.

    $Users=Get-ADUser -Filter * -SearchBase "ou=People,dc=domain,dc=local" | Sort-Object Name

    For some reason this doesn't seem to work anymore:

    $PersonOnLeave.SelectedIndex=-1

    Even when I reset the form after submitting a request it still goes to the first name in our AD (not a big issue)

    Here is the updated code I now use and seems to have bypass the issue of parentheses in the display name

    # Get list of users from AD
    $Users=Get-ADUser -Filter * -SearchBase "ou=People,dc=domain,dc=local" | Sort-Object Name
    
    # Write dates and usernames to csv file
    Function Submit-FullAccess {
    
     $StartDateValue = ($StartDate.Value).ToShortDateString()
     $PersonOnLeaveUsername = $PersonOnLeave.SelectedItem.SamAccountName
     $GiveAccessToUsername = $GiveAccessTo.SelectedItem.SamAccountName
     $RemoveDateValue = ($RemoveDate.Value).ToShortDateString()
     
     $NewSharing = '"' + $StartDateValue + '","' + $PersonOnLeaveUsername + '","' + $GiveAccessToUsername + '","' + $RemoveDateValue + '"'
     Out-File -FilePath FileSystem::\\domain.local\Data\ADE-Shared\Email\MailboxSharing_Scheduled.csv -InputObject $NewSharing -Append -Encoding ascii
    
     $PersonOnLeave.SelectedIndex = -1
     $GiveAccessTo.SelectedIndex = -1
    }
    
    # Select user by cn combo box
    $PersonOnLeave = New-Object System.Windows.Forms.ComboBox
    $PersonOnLeave.Location = New-Object System.Drawing.Size(110,40)
    $PersonOnLeave.Size = New-Object System.Drawing.Size(220,30)
    $PersonOnLeave.DataSource=[system.collections.arraylist]$Users
    $PersonOnLeave.DisplayMember='Name'
    $Form.Controls.Add($PersonOnLeave)

    Thursday, May 14, 2015 3:49 AM
  • Sorted has to be set before you load the box.  It will sort while it loads.  After it is "bound" you cannot change the sorted state.


    \_(ツ)_/

    Thursday, May 14, 2015 5:02 AM
  • .SelectedIndex=-1 works fine if you set it correctly.  It is likely you are not defining your form correctly.

    Here is a demo oof how the CB works with sort and setting oor resetting the CB to unselected.  If you run it you will see that it works correctly.  It just loads all users.  If you have a lot of users you can alter the filter or searchbase.

    function Call-Demo-ComboBox_psf {
        
        [void][reflection.assembly]::Load('System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
    
        [System.Windows.Forms.Application]::EnableVisualStyles()
        $form1 = New-Object 'System.Windows.Forms.Form'
        $buttonClear = New-Object 'System.Windows.Forms.Button'
        $combobox1 = New-Object 'System.Windows.Forms.ComboBox'
        $buttonOK = New-Object 'System.Windows.Forms.Button'
        $InitialFormWindowState = New-Object 'System.Windows.Forms.FormWindowState'
    
        $form1_Load = {
            $users = Get-AdUser -Filter *
    	$combobox1.DataSource=[System.Collections.ArrayList]$users
            $combobox1.DisplayMember = 'Name'
            $combobox1.SelectedIndex = -1
        }
        
        $buttonClear_Click = {
            $combobox1.SelectedIndex = -1
        }
        
        $Form_StateCorrection_Load = {
            $form1.WindowState = $InitialFormWindowState
        }
        
        $form1.SuspendLayout()
    
        # form1
        $form1.Controls.Add($buttonClear)
        $form1.Controls.Add($combobox1)
        $form1.Controls.Add($buttonOK)
        $form1.AcceptButton = $buttonOK
        $form1.ClientSize = '444, 364'
        $form1.FormBorderStyle = 'FixedDialog'
        $form1.MaximizeBox = $False
        $form1.MinimizeBox = $False
        $form1.Name = "form1"
        $form1.StartPosition = 'CenterScreen'
        $form1.Text = "Form"
        $form1.add_Load($form1_Load)
    
        # buttonClear
        $buttonClear.Location = '308, 28'
        $buttonClear.Name = "buttonClear"
        $buttonClear.Size = '75, 23'
        $buttonClear.TabIndex = 2
        $buttonClear.Text = "Clear"
        $buttonClear.UseVisualStyleBackColor = $True
        $buttonClear.add_Click($buttonClear_Click)
    
        # combobox1
        $combobox1.FormattingEnabled = $True
        $combobox1.Location = '24, 31'
        $combobox1.Name = "combobox1"
        $combobox1.Size = '255, 21'
        $combobox1.Sorted = $True
        $combobox1.TabIndex = 1
    
        # buttonOK
        $buttonOK.Anchor = 'Bottom, Right'
        $buttonOK.DialogResult = 'OK'
        $buttonOK.Location = '357, 329'
        $buttonOK.Name = "buttonOK"
        $buttonOK.Size = '75, 23'
        $buttonOK.TabIndex = 0
        $buttonOK.Text = "&OK"
        $buttonOK.UseVisualStyleBackColor = $True
    
        $form1.ResumeLayout()
        $InitialFormWindowState = $form1.WindowState
        $form1.add_Load($Form_StateCorrection_Load)
        return $form1.ShowDialog()
    }
    
    Call-Demo-ComboBox_psf

    All coode and declarations need to be inside oof the form or you will have issues of scope and correct execution.  If you use functions they should be decleared inside of the form function before the form is created (at the beginning).

    The comboboxes must be loaded in a form event and not before the form is displayed.  The form load event is a good place to do this.  By this I mean in a form event and not in the form controls creation code.  This rule can be relaxed once you understand what happens when a form is created/displayed and how the events fire and in what order.


    \_(ツ)_/




    • Edited by jrv Thursday, May 14, 2015 5:18 AM
    Thursday, May 14, 2015 5:14 AM
  • .SelectedIndex=-1 works fine if you set it correctly.  It is likely you are not defining your form correctly.

    Here is a demo oof how the CB works with sort and setting oor resetting the CB to unselected.  If you run it you will see that it works correctly.  It just loads all users.  If you have a lot of users you can alter the filter or searchbase.

    All coode and declarations need to be inside oof the form or you will have issues of scope and correct execution.  If you use functions they should be decleared inside of the form function before the form is created (at the beginning).

    The comboboxes must be loaded in a form event and not before the form is displayed.  The form load event is a good place to do this.  By this I mean in a form event and not in the form controls creation code.  This rule can be relaxed once you understand what happens when a form is created/displayed and how the events fire and in what order.


    \_(ツ)_/




    Thanks for your help jrv. All working great now. Here is my current code. Could I fool you to think I know what I'm doing now? :)

    Import-Module ActiveDirectory Function Call-Mailbox-Sharing_psf { [void][reflection.assembly]::Load('System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089') [System.Windows.Forms.Application]::EnableVisualStyles() $Form = New-Object 'System.Windows.Forms.Form' $StartDate = New-Object 'System.Windows.Forms.DateTimePicker' $PersonOnLeave = New-Object 'System.Windows.Forms.ComboBox' $GiveAccessTo = New-Object 'System.Windows.Forms.ComboBox' $RemoveDate = New-Object 'System.Windows.Forms.DateTimePicker' $StartDateLabel = New-Object 'System.Windows.Forms.Label' $PersonOnLeaveLabel = New-Object 'System.Windows.Forms.Label' $GiveAccessToLabel = New-Object 'System.Windows.Forms.Label' $RemoveDateLabel = New-Object 'System.Windows.Forms.Label' $SubmitFullButton = New-Object 'System.Windows.Forms.Button' $SubmitCopyButton = New-Object 'System.Windows.Forms.Button' $ShowScheduledFull = New-Object 'System.Windows.Forms.Button' $ShowActionedFull = New-Object 'System.Windows.Forms.Button' $ShowCompletedFull = New-Object 'System.Windows.Forms.Button' $ShowScheduledCopy = New-Object 'System.Windows.Forms.Button' $ShowActionedCopy = New-Object 'System.Windows.Forms.Button' $ShowCompletedCopy = New-Object 'System.Windows.Forms.Button' $CloseFormButton = New-Object 'System.Windows.Forms.Button' $InitialFormWindowState = New-Object 'System.Windows.Forms.FormWindowState' $Form_Load = { $Users=Get-ADUser -Filter * -SearchBase "ou=People,dc=domain,dc=local" $PersonOnLeave.DataSource=[system.collections.arraylist]$Users $PersonOnLeave.DisplayMember='Name' $PersonOnLeave.SelectedIndex = -1 $GiveAccessTo.DataSource=[system.collections.arraylist]$Users $GiveAccessTo.DisplayMember='Name' $GiveAccessTo.SelectedIndex = -1 } $Form_StateCorrection_Load = { $Form.WindowState = $InitialFormWindowState } $Form.SuspendLayout() # Form $Form.Controls.Add($StartDate) $Form.Controls.Add($PersonOnLeave) $Form.Controls.Add($GiveAccessTo) $Form.Controls.Add($RemoveDate) $Form.Controls.Add($StartDateLabel) $Form.Controls.Add($PersonOnLeaveLabel) $Form.Controls.Add($GiveAccessToLabel) $Form.Controls.Add($RemoveDateLabel) $Form.Controls.Add($SubmitFullButton) $Form.Controls.Add($SubmitCopyButton) $Form.Controls.Add($CloseFormButton) $Form.Controls.Add($ShowScheduledFull) $Form.Controls.Add($ShowActionedFull) $Form.Controls.Add($ShowCompletedFull) $Form.Controls.Add($ShowScheduledCopy) $Form.Controls.Add($ShowActionedCopy) $Form.Controls.Add($ShowCompletedCopy) $Form.Width = 650 $Form.Height = 200 $Form.StartPosition = "CenterScreen" $Form.Text = ”Submit A New Mailbox Sharing Request” $Form.Add_Load($Form_Load) # Submit Full Access Request $Submit_Full_Click = { $StartDateValue = ($StartDate.Value).ToShortDateString() $PersonOnLeaveUsername = $PersonOnLeave.SelectedItem.SamAccountName $GiveAccessToUsername = $GiveAccessTo.SelectedItem.SamAccountName $RemoveDateValue = ($RemoveDate.Value).ToShortDateString() Write-Host $StartDateValue","$PersonOnLeaveUsername","$GiveAccessToUsername","$RemoveDateValue",Full Access" $NewSharing = '"' + $StartDateValue + '","' + $PersonOnLeaveUsername + '","' + $GiveAccessToUsername + '","' + $RemoveDateValue + '"' Out-File -FilePath FileSystem::\\domain.local\Data\Shared\Email\MailboxSharing_Scheduled.csv -InputObject $NewSharing -Append -Encoding ascii $PersonOnLeave.SelectedIndex = -1 $GiveAccessTo.SelectedIndex = -1 } # Submit Copy Request $Submit_Copy_Click = { $StartDateValue = ($StartDate.Value).ToShortDateString() $PersonOnLeaveUsername = $PersonOnLeave.SelectedItem.SamAccountName $GiveAccessToUsername = $GiveAccessTo.SelectedItem.SamAccountName $RemoveDateValue = ($RemoveDate.Value).ToShortDateString() Write-Host $StartDateValue","$PersonOnLeaveUsername","$GiveAccessToUsername","$RemoveDateValue",Copy" $NewSharing = '"' + $StartDateValue + '","' + $PersonOnLeaveUsername + '","' + $GiveAccessToUsername + '","' + $RemoveDateValue + '"' Out-File -FilePath FileSystem::\\domain.local\Data\Shared\Email\MailboxCopy_Scheduled.csv -InputObject $NewSharing -Append -Encoding ascii $PersonOnLeave.SelectedIndex = -1 $GiveAccessTo.SelectedIndex = -1 } # Close Form $Close_Form_Click = { $Form.Close() } # Start Date Picker $StartDate.Name = "Start Date Picker" $StartDate.Location = '110,10' $StartDate.Size = '220,30' $StartDate.TabIndex = 0 # Person On Leave ComboBox $PersonOnLeave.FormattingEnabled = $True $PersonOnLeave.Name = "Person On Leave Combo" $PersonOnLeave.Location = '110,40' $PersonOnLeave.Size = '220,30' $PersonOnLeave.Sorted = $True $PersonOnLeave.TabIndex = 1 # Give Access To ComboBox $GiveAccessTo.FormattingEnabled = $True $GiveAccessTo.Name = "Give Access To Combo" $GiveAccessTo.Location = '110,70' $GiveAccessTo.Size = '220,30' $GiveAccessTo.Sorted = $True $GiveAccessTo.TabIndex = 2

    # Remove Date Picker $RemoveDate.Name = "Remove Date Picker" $RemoveDate.Location = '110,100' $RemoveDate.Size = '220,30' $RemoveDate.TabIndex = 3

    # Labels $StartDateLabel.Location = '10,10' $StartDateLabel.Size = '110,20' $StartDateLabel.Text = "Start Date" $PersonOnLeaveLabel.Location = '10,40' $PersonOnLeaveLabel.Size = '110,20' $PersonOnLeaveLabel.Text = "Person On Leave" $GiveAccessToLabel.Location = '10,70' $GiveAccessToLabel.Size = '110,20' $GiveAccessToLabel.Text = "Give Access To" $RemoveDateLabel.Location = '10,100' $RemoveDateLabel.Size = '110,20' $RemoveDateLabel.Text = "Remove Date" # Submit Full Button $SubmitFullButton.Name = "Submit Full Button" $SubmitFullButton.Location = '110,130' $SubmitFullButton.Size = '120,20' $SubmitFullButton.Text = "Submit Full Access" $SubmitFullButton.UseVisualStyleBackColor = $True $SubmitFullButton.Add_Click($Submit_Full_Click)

    # Submit Copy Button $SubmitCopyButton.Name = "Submit Copy Button" $SubmitCopyButton.Location = '240,130' $SubmitCopyButton.Size = '90,20' $SubmitCopyButton.Text = "Submit Copy" $SubmitCopyButton.UseVisualStyleBackColor = $True $SubmitCopyButton.Add_Click($Submit_Copy_Click)

    # Close Button #CloseFormButton.Name = "Close Button" $CloseFormButton.Location = '490,130' $CloseFormButton.Size = '130,20' $CloseFormButton.Text = "Close" $CloseFormButton.UseVisualStyleBackColor = $True $CloseFormButton.Add_Click($Close_Form_Click) # Show Scheduled Full Button $ShowScheduledFull.Location = '350,10' $ShowScheduledFull.Size = '130,20' $ShowScheduledFull.Text = "Show Scheduled Full" $ShowScheduledFull.UseVisualStyleBackColor = $True $ShowScheduledFull.Add_Click({Import-Csv -Path FileSystem::\\domain.local\Data\Shared\Email\MailboxSharing_Scheduled.csv | Out-GridView –Title Scheduled}) # Show Actioned Full Button $ShowActionedFull.Location = '350,40' $ShowActionedFull.Size = '130,20' $ShowActionedFull.Text = "Show Actioned Full" $ShowActionedFull.UseVisualStyleBackColor = $True $ShowActionedFull.Add_Click({Import-Csv -Path FileSystem::\\domain.local\Data\Shared\Email\MailboxSharing_Actioned.csv | Out-GridView –Title Actioned}) #Show Completed Full Button $ShowCompletedFull.Location = '350,70' $ShowCompletedFull.Size = '130,20' $ShowCompletedFull.Text = "Show Completed Full" $ShowCompletedFull.UseVisualStyleBackColor = $True $ShowCompletedFull.Add_Click({Import-Csv -Path FileSystem::\\domain.local\Data\Shared\Email\MailboxSharing_Completed.csv | Out-GridView –Title Completed}) # Show Scheduled Copy Button $ShowScheduledCopy.Location = '490,10' $ShowScheduledCopy.Size = '130,20' $ShowScheduledCopy.Text = "Show Scheduled Copy" $ShowScheduledCopy.UseVisualStyleBackColor = $True $ShowScheduledCopy.Add_Click({Import-Csv -Path FileSystem::\\domain.local\Data\Shared\Email\MailboxCopy_Scheduled.csv | Out-GridView –Title Scheduled}) # Show Actioned Copy Button $ShowActionedCopy.Location = '490,40' $ShowActionedCopy.Size = '130,20' $ShowActionedCopy.Text = "Show Actioned Copy" $ShowActionedCopy.UseVisualStyleBackColor = $True $ShowActionedCopy.Add_Click({Import-Csv -Path FileSystem::\\domain.local\Data\Shared\Email\MailboxCopy_Actioned.csv | Out-GridView –Title Actioned}) # Show Completed Copy Button $ShowCompletedCopy.Location = '490,70' $ShowCompletedCopy.Size = '130,20' $ShowCompletedCopy.Text = "Show Completed Copy" $ShowCompletedCopy.UseVisualStyleBackColor = $True $ShowCompletedCopy.Add_Click({Import-Csv -Path FileSystem::\\domain.local\Data\Shared\Email\MailboxCopy_Completed.csv | Out-GridView –Title Completed}) $Form.ResumeLayout() $InitialFormWindowState = $Form.WindowState $Form.Add_Load($Form_StateCorrection_Load) Return $Form.ShowDialog() } Call-Mailbox-Sharing_psf



    • Edited by Grubsy Friday, May 15, 2015 2:27 AM OCD - Fixed Formatting
    Thursday, May 14, 2015 11:41 PM
  • Very nice and I bet you understand it better now too.

    You don't have to use Call_<   >_psf as a function name.  That was auto generated by PowerShell Studio.

    PowerShell studio write code like that automatically.  It does it almost exactly the way I was doing it before PS came along.  Igt is a good way to keep the build organized and in the correct order.


    \_(ツ)_/

    Thursday, May 14, 2015 11:54 PM