Im trying to create a script to set specific (advanced)access rights to a folder. However i keep running into the same error. And i cannot seem to figure it out, im hoping you guys have a solution for me.
This is the error i get:
New-Object : Cannot find an overload for "FileSystemAccessRule" and the argument count: "5". At line:14 char:17
And this is the powershell code that i have:
$folder = "\\netwerk\data\tablet\Test2"
$ReadGroup = "netwerk\ACR_Test2_R"
$WriteGroup = "netwerk\ACR_Test2_RW"
$acl = Get-Acl $folder
$ReadallowString = 'ExecuteFile','ListDirectory','Read','ReadData','ReadAndExecute','ReadExtendedAttributes','ReadPermissions'
$WriteallowString = 'AppendData','CreateDirectories','CreateFiles','DeleteSubdirectoriesAndFiles','ExecuteFile','ListDirectory','Modify','Read','ReadAndExecute','ReadExtendedAttributes','ReadPermissions','Traverse','Write','WriteAttributes','WriteData','WriteExtendedAttributes'
$ReaddenyString = 'Delete','TakeOwnership','ChangePermissions'
$WritedenyString = 'Delete','TakeOwnership','ChangePermissions'
$AllowVar =[System.Security.AccessControl.AccessControlType]::Allow
$DenyVar =[System.Security.AccessControl.AccessControlType]::Deny
$AceAllowRead = New-Object Security.AccessControl.FileSystemAccessRule($ReadGroup, $ReadallowString, $inherit, $propagation, $AllowVar)
$AceAllowWrite = New-Object Security.AccessControl.FileSystemAccessRule($WriteGroup, $WriteallowString, $inherit, $propagation, $AllowVar)
$AceDenyRead = New-Object Security.AccessControl.FileSystemAccessRule($ReadGroup, $ReaddenyString, $inherit, $propagation, $DenyVar)
$AceDenyWrite = New-Object Security.AccessControl.FileSystemAccessRule($WriteGroup, $WritedenyString, $inherit, $propagation, $DenyVar)
$inherit = [system.security.accesscontrol.InheritanceFlags]"ContainerInherit, ObjectInherit"
$propagation = [system.security.accesscontrol.PropagationFlags]"None"
$acl.AddAccessRule($AceAllowRead)
$acl.AddAccessRule($AceDenyRead)
$acl.AddAccessRule($AceAllowWrite)
$acl.AddAccessRule($AceDenyWrite)
Set-Acl $folder $acl
Seems like it trips at the part where i am Creating the FileSystemAccessRule's
I think your issue is with the position of your variable $inherit and $propagation in your script. They should be declared before that you call them.
Try this :
$folder = "\\netwerk\data\tablet\Test2"
$ReadGroup = "netwerk\ACR_Test2_R"
$WriteGroup = "netwerk\ACR_Test2_RW"
$acl = Get-Acl $folder
$ReadallowString = 'ExecuteFile','ListDirectory','Read','ReadData','ReadAndExecute','ReadExtendedAttributes','ReadPermissions'
$WriteallowString = 'AppendData','CreateDirectories','CreateFiles','DeleteSubdirectoriesAndFiles','ExecuteFile','ListDirectory','Modify','Read','ReadAndExecute','ReadExtendedAttributes','ReadPermissions','Traverse','Write','WriteAttributes','WriteData','WriteExtendedAttributes'
$ReaddenyString = 'Delete','TakeOwnership','ChangePermissions'
$WritedenyString = 'Delete','TakeOwnership','ChangePermissions'
$AllowVar =[System.Security.AccessControl.AccessControlType]::Allow
$DenyVar =[System.Security.AccessControl.AccessControlType]::Deny
$inherit = [system.security.accesscontrol.InheritanceFlags]"ContainerInherit, ObjectInherit"
$propagation = [system.security.accesscontrol.PropagationFlags]"None"
$AceAllowRead = New-Object Security.AccessControl.FileSystemAccessRule($ReadGroup, $ReadallowString, $inherit, $propagation, $AllowVar)
$AceAllowWrite = New-Object Security.AccessControl.FileSystemAccessRule($WriteGroup, $WriteallowString, $inherit, $propagation, $AllowVar)
$AceDenyRead = New-Object Security.AccessControl.FileSystemAccessRule($ReadGroup, $ReaddenyString, $inherit, $propagation, $DenyVar)
$AceDenyWrite = New-Object Security.AccessControl.FileSystemAccessRule($WriteGroup, $WritedenyString, $inherit, $propagation, $DenyVar)
$acl.AddAccessRule($AceAllowRead)
$acl.AddAccessRule($AceDenyRead)
$acl.AddAccessRule($AceAllowWrite)
$acl.AddAccessRule($AceDenyWrite)
Set-Acl $folder $acl
Related
I'm working on a little side project of listing outlook calendar meetings in the form data grid view.
I can populate columns with Subject and Start Date with no problem. For some reason, I can not populate a column with .DayOfWeekMask value, even though I can access this property via CLI. Any thoughts? Code below
add-type -AssemblyName 'System.Windows.Forms'
Add-Type -AssemblyName 'System.Drawing'
Add-Type -AssemblyName 'PresentationFramework'
$4 =
"BASE64 code"
$today = get-date
$Script:selection = #()
add-type -AssemblyName "Microsoft.Office.Interop.Outlook"
$outlookFolders = "Microsoft.Office.Interop.Outlook.OlDefaultFolders" -as [type]
$outlook = New-Object -ComObject outlook.application
$namespace = $outlook.GetNamespace("MAPI")
$folder = $namespace.GetDefaultFolder($outlookFolders::olFolderCalendar)
$items = $folder.Items
$meetings = $items|?{$_.isRecurring -eq $true -and $_.Subject -notlike "*Canceled*" <#-and $_.GetRecurrencePattern().DayOfWeekMask -eq 18#>}|Select Subject, Start, #{l='Mask';e={$_.GetRecurrencePattern().DayOfWeekMask}}
$bitmap3 = New-Object System.Windows.Media.Imaging.BitmapImage
$bitmap3.BeginInit()
$bitmap3.StreamSource = [System.IO.MemoryStream][System.Convert]::FromBase64String($4)
$bitmap3.EndInit()
$bitmap3.Freeze()
$image3 = [System.Drawing.Bitmap][System.Drawing.Image]::FromStream($bitmap3.StreamSource)
$icon3 = [System.Drawing.Icon]::FromHandle($image3.GetHicon())
$main2 = New-Object System.Windows.Forms.Form
$main2.Icon = $icon3
$main2.ClientSize = '600,600'
$main2.MinimizeBox = $false
$main2.MaximizeBox = $false
$main2.Text = 'Options'
$main2.AutoSize = $true
$grid = New-Object System.Windows.Forms.DataGridView
$grid.Location = '5,5'
$grid.Height = 500
$grid.Width = 390
$grid.ColumnHeadersVisible = $true
$grid.AutoSizeColumnsMode = 'AllCells'
$grid.ColumnCount = 3
$grid.columns[0].Name = 'Name'
$grid.Columns[1].Name = 'Time'
$grid.Columns[2].Name = 'Day Mask'
$grid.MultiSelect = $true
$grid.SelectionMode = 'FullRowSelect'
$meetings|%{$grid.Rows.Add($($_.Subject), $($_.Start)), $($_.Mask)}
$button = [System.Windows.Forms.Button]::new()
$button.Location = [System.Drawing.Point]::new(5,540)
$button.Size = [System.Drawing.Size]::new(100,50)
$button.Text = 'OK'
$button.Add_Click({
$grid.SelectedRows|%{
$Script:selection += [pscustomobject]#{
Name = $grid.Rows[$_.Index].Cells[0].Value
Time = $grid.Rows[$_.Index].Cells[1].Value
}
}
})
$main2.Controls.AddRange(#($grid,$button))
$main2.ShowDialog()
update you datagrid wiht this one
$grid = New-Object System.Windows.Forms.DataGridView
$grid.Location = '5,5'
$grid.Height = 500
$grid.Width = 390
$grid.ColumnHeadersVisible = $true
$grid.AutoSizeColumnsMode = 'AllCells'
$grid.MultiSelect = $true
$grid.SelectionMode = 'FullRowSelect'
$array.AddRange($meetings)
$grid.DataSource=($array)
======= this datasourge work eveytime..
Based on the answer of #Kemal I removed .ColumnCount and subsequent Name properties. Created new ArrayList via $array = [System.Collections.ArrayList]::new() abd then applied Kemal's solution.
In th end the script looks like this.
add-type -AssemblyName 'System.Windows.Forms'
Add-Type -AssemblyName 'System.Drawing'
Add-Type -AssemblyName 'PresentationFramework'
$4 =
"BASE64 CODE"
$today = get-date
$selection =#()
$array = [System.Collections.ArrayList]::new()
add-type -AssemblyName "Microsoft.Office.Interop.Outlook"
$outlookFolders = "Microsoft.Office.Interop.Outlook.OlDefaultFolders" -as [type]
$outlook = New-Object -ComObject outlook.application
$namespace = $outlook.GetNamespace("MAPI")
$folder = $namespace.GetDefaultFolder($outlookFolders::olFolderCalendar)
$items = $folder.Items
$meetings = $items|?{$_.isRecurring -eq $true -and $_.Subject -notlike "*Canceled*" |Select Subject, Start, #{l='Mask';e={$_.GetRecurrencePattern().DayOfWeekMask}}
$bitmap3 = New-Object System.Windows.Media.Imaging.BitmapImage
$bitmap3.BeginInit()
$bitmap3.StreamSource = [System.IO.MemoryStream][System.Convert]::FromBase64String($4)
$bitmap3.EndInit()
$bitmap3.Freeze()
$image3 = [System.Drawing.Bitmap][System.Drawing.Image]::FromStream($bitmap3.StreamSource)
$icon3 = [System.Drawing.Icon]::FromHandle($image3.GetHicon())
$main2 = New-Object System.Windows.Forms.Form
$main2.Icon = $icon3
$main2.ClientSize = '600,600'
$main2.MinimizeBox = $false
$main2.MaximizeBox = $false
$main2.Text = 'Options'
$main2.AutoSize = $true
$grid = New-Object System.Windows.Forms.DataGridView
$grid.Location = '5,5'
$grid.Height = 500
$grid.Width = 390
$grid.ColumnHeadersVisible = $true
$grid.AutoSizeColumnsMode = 'AllCells'
$grid.MultiSelect = $true
$grid.SelectionMode = 'FullRowSelect'
$array.AddRange($meetings)
$grid.DataSource=($array)
$button = [System.Windows.Forms.Button]::new()
$button.Location = [System.Drawing.Point]::new(5,540)
$button.Size = [System.Drawing.Size]::new(100,50)
$button.Text = 'OK'
$button.Add_Click({
$grid.SelectedRows|%{
$Script:selection += [pscustomobject]#{
Name = $grid.Rows[$_.Index].Cells[0].Value
Time = $grid.Rows[$_.Index].Cells[1].Value
DayofWeek = $grid.Rows[$_.Index].Cells[2].Value
}
}
})
$main2.Controls.AddRange(#($grid,$button))
$main2.ShowDialog()
I can open my mailbox in exchange online with EWS and Powershell
$service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService
$service.Credentials = New-Object System.Net.NetworkCredential -ArgumentList $mail, $password
$service.URL = New-Object Uri("https://outlook.office365.com/EWS/Exchange.asmx")
$view = New-Object Microsoft.Exchange.WebServices.Data.ItemView($numOfEmailsToRead, $index)
$folderview = New-Object Microsoft.Exchange.WebServices.Data.FolderView(10)
$folderview.PropertySet = New-Object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.Webservices.Data.BasePropertySet]::FirstClassProperties)
$folderview.PropertySet.Add([Microsoft.Exchange.Webservices.Data.FolderSchema]::DisplayName)
$folderview.Traversal = [Microsoft.Exchange.Webservices.Data.FolderTraversal]::Deep
$folderfindResults = $service.FindFolders([Microsoft.Exchange.Webservices.Data.WellKnownFolderName]::Inbox, $folderview)
$SearchFilterContainsSubString = New-Object Microsoft.Exchange.WebServices.Data.SearchFilter+ContainsSubstring([Microsoft.Exchange.WebServices.Data.ItemSchema]::Subject, $Paramerter)
$SearchFilterNot = New-Object Microsoft.Exchange.WebServices.Data.SearchFilter+Not($SearchFilterContainsSubString)
foreach ($InboxFolder in $folderfindResults) {
$findResultsItems = $InboxFolder.findItems($SearchFilterNot,$view)}
How do I change the code to open a mailbox to which I have full access?
In your example you need to use the Mailbox overload for Folder id so change
$folderfindResults = $service.FindFolders([Microsoft.Exchange.Webservices.Data.WellKnownFolderName]::Inbox, $folderview)
$SearchFilterContainsSubString = New-Object Microsoft.Exchange.WebServices.Data.SearchFilter+ContainsSubstring([Microsoft.Exchange.WebServices.Data.ItemSchema]::Subject, $Paramerter)
$SearchFilterNot = New-Object Microsoft.Exchange.WebServices.Data.SearchFilter+Not($SearchFilterContainsSubString)
foreach ($InboxFolder in $folderfindResults) {
$findResultsItems = $InboxFolder.findItems($SearchFilterNot,$view)}
To
$MailboxToAccess = "blah#blah.com"
$folderid = new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox,$MailboxToAccess)
$folderfindResults = $service.FindFolders($folderid, $folderview)
$SearchFilterContainsSubString = New-Object Microsoft.Exchange.WebServices.Data.SearchFilter+ContainsSubstring([Microsoft.Exchange.WebServices.Data.ItemSchema]::Subject, $Paramerter)
$SearchFilterNot = New-Object Microsoft.Exchange.WebServices.Data.SearchFilter+Not($SearchFilterContainsSubString)
foreach ($InboxFolder in $folderfindResults) {
$findResultsItems = $InboxFolder.findItems($SearchFilterNot,$view)}
Here is a simple example of connecting to a different mailbox
$MailboxName = New-Object Microsoft.Exchange.WebServices.Data.Mailbox("support#domain.com") #specifies which mailbox EWS should connect to
$folderid= new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox,$MailboxName)
$Inbox = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderid)
For more detailed info please read this blog: https://gsexdev.blogspot.com/2016/10/ews-basics-accessing-and-using-shared.html
Thank you for your support.
I was able to do it with the line
$service.ImpersonatedUserId = New-Object Microsoft.Exchange.WebServices.Data.ImpersonatedUserId([Microsoft.Exchange.WebServices.Data.ConnectingIdType]::SmtpAddress,$Mailbox);
Resolve.
I was getting a 401 error. The error was because I had overwritten the credentials. Now everything works.
In Exchange the executing user needs the role
"ApplicationImpersonation"
I need to create a checkbox automatically depends on folder I selected. I create ComboBox, then in the ComboBox, I can select which folder that I want to select. Inside of my folder, I have some file. The file consist of some extension file. I just need to pick 2 extension file from the folder, example(*.txt and *.csv).
After I select the folder, the checkBox will create automatically, the total of the checkBox depends on how many file exist in that folder with specific extension(*.txt and *.csv).
In my code, I already do some stuff, which is select the folder that I need to select, but still struggle with the checkBox. Anyone can help me please. Thank you so much. I really appreciate for the help.
I put my script in the ##2nd Updated.
Updated
Consider to #f6a4 answer, this is the result
The first picture is I just use this path to get the folder
'D:\Data\'
In the first picture, I already double click the folder1 and folder2, but the file do not appear.
The second picture, I specify the folder path
'D:\Data\folder1'
The second picture, the file appear because I specify the folder in the path, so the folder name do not appear in the please select folder box and return this error $CTRL_ListFolder.Items.AddRange( (Get-ChildItem -Path $GH.CurrentFold ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ArgumentNullException
2n Updated
I updated my script. But the file only appear 1, once I click the folder. And when I change to click other folder, It does not appear the file.
Add-Type -AssemblyName PresentationFramework
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()
$Global:status = "inactive"
$Global:array = New-Object System.Collections.Generic.List[System.Object]
$Form = New-Object system.Windows.Forms.Form
$Form.text = "BPS Image Automation Utility"
$Form.BackColor = "#f6f6f6"
$Form.AutoSize = $true
$Form.FormBorderStyle = "FixedDialog"
$Form.MaximizeBox = $false
$Form.startposition = "centerscreen"
$Form.WindowState = 'Maximized'
$Label1 = New-Object system.Windows.Forms.Label
$Label1.text = "Please select the image"
$Label1.AutoSize = $true
$Label1.width = 25
$Label1.height = 10
$Label1.location = New-Object System.Drawing.Point(50,50)
$Label1.Font = 'Microsoft Sans Serif,10'
$Label1.ForeColor = "#000000"
$label1.AutoSize = $true
$Button3 = New-Object system.Windows.Forms.Button
$Button3.BackColor = "#136aa4"
$Button3.ForeColor = "#ffffff"
$Button3.text = "Done"
$Button3.width = 90
$Button3.height = 32
$Button3.AutoSize = $true
$Button3.UseCompatibleTextRendering = $True
$Button3.UseVisualStyleBackColor = $False
# $Button3.location = New-Object System.Drawing.Point(1700,920)
$Button3.Font = 'Microsoft Sans Serif,10'
# $Button3.Visible = $false
$Button2 = New-Object system.Windows.Forms.Button
$Button2.BackColor = "#136aa4"
$Button2.ForeColor = "#ffffff"
$Button2.text = "Delete"
$Button2.width = 90
$Button2.height = 32
$Button2.UseCompatibleTextRendering = $True
$Button2.UseVisualStyleBackColor = $False
$Button2.AutoSize = $true
# $Button2.location = New-Object System.Drawing.Point(1600,920)
$Button2.Font = 'Microsoft Sans Serif,10'
# $Button2.Visible = $false
$Panel = New-Object System.Windows.Forms.TableLayoutPanel
$panel.Dock = "Fill"
$panel.ColumnCount = 1
$panel.RowCount = 1
$panel.CellBorderStyle = "single"
$panel.ColumnStyles.Add((new-object System.Windows.Forms.ColumnStyle([System.Windows.Forms.SizeType]::Percent, 100)))
$panel.RowStyles.Add((new-object System.Windows.Forms.RowStyle([System.Windows.Forms.SizeType]::Percent, 100)))
$Groupbox1 = New-Object system.Windows.Forms.Groupbox
$Groupbox1.text = "Job Handling"
$Groupbox1.Font = 'Microsoft Sans Serif,9'
$Groupbox1.AutoSize = $true
$Groupbox1.ForeColor = "#032d5d"
$Groupbox1.location = New-Object System.Drawing.Point(8,13)
$Groupbox1.Padding = New-Object -TypeName System.Windows.Forms.Padding -ArgumentList (0,5,5,0)
$Groupbox1.Dock = "fill"
$Groupbox1.UseCompatibleTextRendering = $True
$Groupbox2 = New-Object system.Windows.Forms.Groupbox
$Groupbox2.text = "Job Information"
$Groupbox2.Font = 'Microsoft Sans Serif,9'
$Groupbox2.AutoSize = $true
$Groupbox2.ForeColor = "#032d5d"
$Groupbox2.Dock = "None"
$Groupbox2.UseCompatibleTextRendering = $True
$ComboBox1 = New-Object system.Windows.Forms.ComboBox
$ComboBox1.BackColor = "#e8f3ff"
$ComboBox1.width = 190
$ComboBox1.height = 20
$ComboBox1.location = New-Object System.Drawing.Point(35,80)
$ComboBox1.Font = 'Microsoft Sans Serif,12'
$ComboBox1.AutoSize = $true
$ImageList = #(Get-ChildItem -Directory "D:\Process")
foreach ($img in $ImageList) {
$ComboBox1.Items.Add($img)
}
$ComboBox1.Add_Click({
if($ComboBox1.SelectedItem){
$Checkbox.Visible = $true
}
})
$Checkboxes += New-Object System.Windows.Forms.CheckBox
$Checkboxes = #()
$y = 20
$files = Get-ChildItem "D:\Process\$img" -Filter *.txt, *.csv
$files
foreach ($file in $files)
{
$Checkbox = New-Object System.Windows.Forms.CheckBox
$Checkbox.Text = $file
$Checkbox.Location = New-Object System.Drawing.Size(10,$y)
$Checkbox.Size = New-Object System.Drawing.Size(330,20)
$y += 30
$Groupbox2.Controls.Add($Checkbox)
$Checkboxes += $Checkbox
$Checkbox.Visible = $false
}
$Form.controls.AddRange(#($Panel))
$Panel.controls.AddRange(#($Groupbox1))
$Groupbox1.Controls.AddRange(#($Groupbox2, $ComboBox1, $Label1, $Button3, $Button2))
[void]$Form.Show()
$g2w = $Form.Width - 90
$g2h = $Form.Height - 270
$g2h
$Groupbox2.location = New-Object System.Drawing.Point(35,110)
$Groupbox2.size = New-Object System.Drawing.Size($g2w,$g2h)
$Groupbox2.AutoSize = $true
$bt2_w = $g2w - 55
$bt2_h = $g2h + 130
$Button2.location = New-Object System.Drawing.Point($bt2_w,$bt2_h)
$bt3_w = $g2w - 160
$Button3.location = New-Object System.Drawing.Point($bt3_w,$bt2_h)
$Form.Visible = $false
[void]$Form.ShowDialog()
This should do exactly what you want. By double click on a Directory you can browse through subdirectories as well.
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()
# Global variables
$GH = [hashtable]::Synchronized(#{})
$GH.FolderPath = 'C:\Users\myUser\Desktop\csvfiles'
$GH.CurrentFolderPath = $GH.FolderPath
$GH.FileMask = #('*.txt','*.csv')
# windows form
$form = New-Object System.Windows.Forms.Form
$form.Visible = $false
[void]$form.SuspendLayout()
$form.Text = "File Selection"
$form.ClientSize = New-Object System.Drawing.Size(320,430)
$form.StartPosition = 'CenterScreen'
$form.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedSingle
# tab control
$CTRL_TabCtrl = New-Object System.Windows.Forms.TabControl
$CTRL_TabCtrl.Location = New-Object System.Drawing.Point(5,5)
$CTRL_TabCtrl.Size = New-Object System.Drawing.Size(310,420)
[void]$form.Controls.Add($CTRL_TabCtrl)
$CTRL_Tab1 = New-Object System.Windows.Forms.TabPage
$CTRL_Tab1.AutoSize = $true
$CTRL_Tab1.Text = 'Main'
$CTRL_Tab1.TabIndex = 1
[void]$CTRL_TabCtrl.Controls.Add($CTRL_Tab1)
# list folder
$CTRL_label10 = New-Object System.Windows.Forms.Label
$CTRL_label10.Location = New-Object System.Drawing.Point(10,10)
$CTRL_label10.Size = New-Object System.Drawing.Size(260,20)
$CTRL_label10.Name = 'Label10'
$CTRL_label10.Text = 'Please select a folder:'
[void]$CTRL_Tab1.Controls.Add($CTRL_label10)
$CTRL_ListFolder = New-Object System.Windows.Forms.Listbox
$CTRL_ListFolder.Location = New-Object System.Drawing.Point(10,30)
$CTRL_ListFolder.Size = New-Object System.Drawing.Size(280,60)
$CTRL_ListFolder.SelectionMode = [System.Windows.Forms.SelectionMode]::One
$CTRL_ListFolder.Items.AddRange( (Get-ChildItem -Path $GH.CurrentFolderPath -Directory).Name )
$CTRL_ListFolder.Enabled = $true
$CTRL_ListFolder.Add_MouseDoubleClick( {
$listFolder_innerevent = $true
if( $CTRL_ListFolder.SelectedItem -eq '..' ) {
$GH.CurrentFolderPath = $GH.CurrentFolderPath.Substring( 0, $GH.CurrentFolderPath.LastIndexOf( '\' ) )
[void]$CTRL_ListFolder.Items.Clear()
if( $GH.CurrentFolderPath.Length -gt $GH.FolderPath.Length ) {
[void]$CTRL_ListFolder.Items.Add( '..' )
}
$CTRL_ListFolder.Items.AddRange( (Get-ChildItem -Path $GH.CurrentFolderPath -Directory).Name )
[void]$CTRL_CheckListBox.Items.Clear()
$files = (Get-ChildItem -Path ($GH.CurrentFolderPath + '\*') -Include $GH.FileMask -File ).Name
if( $files ) {
[void]$CTRL_CheckListBox.Items.AddRange( $files )
}
}
else {
if( (Get-ChildItem -Path ($GH.CurrentFolderPath + '\' + $CTRL_ListFolder.SelectedItem) -Directory).Name ) {
$GH.CurrentFolderPath += '\' + $CTRL_ListFolder.SelectedItem
[void]$CTRL_ListFolder.Items.Clear()
[void]$CTRL_ListFolder.Items.Add( '..' )
[void]$CTRL_ListFolder.Items.AddRange( (Get-ChildItem -Path $GH.CurrentFolderPath -Directory).Name )
[void]$CTRL_CheckListBox.Items.Clear()
$files = (Get-ChildItem -Path ($GH.CurrentFolderPath + '\*') -Include $GH.FileMask -File ).Name
if( $files ) {
[void]$CTRL_CheckListBox.Items.AddRange( $files )
}
}
}
} )
[void]$CTRL_Tab1.Controls.Add($CTRL_ListFolder)
# list folder with check boxes for files
$CTRL_label12 = New-Object System.Windows.Forms.Label
$CTRL_label12.Location = New-Object System.Drawing.Point(10,100)
$CTRL_label12.Size = New-Object System.Drawing.Size(260,20)
$CTRL_label12.Name = 'Label12'
$CTRL_label12.Text = 'Files found:'
[void]$CTRL_Tab1.Controls.Add($CTRL_label12)
$CTRL_CheckListBox = New-Object System.Windows.Forms.CheckedListbox
$CTRL_CheckListBox.Location = New-Object System.Drawing.Point(10,120)
$CTRL_CheckListBox.Size = New-Object System.Drawing.Size(280,230)
$CTRL_CheckListBox.CheckOnClick = $true
$CTRL_CheckListBox.Enabled = $true
$files = (Get-ChildItem -Path ($GH.CurrentFolderPath + '\*') -Include $GH.FileMask -File ).Name
if( $files ) {
[void]$CTRL_CheckListBox.Items.AddRange( $files )
}
[void]$CTRL_Tab1.Controls.Add($CTRL_CheckListBox)
$CTRL_OKButton1 = New-Object System.Windows.Forms.Button
$CTRL_OKButton1.Location = New-Object System.Drawing.Point(70,365)
$CTRL_OKButton1.Size = New-Object System.Drawing.Size(75,23)
$CTRL_OKButton1.Text = 'OK'
$CTRL_OKButton1.DialogResult = [System.Windows.Forms.DialogResult]::OK
$form.AcceptButton = $CTRL_OKButton1
[void]$CTRL_Tab1.Controls.Add($CTRL_OKButton1)
$CTRL_CancelButton1 = New-Object System.Windows.Forms.Button
$CTRL_CancelButton1.Location = New-Object System.Drawing.Point(150,365)
$CTRL_CancelButton1.Size = New-Object System.Drawing.Size(75,23)
$CTRL_CancelButton1.Text = 'Cancel'
$CTRL_CancelButton1.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
$form.CancelButton = $CTRL_CancelButton1
[void]$CTRL_Tab1.Controls.Add($CTRL_CancelButton1)
[void]$form.ResumeLayout()
$userInput = $form.ShowDialog()
if ($userInput -eq [System.Windows.Forms.DialogResult]::OK) {
# User clicked OK Button
}
I found the following which seems to work for what it is, but I need 2 things changed, and can't figure it out.
$acl = Get-Acl D:\New
$permission = "Everyone","Read","Allow"
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $permission
$acl.SetAccessRule($accessRule)
$acl | Set-Acl D:\New
I need to be able to give "HomeGroup" permission, not "Everyone".
I need this to recurse all folders.
When in doubt, read the documentation. You need to change the identity from "Everyone" to "$env:COMPUTERNAME\HomeGroup" and set the appropriate inheritance and propagation flags.
$identity = "$env:COMPUTERNAME\HomeGroup"
$accessRight = 'Read'
$inheritance = 'ContainerInherit, ObjectInherit'
$propagation = 'None'
$type = 'Allow'
$accessRule = New-Object Security.AccessControl.FileSystemAccessRule (
$identity, $accessRight, $inheritance, $propagation, $type
)
any ideas as to why this ews managed api in powershell keeps returning a 0 folder count and no permissions? i'm using impersonation, it's returning the folder names but no permissions.
function GetPerms{
param([string]$mailboxaddress)
$enumSmtpAddress = [Microsoft.Exchange.WebServices.Data.ConnectingIdType]::SmtpAddress
$global:service.ImpersonatedUserId = New-Object Microsoft.Exchange.WebServices.Data.ImpersonatedUserId($enumSmtpAddress,$mailboxaddress);
$mailbox = New-Object Microsoft.Exchange.WebServices.Data.Mailbox($mailboxaddress)
$FolderID = New-Object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::MsgFolderRoot,$mailbox)
$FolderRoot = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($global:service,$FolderID);
$FolderView = New-Object Microsoft.Exchange.WebServices.Data.FolderView(10000)
$FolderView.Traversal = [Microsoft.Exchange.WebServices.Data.FolderTraversal]::Deep
$findfolders = $FolderRoot.FindFolders($FolderView);
foreach ($folder in $findfolders.Folders){
$id = New-Object Microsoft.Exchange.WebServices.Data.FolderId($folder.Id.UniqueId.ToString())
$fld = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($global:service,$id);
$perms = $fld.Permissions
[int]$permcount = $fld.Permissions.Count
write-host $permcount
write-host $fld.Displayname, $fld.Permissions.Count
foreach($f in $fld.Permisions.UserID.PrimarySmtpAddress){
write-host $f
}
for($t=0;$t -le $perms.Count; $t++){
[string]$displayname = $fld.Permissions[$t].UserId.DisplayName
[string]$smtp = $fld.Permissions[$t].UserId.PrimarySmtpAddress
#write-host $mailboxaddress,$fld.DisplayName,$smtp
}
}
}
You need request that Exchange return the Folder Permissions with a PropertySet eg
$psPropset= new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)
$psPropset.Add([Microsoft.Exchange.WebServices.Data.FolderSchema]::Permissions)
$fld = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($global:service,$id,$psPropset);
And that should then return the permissions
Cheers
Glen