The code I'm using is:
PowerShell Code
Double-click the code block to select all.#Generated Form Function function GenerateForm { ######################################################################## # Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.10.0 # Generated On: 4/22/2014 2:37 PM # Generated By: gdavies ######################################################################## #region Import the Assemblies [reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null [reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null #endregion #region Generated Form Objects $form1 = New-Object System.Windows.Forms.Form $textBox3 = New-Object System.Windows.Forms.TextBox $GroupNameLabel = New-Object System.Windows.Forms.Label $TextLabel = New-Object System.Windows.Forms.Label $ResultLabel = New-Object System.Windows.Forms.Label $ResultsBox = New-Object System.Windows.Forms.TextBox $ExitButton = New-Object System.Windows.Forms.Button $RemoveUserFromGroupButton = New-Object System.Windows.Forms.Button $AddUserToGroupButton = New-Object System.Windows.Forms.Button $DisplayGroupMembersButton = New-Object System.Windows.Forms.Button $SearchOUPermissionsButton = New-Object System.Windows.Forms.Button $UserEntryTextBox = New-Object System.Windows.Forms.TextBox $WarningLabel = New-Object System.Windows.Forms.Label $InstructionLabel = New-Object System.Windows.Forms.Label $InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState #endregion Generated Form Objects #---------------------------------------------- #Generated Event Script Blocks #---------------------------------------------- #Provide Custom Code for events specified in PrimalForms. $AddUserToGroupButton_OnClick= { $resultsbox.Text=Add-ADGroupMember -Identity $textBox3.Text -Members $UserEntryTextBox.Text | Out-String $ResultsBox.Focus() } $ExitButton_OnClick= { $form1.Close() } $DisplayGroupMembersButton_OnClick= { $resultsbox.Text=Get-ADGroupMember $UserEntryTextBox.Text -recursive | Select-Object Name | Out-String $ResultsBox.Focus() } $RemoveUserFromGroupButton_OnClick= { $resultsbox.Text=Remove-ADGroupMember -Identity $textBox3.Text -Members $UserEntryTextBox.Text -confirm:$false | Out-String $ResultsBox.Focus() } $SearchPermButton_OnClick= { $resultsbox.Text=Get-QADObject bellevue.edu/$UserEntryTextBox -SecurityMask Dacl | Get-QADPermission -UseExtendedMatch -Inherited -SchemaDefault -Property ('name') | Out-String $ResultsBox.Focus() } $ImportModules= { Add-PSSnapin Quest.ActiveRoles.ADManagement import-module activedirectory } $OnLoadForm_StateCorrection= {#Correct the initial state of the form to prevent the .Net maximized form issue $form1.WindowState = $InitialFormWindowState } #---------------------------------------------- #region Generated Form Code $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 611 $System_Drawing_Size.Width = 684 $form1.ClientSize = $System_Drawing_Size $form1.DataBindings.DefaultDataSourceUpdateMode = 0 $form1.Name = "form1" $form1.Text = "Search and modify AD permissions" $form1.add_Load($ImportModules) $textBox3.DataBindings.DefaultDataSourceUpdateMode = 0 $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 430 $System_Drawing_Point.Y = 140 $textBox3.Location = $System_Drawing_Point $textBox3.Name = "textBox3" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 20 $System_Drawing_Size.Width = 240 $textBox3.Size = $System_Drawing_Size $textBox3.TabIndex = 15 $form1.Controls.Add($textBox3) $GroupNameLabel.DataBindings.DefaultDataSourceUpdateMode = 0 $GroupNameLabel.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",8.25,1,3,0) $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 340 $System_Drawing_Point.Y = 140 $GroupNameLabel.Location = $System_Drawing_Point $GroupNameLabel.Name = "GroupNameLabel" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 20 $System_Drawing_Size.Width = 80 $GroupNameLabel.Size = $System_Drawing_Size $GroupNameLabel.TabIndex = 14 $GroupNameLabel.Text = "Name 2" $GroupNameLabel.TextAlign = 32 $form1.Controls.Add($GroupNameLabel) $TextLabel.DataBindings.DefaultDataSourceUpdateMode = 0 $TextLabel.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",8.25,1,3,0) $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 10 $System_Drawing_Point.Y = 140 $TextLabel.Location = $System_Drawing_Point $TextLabel.Name = "TextLabel" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 20 $System_Drawing_Size.Width = 80 $TextLabel.Size = $System_Drawing_Size $TextLabel.TabIndex = 13 $TextLabel.Text = "Name 1" $TextLabel.TextAlign = 32 $form1.Controls.Add($TextLabel) $ResultLabel.DataBindings.DefaultDataSourceUpdateMode = 0 $ResultLabel.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",8.25,1,3,0) $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 10 $System_Drawing_Point.Y = 180 $ResultLabel.Location = $System_Drawing_Point $ResultLabel.Name = "ResultLabel" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 20 $System_Drawing_Size.Width = 660 $ResultLabel.Size = $System_Drawing_Size $ResultLabel.TabIndex = 12 $ResultLabel.Text = "Results" $ResultLabel.TextAlign = 32 $form1.Controls.Add($ResultLabel) $ResultsBox.BackColor = [System.Drawing.Color]::FromArgb(255,0,0,0) $ResultsBox.DataBindings.DefaultDataSourceUpdateMode = 0 $ResultsBox.ForeColor = [System.Drawing.Color]::FromArgb(255,124,252,0) $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 10 $System_Drawing_Point.Y = 210 $ResultsBox.Location = $System_Drawing_Point $ResultsBox.Multiline = $True $ResultsBox.Name = "ResultsBox" $ResultsBox.ReadOnly = $True $ResultsBox.ScrollBars = 2 $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 330 $System_Drawing_Size.Width = 660 $ResultsBox.Size = $System_Drawing_Size $ResultsBox.TabIndex = 11 $form1.Controls.Add($ResultsBox) $ExitButton.BackColor = [System.Drawing.Color]::FromArgb(255,0,0,0) $ExitButton.DataBindings.DefaultDataSourceUpdateMode = 0 $ExitButton.FlatStyle = 1 $ExitButton.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",8.25,1,3,0) $ExitButton.ForeColor = [System.Drawing.Color]::FromArgb(255,255,255,255) $ExitButton.Image = [System.Drawing.Image]::FromFile('C:\Users\gdavies\Pictures\exit1.jpg') $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 590 $System_Drawing_Point.Y = 550 $ExitButton.Location = $System_Drawing_Point $ExitButton.Name = "ExitButton" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 40 $System_Drawing_Size.Width = 75 $ExitButton.Size = $System_Drawing_Size $ExitButton.TabIndex = 10 $ExitButton.UseVisualStyleBackColor = $False $ExitButton.add_Click($ExitButton_OnClick) $form1.Controls.Add($ExitButton) $RemoveUserFromGroupButton.BackColor = [System.Drawing.Color]::FromArgb(255,255,69,0) $RemoveUserFromGroupButton.DataBindings.DefaultDataSourceUpdateMode = 0 $RemoveUserFromGroupButton.FlatStyle = 1 $RemoveUserFromGroupButton.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",6.75,1,3,0) $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 460 $System_Drawing_Point.Y = 550 $RemoveUserFromGroupButton.Location = $System_Drawing_Point $RemoveUserFromGroupButton.Name = "RemoveUserFromGroupButton" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 40 $System_Drawing_Size.Width = 120 $RemoveUserFromGroupButton.Size = $System_Drawing_Size $RemoveUserFromGroupButton.TabIndex = 9 $RemoveUserFromGroupButton.Text = "Remove user from security group" $RemoveUserFromGroupButton.UseVisualStyleBackColor = $False $RemoveUserFromGroupButton.add_Click($RemoveUserFromGroupButton_OnClick) $form1.Controls.Add($RemoveUserFromGroupButton) $AddUserToGroupButton.BackColor = [System.Drawing.Color]::FromArgb(255,255,69,0) $AddUserToGroupButton.DataBindings.DefaultDataSourceUpdateMode = 0 $AddUserToGroupButton.FlatStyle = 1 $AddUserToGroupButton.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",6.75,1,3,0) $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 310 $System_Drawing_Point.Y = 550 $AddUserToGroupButton.Location = $System_Drawing_Point $AddUserToGroupButton.Name = "AddUserToGroupButton" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 40 $System_Drawing_Size.Width = 120 $AddUserToGroupButton.Size = $System_Drawing_Size $AddUserToGroupButton.TabIndex = 8 $AddUserToGroupButton.Text = "Add user to security group" $AddUserToGroupButton.UseVisualStyleBackColor = $False $AddUserToGroupButton.add_Click($AddUserToGroupButton_OnClick) $form1.Controls.Add($AddUserToGroupButton) $DisplayGroupMembersButton.BackColor = [System.Drawing.Color]::FromArgb(255,173,255,47) $DisplayGroupMembersButton.DataBindings.DefaultDataSourceUpdateMode = 0 $DisplayGroupMembersButton.FlatStyle = 1 $DisplayGroupMembersButton.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",6.75,1,3,0) $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 160 $System_Drawing_Point.Y = 550 $DisplayGroupMembersButton.Location = $System_Drawing_Point $DisplayGroupMembersButton.Name = "DisplayGroupMembersButton" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 40 $System_Drawing_Size.Width = 120 $DisplayGroupMembersButton.Size = $System_Drawing_Size $DisplayGroupMembersButton.TabIndex = 7 $DisplayGroupMembersButton.Text = "Display members of security group" $DisplayGroupMembersButton.UseVisualStyleBackColor = $False $DisplayGroupMembersButton.add_Click($DisplayGroupMembersButton_OnClick) $form1.Controls.Add($DisplayGroupMembersButton) $SearchOUPermissionsButton.BackColor = [System.Drawing.Color]::FromArgb(255,173,255,47) $SearchOUPermissionsButton.DataBindings.DefaultDataSourceUpdateMode = 0 $SearchOUPermissionsButton.FlatStyle = 1 $SearchOUPermissionsButton.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",6.75,1,3,0) $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 10 $System_Drawing_Point.Y = 550 $SearchOUPermissionsButton.Location = $System_Drawing_Point $SearchOUPermissionsButton.Name = "SearchOUPermissionsButton" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 40 $System_Drawing_Size.Width = 120 $SearchOUPermissionsButton.Size = $System_Drawing_Size $SearchOUPermissionsButton.TabIndex = 6 $SearchOUPermissionsButton.Text = " Search assigned permissions for OU" $SearchOUPermissionsButton.UseVisualStyleBackColor = $False $SearchOUPermissionsButton.add_Click($SearchOUPermissionsButton_OnClick) $form1.Controls.Add($SearchOUPermissionsButton) $UserEntryTextBox.DataBindings.DefaultDataSourceUpdateMode = 0 $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 100 $System_Drawing_Point.Y = 140 $UserEntryTextBox.Location = $System_Drawing_Point $UserEntryTextBox.Name = "UserEntryTextBox" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 20 $System_Drawing_Size.Width = 240 $UserEntryTextBox.Size = $System_Drawing_Size $UserEntryTextBox.TabIndex = 5 $form1.Controls.Add($UserEntryTextBox) $WarningLabel.BackColor = [System.Drawing.Color]::FromArgb(255,255,255,255) $WarningLabel.DataBindings.DefaultDataSourceUpdateMode = 0 $WarningLabel.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",8.25,1,3,0) $WarningLabel.ForeColor = [System.Drawing.Color]::FromArgb(255,178,34,34) $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 10 $System_Drawing_Point.Y = 70 $WarningLabel.Location = $System_Drawing_Point $WarningLabel.Name = "WarningLabel" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 60 $System_Drawing_Size.Width = 660 $WarningLabel.Size = $System_Drawing_Size $WarningLabel.TabIndex = 1 $WarningLabel.Text = "Ensure the OU, Security Group or User ID are entered exactly as they appear in AD. Any incorrect spelling will result in either a failure or the search/change being run on the wrong object For Add/Remove user from group, please enter the user ID in the first text box, the Group name in the second" $WarningLabel.TextAlign = 32 $form1.Controls.Add($WarningLabel) $InstructionLabel.DataBindings.DefaultDataSourceUpdateMode = 0 $InstructionLabel.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",8.25,1,3,0) $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 10 $System_Drawing_Point.Y = 10 $InstructionLabel.Location = $System_Drawing_Point $InstructionLabel.Name = "InstructionLabel" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 40 $System_Drawing_Size.Width = 660 $InstructionLabel.Size = $System_Drawing_Size $InstructionLabel.TabIndex = 0 $InstructionLabel.Text = "Enter the OU, Security Group or User you wish to search or modify then hit the relevant button. IMPORTANT NOTE: No confirmation will be requested so please ensure you are making the correct change and you are authorized to make the change." $InstructionLabel.TextAlign = 32 $form1.Controls.Add($InstructionLabel) #endregion Generated Form Code #Save the initial state of the form $InitialFormWindowState = $form1.WindowState #Init the OnLoad event to correct the initial state of the form $form1.add_Load($OnLoadForm_StateCorrection) #Show the Form $form1.ShowDialog()| Out-Null } #End Function #Call the Function GenerateFormEverything works, apart from the main one he needs (lines 38+39). If I try to run this it gives no output, I tried pushing it out to a file, it creates the file but there is no data. Running the same script this way:
PowerShell Code
Double-click the code block to select all.Add-PSSnapin Quest.ActiveRoles.ADManagement import-module activedirectory $prompt = @" ______________________________________________________________________________ | | | Please select from the options below | | | | s = Search assigned permissions for OU | | g = Display members of Security Group | | a = Add user to Security Group | | r = Remove user from Security Group | | x = exit | | | |______________________________________________________________________________| "@ Clear-host Do{ $originalcolor = $host.UI.RawUI.ForegroundColor $host.UI.RawUI.ForegroundColor = "green" $choice = Read-Host -Prompt $prompt $host.UI.RawUI.ForegroundColor = "green" Switch($choice){ s {$user = Read-Host 'Enter the OU you wish to see assigned permissions for. you do not need to enter bellevue.edu/ just the path from there (i.e. employees, employees/disabled accounts etc.)' ; Get-QADObject bellevue.edu/$user -SecurityMask Dacl | Get-QADPermission -UseExtendedMatch -Inherited -SchemaDefault -Property ('sAMAccountName','name')} g {$user = Read-Host 'Enter the Security Group name you wish to list the members of' ; Get-ADGroupMember $user -recursive | Select-Object Name} a {$user = Read-Host 'Enter the Account name (sAMAccountName) you wish to add'; $group = Read-Host 'Enter the Security Group you wish to add the user to' ; Add-ADGroupMember -Identity $group -Members $user} r {$user = Read-Host 'Enter the Account name (sAMAccountName) you wish to remove'; $group = Read-Host 'Enter the Security Group you wish to remove the user from' ; Remove-ADGroupMember -Identity $group -Members $user -confirm:$false} x {break} default {write-host "Invalid selection, please try again." -ForegroundColor Red} } }Until($choice -eq "x")works fine, the only difference is the variable names and the way it looks.
Is this a problem with PrimalForms and the Quest pssnapin not playing together maybe?