PowerShell Active Directory AddAccessRule - powershell

I am attempting to add a Computer Object to the security of another Computer object in AD and give it Full Control.
$ou = [ADSI]"LDAP://CN=Tester1,OU=test,OU=Test1,DC=contoso,DC=com"
$sec = $ou.psbase.ObjectSecurity
$act = [System.Security.AccessControl.AccessControlType]::Allow
$adrights = [System.DirectoryServices.ActiveDirectoryRights]::GenericAll
$who = New-Object -TypeName System.Security.Principal.???? -ArgumentList "domain\ComputerObject"
$newrule1 = New-Object -TypeName System.DirectoryServices.ActiveDirectoryAccessRule -ArgumentList $who, $adrights, $act
$sec.AddAccessRule($newrule1)
$ou.psbase.CommitChanges()
With the line (New-Object -TypeName System.Security.Principal.??) what is the correct class for Computer object? (I have tried .NTaccount)

The answer was
$who = New-Object -TypeName System.Security.Principal.NTaccount -ArgumentList "domain\ComputerObject$"
the $ specifies a computer Object.

Related

WinForm not loading the first time

I am writing a program using PowerShell WinForms.
For example, the "Login" part of the program.
#CREDENTIAL CREATE - LOGIN AND PASSWORD INPUT
############################################
#APP FOUNDATION
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
#Login_Form
$Login_Form = New-Object -TypeName System.Windows.Forms.Form
$Login_Form.ClientSize = (New-Object -TypeName System.Drawing.Size -ArgumentList #([System.Int32]340,[System.Int32]110))
$Login_Form.Text = [System.String]'Login_Form'
$Login_Form.add_Load($Login_Form_Load)
$Login_Form.ResumeLayout($false)
$Login_Form.PerformLayout()
$Login_Form.SuspendLayout()
$Login_Form.FormBorderStyle = "FixedDialog"
#Login_Label_User
$Login_Label_User = (New-Object -TypeName System.Windows.Forms.Label)
$Login_Label_User.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList #([System.Int32]12,[System.Int32]9))
$Login_Label_User.Name = [System.String]'Login_Label_User'
$Login_Label_User.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList #([System.Int32]100,[System.Int32]18))
$Login_Label_User.TabIndex = [System.Int32]3
$Login_Label_User.Text = [System.String]'Login:'
$Login_Label_User.UseCompatibleTextRendering = $true
#Login_TextBox_User
$Login_TextBox_User = (New-Object -TypeName System.Windows.Forms.TextBox)
$Login_TextBox_User.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList #([System.Int32]12,[System.Int32]30))
$Login_TextBox_User.Name = [System.String]'Login_TextBox_User'
$Login_TextBox_User.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList #([System.Int32]224,[System.Int32]21))
$Login_TextBox_User.TabIndex = [System.Int32]0
$Login_TextBox_User.Text = ((Get-ADDomain).name + "\")
$Login_TextBox_User.add_TextChanged($Login_TextBox_User_TextChanged)
#Login_TextBox_Password
$Login_TextBox_Password = (New-Object -TypeName System.Windows.Forms.TextBox)
$Login_TextBox_Password.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList #([System.Int32]12,[System.Int32]74))
$Login_TextBox_Password.Name = [System.String]'Login_TextBox_Password'
$Login_TextBox_Password.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList #([System.Int32]187,[System.Int32]21))
$Login_TextBox_Password.TabIndex = [System.Int32]1
$Login_TextBox_Password.Text = [System.String]''
$Login_TextBox_Password.PasswordChar = '*'
#Login_Button_Enter
$Login_Button_Enter = (New-Object -TypeName System.Windows.Forms.Button)
$Login_Button_Enter.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList #([System.Int32]251,[System.Int32]74))
$Login_Button_Enter.Name = [System.String]'Login_Button_Enter'
$Login_Button_Enter.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList #([System.Int32]75,[System.Int32]21))
$Login_Button_Enter.TabIndex = [System.Int32]2
$Login_Button_Enter.Text = [System.String]'ENTER'
$Login_Button_Enter.UseCompatibleTextRendering = $true
$Login_Button_Enter.UseVisualStyleBackColor = $true
$Login_Button_Enter.add_Click($Login_Button_Enter_Click)
#Login_Button_ShowHide
$Login_Button_ShowHide = (New-Object -TypeName System.Windows.Forms.Button)
$Login_Button_ShowHide.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList #([System.Int32]205,[System.Int32]74))
$Login_Button_ShowHide.Name = [System.String]'Login_Button_ShowHide'
$Login_Button_ShowHide.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList #([System.Int32]32,[System.Int32]21))
$Login_Button_ShowHide.TabIndex = [System.Int32]2
$Login_Button_ShowHide.Text = [System.String]'SHOW'
$Login_Button_ShowHide.UseCompatibleTextRendering = $true
$Login_Button_ShowHide.UseVisualStyleBackColor = $true
$Login_Button_ShowHide.add_Click($Login_Button_ShowHide_Click)
#Login_Label_Password
$Login_Label_Password = (New-Object -TypeName System.Windows.Forms.Label)
$Login_Label_Password.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList #([System.Int32]12,[System.Int32]54))
$Login_Label_Password.Name = [System.String]'Login_Label_Password'
$Login_Label_Password.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList #([System.Int32]100,[System.Int32]17))
$Login_Label_Password.TabIndex = [System.Int32]4
$Login_Label_Password.Text = [System.String]'Password:'
$Login_Label_Password.UseCompatibleTextRendering = $true
$Login_Label_Password.add_Click($Label2_Click)
#Form.Controls
$Login_Form.controls.AddRange(#($Login_Label_Password,$Login_Label_User,$Login_Button_Enter,$Login_Button_ShowHide,$Login_TextBox_Password,$Login_TextBox_User))
#Login_Button_Enter Click logic
$Login_Button_Enter_Click = {
$Script:username = $Login_TextBox_User.Text
$Script:password = $Login_TextBox_Password.Text
$Script:secstr = New-Object -TypeName System.Security.SecureString
$Script:password.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)}
$Script:cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $secstr
$Login_Form.Close()
}
#Login_Button_ShowHide Click logic
$Login_Button_ShowHide_Click = {
if($Script:Login_TextBox_Password.PasswordChar -eq '*') {
$Script:Login_TextBox_Password.PasswordChar = 0
$Login_Button_ShowHide.Text = [System.String]'SHOW'
}
elseif($Login_TextBox_Password.PasswordChar -eq 0) {
$Login_Button_ShowHide.Text = [System.String]'HIDE'
$Script:Login_TextBox_Password.PasswordChar = "*"
}
}
#START APPLICATION
[void]$Login_Form.ShowDialog()
When I run the script for the first time, the window and everything else is shown correctly, but the buttons and logic do not work.
For everything to work fine, I need to run it a second time.
How do I make everything work the first time I start it?
I've tried everything that is possible already. I do not understand what is wrong.
PowerShell is a largely interpreted language - statements are executed in line order.
You therefore need to define the event action scriptblocks before you can assign them to the respective event handlers, otherwise you're just assigning $null to the event handlers, which is why none of your buttons work.
# define the scriptblock that's supposed to handle the event action...
$Login_Button_ShowHide_Click = {
if($Script:Login_TextBox_Password.PasswordChar -eq '*') {
$Script:Login_TextBox_Password.PasswordChar = 0
$Login_Button_ShowHide.Text = [System.String]'SHOW'
}
elseif($Login_TextBox_Password.PasswordChar -eq 0) {
$Login_Button_ShowHide.Text = [System.String]'HIDE'
$Script:Login_TextBox_Password.PasswordChar = "*"
}
}
#Login_Button_ShowHide
$Login_Button_ShowHide = (New-Object -TypeName System.Windows.Forms.Button)
$Login_Button_ShowHide.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList #([System.Int32]205,[System.Int32]74))
$Login_Button_ShowHide.Name = [System.String]'Login_Button_ShowHide'
$Login_Button_ShowHide.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList #([System.Int32]32,[System.Int32]21))
$Login_Button_ShowHide.TabIndex = [System.Int32]2
$Login_Button_ShowHide.Text = [System.String]'SHOW'
$Login_Button_ShowHide.UseCompatibleTextRendering = $true
$Login_Button_ShowHide.UseVisualStyleBackColor = $true
# ... _before_ assigning it to handlethe event
$Login_Button_ShowHide.add_Click($Login_Button_ShowHide_Click)
Repeat for all the scriptblocks assigned as event handlers - either move them all to the top of the script, or, move all the .add_<EventName>() calls to the bottom, just before launching the GUI:
# Rest of script goes here ...
# register all event handlers
$Login_TextBox_User.add_TextChanged($Login_TextBox_User_TextChanged)
$Login_Button_Enter.add_Click($Login_Button_Enter_Click)
$Login_Button_ShowHide.add_Click($Login_Button_ShowHide_Click)
# start app
[void]$Login_Form.ShowDialog()

Powershell Admin rights dont work in Windows Forms

I want to add and remove user from the lokal Administrator group. Problem is that even I elevate rights in first place It still Access Denies me when I try to add them.
In a similar code It works this way... only thing I changed it that I created a GUI for it.
Here is the code:
$myWindowsID=[System.Security.Principal.WindowsIdentity]::GetCurrent()
$myWindowsPrincipal=new-object System.Security.Principal.WindowsPrincipal($myWindowsID)
$adminRole=[System.Security.Principal.WindowsBuiltInRole]::Administrator
if (!$myWindowsPrincipal.IsInRole($adminRole)){
start-process "powershell" -Verb "runas" -ArgumentList "-File",$MyInvocation.MyCommand.Definition
}
[VOID] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[Void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$objForm = New-Object System.Windows.Forms.Form
$objForm.BackgroundImageLayout = 0
$objForm.BackgroundImage =[System.Drawing.Image]::FromFile('xx')
$objForm.StartPosition = "CenterScreen"
$objForm.Icon="xx"
$objForm.Size = New-Object System.Drawing.Size(400,200)
$objForm.Text = "Lokal Admin Adder v.01"
$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(75,30)
$objLabel.Size = New-Object System.Drawing.Size(240,20)
$objLabel.Text = "Nutzernamen eingeben(m_mustermann)"
$objForm.Controls.Add($objLabel)
$objLabel2 = New-Object System.Windows.Forms.Label
$objLabel2.Location = New-Object System.Drawing.Size(280,140)
$objLabel2.Size = New-Object System.Drawing.Size(300,20)
$objLabel2.Text = "by Lucas Klarner"
$objForm.Controls.Add($objLabel2)
$objTextBox = New-Object System.Windows.Forms.TextBox
$objTextBox.Location = New-Object System.Drawing.Size(85,50)
$objTextBox.Size = New-Object System.Drawing.Size(200,20)
$objForm.Controls.Add($objTextBox)
$FinishButton = New-Object System.Windows.Forms.Button
$FinishButton.Location = New-Object System.Drawing.Size (20,80)
$FinishButton.Size = New-Object System.Drawing.Size (150,20)
$FinishButton.Text = "Nutzer hinzufügen"
$FinishButton.Name = "Nutzer hinzufügen"
$FinishButton.Add_Click({
$Usr = $objTextBox.Text; Add-LocalGroupMember -Group Administratoren -Member $Usr })
$objForm.Controls.Add($FinishButton)
$DeleteButton = New-Object System.Windows.Forms.Button
$DeleteButton.Location = New-Object System.Drawing.Size (210,80)
$DeleteButton.Size = New-Object System.Drawing.Size (150,20)
$DeleteButton.Text = "Nutzer entfernen"
$DeleteButton.Name = "Nutzer entfernen"
$DeleteButton.DialogResult = "OK"
$DeleteButton.Add_Click({
$Usr = $objTextBox.Text;Remove-LocalGroupMember -Group Administratoren -Member $Usr -Verbose })
$objForm.Controls.Add($DeleteButton)
[void] $objForm.ShowDialog()
Thanks a lot!!
FIXED:
Somehow my elevation code was not running correctly and I made a new one out of some internet posts:
if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) {
if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) {
$CommandLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments
Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CommandLine
Exit
}
}
Here's how it works:
The first line checks to see if the script is already running in an elevated environment. This would occur if PowerShell is running as Administrator or UAC is disabled. If it is, the script will continue to run normally in that process.
The second line checks to see if the Windows operating system build number is 6000 (Windows Vista) or greater. Earlier builds did not support Run As elevation.
The third line retrieves the command line used to run the original script, including any arguments.
Finally, the fourth line starts a new elevated PowerShell process where the script runs again. Once the script terminates, the elevated PowerShell window closes.
https://blog.expta.com/2017/03/how-to-self-elevate-powershell-script.html

Creating customer service Calendar in D365 via PowerShell command

I want to create "customer service Calendar" in D365 via PowerShell command. Can anyone help me? Thanks in advance
I have tried something like this, can able to create calendar not calendarurle
$usercalendarid="4385DF09-D156-4D4E-BABE-E6548DF50B49"
$StandardBUid ="BCAF91CC-5D73-EA11-A811-000D3AB855E7"
$mainCalendarGuid="4385DF09-D156-4D4E-BABE-E6548DF50B49"
$innerCalendarGuid="9566ab3e-208f-40cb-9b01-35110efa1161"
$businessunit = Get-CrmRecord -conn $conn -EntityLogicalName businessunit -Id $StandardBUid -Fields name
$standardBUReference = New-CrmEntityReference -EntityLogicalName businessunit -Id $StandardBUid
$calendarTypeValue = New-Object -TypeName Microsoft.Xrm.Sdk.OptionSetValue -ArgumentList 1
$calendarid = New-Object -TypeName System.Guid $mainCalendarGuid
New-CrmRecord -conn $conn -EntityLogicalName calendar -Fields #{"name"="cale2";"type"=$calendarTypeValue;"businessunitid"=$standardBUReference;calendarid=$calendarid }
*-- Create innercalendar*
$innerscalendarid = New-Object -TypeName System.Guid $innerCalendarGuid
$calendarTypeValue = New-Object -TypeName Microsoft.Xrm.Sdk.OptionSetValue -ArgumentList -1
New-CrmRecord -conn $conn -EntityLogicalName calendar -Fields #{"name"="inner";"businessunitid"=$standardBUReference; calendarid=$innerscalendarid }
-- Create calendarrule
$createdInnerCalendarReference = New-CrmEntityReference -EntityLogicalName calendar -Id $innerCalendarGuid
$createdMainCalendarReference = New-CrmEntityReference -EntityLogicalName calendar -Id $mainCalendarGuid
$timezoneValue = New-Object -TypeName Microsoft.Xrm.Sdk.OptionSetValue -ArgumentList 190
$entCollectioncalendarRules = New-Object Microsoft.Xrm.Sdk.EntityCollection
[Microsoft.Xrm.Sdk.Entity]$calendarRuleEntity = New-Object Microsoft.Xrm.Sdk.Entity
$calendarRuleEntity.LogicalName = 'calendarrule'
$calendarRuleEntity.Id= New-Object -TypeName System.Guid '9d3423b2-c69e-46db-9fde-b7f68784286c'
$calendarRuleEntity.Attributes['duration']=1234
$calendarRuleEntity.Attributes['calendarid']=$createdMainCalendarReference
$calendarRuleEntity.Attributes['innercalendarid']=$createdInnerCalendarReference
$calendarRuleEntity.Attributes['effort']=1.0;
$calendarRuleEntity.Attributes['extentcode']=1;
$calendarRuleEntity.Attributes['pattern'] = "FREQ=DAILY;COUNT=1"
$calendarRuleEntity.Attributes['rank']=0
$calendarRuleEntity.Attributes['timezonecode']=110
$calendarRuleEntity.Attributes['starttime'] = Get-Date
$calendarRuleEntity.Attributes['innercalendarid'] =$createdInnerCalendarReference
$calendarRuleEntity.Attributes['calendarid'] = $createdMainCalendarReference
$entCollectioncalendarRules.Entities.Add($calendarRuleEntity)
$entCollectioncalendarRules.Entities.Add($calendarRuleEntity1)
-- Update Calendarrule to calendar
$calendartobeUpdated = Get-CrmRecord -conn $conn -EntityLogicalName calendar -Id $innerCalendarGuid -Fields *
$calendartobeUpdated.name="Updated from powershell 2"
$calendartobeUpdated.calendarrules.Entities.Add($calendarRuleEntity)
Set-CrmRecord -conn $conn -CrmRecord $calendartobeUpdated

Powershell in UIPath. Throw : Unable to cast object of type 'Microsoft.Exchange.WebServices.Data.GetItemResponse' to type 'System.String'

I am trying to grab emails from Exchange using powershell in UI Path. When trying to return the items, I get the following error:
Throw : Unable to cast object of type 'Microsoft.Exchange.WebServices.Data.GetItemResponse' to type 'System.String'.
Even when I change the TypeArgument in UI Path. Currently I am using the Invoke power shell activity but I get the same issues using the RunPowershellScript activity. Below is a screenshot of my sequence in UI Path, my parameters, and my powershell script, Thank you!
Param(
[parameter()]
[string]$mailbox,
[parameter()]
[string]$password
)
try{
#https://forum.uipath.com/t/get-argument-from-an-process-with-exception-in-reframework/22537/4
function test-password(){
$Creds = new-object System.Net.networkCredential -ArgumentList $mailbox, $password
$mailFolder = "Inbox"
$itemView = 3
#[Reflection.Assembly]::LoadFile("C:\Program Files\Microsoft\Exchange\Web Services\2.2\Microsoft.Exchange.WebServices.dll")
$ExSer = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP1)
$ExSer.Credentials = ($Creds)
$ExSer.Url = new-object Uri("https://outlook.office365.com/EWS/Exchange.asmx")
$ExSer.AutodiscoverUrl($mailbox, {$true})
$setMailFolder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($ExSer,[Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox)
$logs2 += "Successfully Connected to mailbox $mailbox"
$iv = new-object Microsoft.Exchange.WebServices.Data.ItemView($itemView)
$CustomFilter = new-object Microsoft.Exchange.WebServices.Data.SearchFilter+SearchFilterCollection([Microsoft.Exchange.WebServices.Data.LogicalOperator]::And)
$ifIsRead = new-object Microsoft.Exchange.WebServices.Data.SearchFilter+IsEqualTo([Microsoft.Exchange.WebServices.Data.EmailMessageSchema]::IsRead,$false)
$ifFrom = new-object Microsoft.Exchange.WebServices.Data.SearchFilter+IsEqualTo([Microsoft.Exchange.WebServices.Data.EmailMessageSchema]::From,"filteremail#mycompany.com")
$CustomFilter.add($ifIsRead)
$CustomFilter.add($ifFrom)
$filteredEmails = $ExSer.FindItems($setMailFolder.Id,$CustomFilter, $iv)
$psPropertySet = new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)
$psPropertySet.RequestedBodyType = [Microsoft.Exchange.WebServices.Data.BodyType]::Text;
#add-type "Microsoft.Exchange.WebServices.Data.GetItemResponse"
$ExSer.LoadPropertiesForItems($filteredEmails,$psPropertySet)
$item = $filteredEmails.Items[0]
return $mailbox, $item
}
test-password
}
catch{
Throw
}
I commented out the load dll as it seemed to work without it and was throwing a similar error when it hit it. The code seems to throw an error when it hits $Exser.LoadPropertyItems. I have also tried switching to Exchange 2007 etc. To clarify, when running purely powershell outside of UI Path, this code works just fine.
I figured it out....I was just being a dingus. It was trying to load an object, which was breaking it. If I saved it as a variable and then converted it within my script and returned what I needed as a string....guess what? It could understand the string. Below is my updated powershell.
Param(
[parameter()]
[string]$mailbox,
[parameter()]
[string]$password
)
try{
#https://forum.uipath.com/t/get-argument-from-an-process-with-exception-in-reframework/22537/4
function test-password(){
$Creds = new-object System.Net.networkCredential -ArgumentList $mailbox, $password
$mailFolder = "Inbox"
$itemView = 50
# Add-Type -Path "C:\Program Files\Microsoft\Exchange\Web Services\2.2\Microsoft.Exchange.WebServices.dll"
#[Reflection.Assembly]::LoadFile("C:\Program Files\Microsoft\Exchange\Web Services\2.2\Microsoft.Exchange.WebServices.dll")
$ExSer = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP1)
$ExSer.Credentials = ($Creds)
$ExSer.Url = new-object Uri("https://outlook.office365.com/EWS/Exchange.asmx")
$ExSer.AutodiscoverUrl($mailbox, {$true})
$setMailFolder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($ExSer,[Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox)
$logs2 += "Successfully Connected to mailbox $mailbox"
$iv = new-object Microsoft.Exchange.WebServices.Data.ItemView($itemView)
$CustomFilter = new-object Microsoft.Exchange.WebServices.Data.SearchFilter+SearchFilterCollection([Microsoft.Exchange.WebServices.Data.LogicalOperator]::And)
$ifIsRead = new-object Microsoft.Exchange.WebServices.Data.SearchFilter+IsEqualTo([Microsoft.Exchange.WebServices.Data.EmailMessageSchema]::IsRead,$true)
$ifFrom = new-object Microsoft.Exchange.WebServices.Data.SearchFilter+IsEqualTo([Microsoft.Exchange.WebServices.Data.EmailMessageSchema]::From,"emailtofilterby#mycompany.com")
$CustomFilter.add($ifIsRead)
$CustomFilter.add($ifFrom)
$filteredEmails = $ExSer.FindItems($setMailFolder.Id,$CustomFilter, $iv)
$psPropertySet = new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)
$psPropertySet.RequestedBodyType = [Microsoft.Exchange.WebServices.Data.BodyType]::Text;
#add-type "Microsoft.Exchange.WebServices.Data.GetItemResponse"
$FilteredEmailitems = $ExSer.LoadPropertiesForItems($filteredEmails,$psPropertySet)
$EmailBody = $FilteredEmailitems.Item(0) | Select-Object -ExpandProperty Item | Select-Object -ExpandProperty Body | Select-Object -ExpandProperty Text
return $EmailBody
}
test-password
}
catch{
Throw
}

Create a user in MongoDb using powershell

I'm using MongoDb v3.0.3 and want to create a user in a database with admin privileges using powershell. I hook into the C# driver but I don't get very far:
$pathToMongoDbCSharpDriver = "F:\Work\...\mongocsharpdriver.1.9.2\lib\net35"
Add-Type -Path "$pathToMongoDbCSharpDriver\MongoDB.Bson.dll"
Add-Type -Path "$pathToMongoDbCSharpDriver\MongoDB.Driver.dll"
$client = New-Object -TypeName MongoDB.Driver.MongoClient -ArgumentList "mongodb://localhost:30000"
$server = $client.GetServer()
$databaseName = "Dev"
$collectionName = "Settings"
$database = $server.GetDatabase($databaseName)
$collection = $database.GetCollection($collectionName)
$credentials = New-Object -TypeName MongoDB.Driver.MongoCredential("Admin", "password", $true);
$user = New-Object -TypeName MongoDB.Driver.MongoUser($credentials, $false)
$credentials fails because argument 1 it is not a MongoIdentity and I can't find any information about how to create one of these. Any help would be gratefully received
I use all the parameters in the argument list. The following works fine for me:
$Client = New-Object -TypeName MongoDB.Driver.MongoClient -ArgumentList "mongodb://dbuser:dbpass#localhost:27017/test"