Powershell Error creating entry through WSDL SOAP connection - powershell

So I am getting a conversion error when submitting something via WSDL SOAP in PowerShell.
I am trying to create entries in a system called Kablink however although the entry has all the values etc. in the variable $soapData when I attempt the actual creation I get an error about being unable convert argument entry from one value to another even though both specified values are the same.
Cannot convert argument "entry", with value: "folder_addEntry.FolderEntry", for "folder_addEntry" to type "folder_addEntry.FolderEntry": "Cannot convert the "folder_addEntry.FolderEntry" value of type
"folder_addEntry.FolderEntry" to type "folder_addEntry.FolderEntry"."
Any ideas would be hugely appreciated as this is now driving me insane.
Below is the script I am using
$kablinkSoapUrl = "http://servername/ssr/secure/ws/TeamingServiceV1?wsdl"
$kablinkConnector = New-WebServiceProxy -Uri $kablinkSoapUrl -Credential $Credential -namespace "folder_addEntry"
#Set Binder ID to Shift Rota entries folder
$binderID = 155
#write-host $soapData
#Import Objects and Populate Default Values
$soapDescription = New-Object ("folder_addEntry.Description")
$soapDescription.text = "Some Description"
$soapDescription.format = 0
$soapAttachment = New-Object("folder_addEntry.attachmentsField")
$soapAttachment.name = ""
$soapAttachment.type = ""
$soapAttachment.attachments = #()
$soapCreate = New-Object ("folder_addEntry.Timestamp")
$soapCreate.date = get-date
$soapCreate.principal = ""
$soapCreate.principalId = 2
$soapModify = New-Object ("folder_addEntry.Timestamp")
$soapModify.date = get-date
$soapModify.principal = ""
$soapModify.principalId = 2
$soapRating = New-Object ("folder_addEntry.AverageRating")
$soapRating.averageRating = ""
$soapRating.ratingCount = ""
$soapCustBool = New-Object ("folder_addEntry.CustomBooleanField")
$soapCustBool = #()
$soapCustDate = New-Object ("folder_addEntry.CustomDateField")
$soapCustDate = #()
$soapCustEven = New-Object ("folder_addEntry.CustomEventField")
$soapCustEven = #()
$soapCustLong = New-Object ("folder_addEntry.CustomLongArrayField")
$soapCustLong = #()
$soapCustStriArr = New-Object ("folder_addEntry.CustomStringArrayField")
$soapCustStriArr = #()
$soapCustStr = New-Object ("folder_addEntry.CustomStringField")
$soapCustStr = #()
#Construct Entry
$soapData = New-Object -TypeName folder_addEntry.FolderEntry
$soapData.attachmentsField = $soapAttachment
$soapData.averageRating = $soapRating
$soapData.creation = $soapCreate
$soapData.customBooleanFields = $soapCustBool
$soapData.customDateFields = $soapCustDate
$soapData.customEventFields = $soapCustEven
$soapData.customLongArrayFields = $soapCustLong
$soapData.customStringArrayFields = $soapCustStriArr
$soapData.customStringFields = $soapCustStr
$soapData.definitionId = "8a8ab38c62d40d5c0162fc8330eb01ad"
$soapData.description = $soapDescription
$soapData.entityType = "fileEntry"
$soapData.eventAsIcalString = 0
$soapData.family = "file"
$soapData.id = ""
$soapData.modification = $soapModify
$soapData.parentBinderId = 155
$soapData.permaLink = ""
$soapData.title = "PowerShell Entry"
$soapData.docLevel = 1
$soapData.docNumber = ""
$soapData.href = ""
$soapData.preDeleted = 0
$soapData.preDeletedBy = ""
$soapData.preDeletedWhen = ""
$soapData.reservedBy = ""
$soapData.workflows = #()
# Print Soap Data
$soapData
# Submit Entry
$kablinkConnector.folder_addEntry("",$soapData,"")
Thanks in advance.

Added -class "folder_getEntry" when creating the $kablinkConnector variable making the line
$kablinkConnector = New-WebServiceProxy -Uri $kablinkSoapUrl -Credential $Credential -namespace "folder_addEntry" -class "folder_getEntry"
And now it works

Related

how to make power shell script from qrcode desktop application

I have created desktop application with generate qr code like below
I want make a script using batch script or powershell with the qrcode.exe based on value enter url and Qr Image Name using command line.the output should be QR Code Image too.
can try with this but first import the QRCodeGenerator before running the script
#Import-Module QRCodeGenerator
[string] $webname, [string] $url, [string] $output = ".\images\"
$webname = 'Google'
$url = 'https://www.google.com'
$outputfolder = $outputfolder + $webname +'.JPG'
New-PSOneQRCodeURI -URI $url -Width 15 -OutPath $output
and then the output result will be showing as JPG type.
Install-Module -Name QRCodeGenerator
Import-Module QRCodeGenerator
Add-Type -assembly System.Windows.Forms
$qr_base_form = New-Object System.Windows.Forms.Form
$qr_base_form.Height = 150
$qr_base_form.Width = 350
$qr_base_form.Text = "QR Code Generator"
$qr_base_form.AutoSize = $true
$qr_label_url = New-Object System.Windows.Forms.Label
$qr_label_url.Location = '10,10'
$qr_label_url.Size = '100,15'
$qr_label_url.Text = "URL:"
$qr_input_url = New-Object System.Windows.Forms.TextBox
$qr_input_url.Location = '10,30'
$qr_input_url.Size = '100,25'
$qr_label_name = New-Object System.Windows.Forms.Label
$qr_label_name.Location = '10,70'
$qr_label_name.Size = '100,15'
$qr_label_name.Text = "Name:"
$qr_input_name = New-Object System.Windows.Forms.TextBox
$qr_input_name.Location = '10,90'
$qr_input_name.Size = '100,25'
$qr_png_viewer = New-Object System.Windows.Forms.PictureBox
$qr_png_viewer.Image = $img
$qr_png_viewer.SizeMode = "Autosize"
$qr_png_viewer.Anchor = "Bottom, left"
$qr_png_viewer.Location = '150,10'
$qr_button_create = New-Object System.Windows.Forms.Button
$qr_button_create.Location = '150,150'
$qr_button_create.Size = '100,25'
$qr_button_create.Text = "Create Code"
$qr_button_create.Add_Click({
$path = "H:\LIVE\" + "$name"+ ".jpg"
$urllink = $qr_input_url.Text
$name = $qr_input_name.Text
New-PSOneQRCodeURI -URI "$urllink" -Width 15 -OutPath "$path"
$img = $path
})
$qr_base_form.Controls.Add($qr_label_url)
$qr_base_form.Controls.Add($qr_input_url)
$qr_base_form.Controls.Add($qr_label_name)
$qr_base_form.Controls.Add($qr_input_name)
$qr_base_form.Controls.Add($qr_png_viewer)
$qr_base_form.Controls.Add($qr_button_create)
$qr_base_form.ShowDialog()
This code should work for you. Just try changing the variables and try running it. GUI is also included.

Powershell UI - DialogResult - PropertyAssignmentException

I am creating a powershell UI for some Script.
Now I am running in an error. But first, here is my code of my form:
$form_appBase = New-Object System.Windows.Forms.Form
$form_appBase.Text = 'APP Policy creator'
$form_appBase.Width = 350
$form_appBase.Height = 150
$form_appBase.AutoSize = $true
$label_appFilename = New-Object System.Windows.Forms.Label
$label_appFilename.Location = '10,10'
$label_appFilename.Size = '200,15'
$label_appFilename.Text = 'Program'
$Textbox_appFilename = New-Object System.Windows.Forms.TextBox
$Textbox_appFilename.Location = '10,30'
$Textbox_appFilename.Size = '200,25'
$label_appVersion = New-Object System.Windows.Forms.Label
$label_appVersion.Location = '220,10'
$label_appVersion.Size = '100,15'
$label_appVersion.Text = 'Version:'
$Textbox_appVersion = New-Object System.Windows.Forms.TextBox
$Textbox_appVersion.Location = '220,30'
$Textbox_appVersion.Size = '100,25'
$label_appProgPath = New-Object System.Windows.Forms.Label
$label_appProgPath.Location = '10,60'
$label_appProgPath.Size = '130,15'
$label_appProgPath.Text = 'Path to PROG Policy'
$textbox_appProgPath = New-Object System.Windows.Forms.TextBox
$textbox_appProgPath.Location = '150,60'
$textbox_appProgPath.Size = '170,25'
$Radio_appBaseSW = New-Object System.Windows.Forms.RadioButton
$Radio_appBaseSW.Location = '10,90'
$Radio_appBaseSW.Size = '100,15'
$Radio_appBaseSW.Text = "Software"
$Radio_appBaseSW.DialogResult = [System.Windows.Forms.DialogResult]::SW
$Radio_appBaseHW = New-Object System.Windows.Forms.RadioButton
$Radio_appBaseHW.Location = '10,110'
$Radio_appBaseHW.Size = '100,15'
$Radio_appBaseHW.Text = "Hardware"
$Radio_appBaseHW.DialogResult = [System.Windows.Forms.DialogResult]::HW
$Button_appConfirm = New-Object System.Windows.Forms.Button
$Button_appConfirm.Location = '220,95'
$Button_appConfirm.Size = '100,30'
$Button_appConfirm.Text = "Create"
$form_appBase.Controls.Add($label_appFilename)
$form_appBase.Controls.Add($Textbox_appFilename)
$form_appBase.Controls.Add($label_appVersion)
$form_appBase.Controls.Add($Textbox_appVersion)
$form_appBase.Controls.Add($label_appProgPath)
$form_appBase.Controls.Add($textbox_appProgPath)
$form_appBase.Controls.Add($Radio_appBaseSW)
$form_appBase.Controls.Add($Radio_appBaseHW)
$form_appBase.Controls.Add($Button_appConfirm)
$form_appBase.AcceptButton = $Button_appConfirm
$dialogResultSHW = $form_appBase.ShowDialog()
}
$Button_appConfirm.Add_click(
{
if ($dialogResultSHW -eq "SW"){$appSHW = "SW"}
elseif ($dialogResultSHW -eq "HW"){
$appSHW = "HW"
$appFilename = $Textbox_appFilename.Text
$appVersion = $Textbox_appVersion.Text
$appProgPath = $textbox_appProgPath.Text
$appUNCPath = "\\zen\netlogon\applocker\Output + '\' + $appSHW + '-' + $appFilename + '-' $appVersion + '.' + 'xml' "
Write-Host "$appFilename"
Write-Host "$appVersion"
Write-Host "$appProgPath"
Write-Host "$appSHW"
Write-Host "$appUNCPath"
powershell.exe -file \\zen\netlogon\applocker\applockerwork.ps1 -application -in $appProgPath -out $appUNCPath
}
}
)
After checking everything, I get the following error:
Powershell_Error
Can anyone help me to find out why this error persists? I tried many Ideas I found on the WWW but nothing seemed to work.
First of all, the [System.Windows.Forms.DialogResult] enum does not have values like "SW" or "HW"..
Remove the lines $Radio_appBaseSW.DialogResult = ... and $Radio_appBaseHW.DialogResult = ... because as guiwhatsthat commented, the RadioButtonClass does not have such a property.
Also change $dialogResultSHW = $form_appBase.ShowDialog() into [void]$form_appBase.ShowDialog()
Then, in your $Button_appConfirm.Add_click({..}) event, do
$appSHW = if ($Radio_appBaseSW.Checked) { "SW" } elseif ($Radio_appBaseHW.Checked) {"HW"}
and use the value of $appSHW do perform the different actions, or simply do
if ($Radio_appBaseSW.Checked) {
# perform action for choice Software
}
elseif ($Radio_appBaseHW.Checked) {
perform a different action for choice Software
}
else {
# no radiobutton was touched... Alert the user to select either the Software or the Hardware radio button
}
Finally, do not forget to remove the form from memory when you are done with it with $form_appBase.Dispose()

Create AD user in a different domain

I created a series of scripts for creating domain users. Since every domain where we create users requires different parameters and conditions, I have one script for each domain. But in case of one domain I have a problem. For this domain the manual procedure is like this:
1) open dsa.msc
2) connect to the "xyz" domain (the user is being created from a server in "abc" domain)
3) Create the user (operation for 10 to 15 minutes, that's why I created the scripts)
Unfortunately, when I run my script, I get the error message, that "The server is unwilling to process the request" (That's the precise complete error message) during execution of New-ADUser cmdlet. I suppose the reason is the need to perform the step 2 in the procedure I described above. So I somehow need to simulate it in the script, but I have no idea how to do that.
This is how the command is defined:
$params = #{
'GivenName' = $First_name_val.Text
'Surname' = $Second_name_val.Text
'DisplayName' = $Display_name
'AccountPassword' = $password
'Path' = $Location_val.Text
'Name' = $User_name_val.Text
'CannotChangePassword' = $Cannot_chg_pass.Checked
'PasswordNeverExpires' = $Pass_not_expires.Checked
'ChangePasswordAtLogon' = $Must_chg_pass.Checked
'Enabled' = !($Account_disabled_val.Checked)
'Description' = $GECOS_val.Text
'Office' = "NA"
'OfficePhone' = "NA"
'Title' = $Job_Title_val.Text
'Department' = $Department_val.Text
'Company' = $Company_val.Text
'SamAccountName' = $User_name_val.Text
'UserPrincipalName' = $User_name_val.Text + "#woodplc.com"
'EmailAddress' = $Email_Address_val.Text
'PassThru' = $true
}
$New_user = New-ADUser #params
Definition of $User_name_val.Text is here:
#region Real name of the user
[void]$AD_user_creation.SuspendLayout()
$Display_name_lbl = New-Object system.Windows.Forms.Label
$Display_name_lbl.text = "User`'s real name"
$Display_name_lbl.AutoSize = $true
$Display_name_lbl.width = 25
$Display_name_lbl.height = 10
$Display_name_lbl.location = New-Object System.Drawing.Point(10,10)
$First_name_val = New-Object system.Windows.Forms.TextBox
$First_name_val.Text = "a."
$First_name_val.multiline = $false
$First_name_val.width = 120
$First_name_val.height = 20
$First_name_val.location = New-Object System.Drawing.Point(200,10)
$Second_name_val = New-Object system.Windows.Forms.TextBox
$Second_name_val.multiline = $false
$Second_name_val.width = 120
$Second_name_val.height = 20
$Second_name_val.location = New-Object System.Drawing.Point(330,10)
$Display_name_val = New-Object system.Windows.Forms.Label
$Display_name_val.Text = ""
$Display_name_val.width = 250
$Display_name_val.height = 20
$Display_name_val.location = New-Object System.Drawing.Point(200,40)
$showFullName = { $Display_name_val.Text = ($First_name_val.Text + "." + $Second_name_val.Text) }
[void]$Second_name_val.Add_Leave( { & $showFullName } )
[void]$First_name_val.Add_Leave( { & $showFullName } )
#endregion
#region User name of the user
$User_name_lbl = New-Object system.Windows.Forms.Label
$User_name_lbl.text = "User logon name"
$User_name_lbl.AutoSize = $true
$User_name_lbl.width = 25
$User_name_lbl.height = 10
$User_name_lbl.location = New-Object System.Drawing.Point(10,70)
$User_name_val = New-Object system.Windows.Forms.TextBox
$User_name_val.multiline = $false
$User_name_val.width = 250
$User_name_val.height = 20
$User_name_val.location = New-Object System.Drawing.Point(200,70)
$LogonName = {$User_name_val.Text = ($First_name_val.Text + "." + $Second_name_val.Text)}
[void]$Second_name_val.Add_Leave({& $LogonName})
[void]$First_name_val.Add_Leave({& $LogonName})
[void]$AD_user_creation.ResumeLayout()
#endregion
The error "The server is unwilling to process the request" means that some of your input values are invalid. For example, the OU you are providing could be invalid (maybe a space that shouldn't be there), or the SamAccountName might be too long or contain an invalid character, etc.
If you show the full command you are using I might be able to spot something.
If there was an issue connecting to the server or authenticating, then the error message would be different.

Getting more information selecting by a Combobox Powershell

Hello guys I'm currently coding an IHM in powershell to configure switches. I'm using a combobox to select a model. The combobx is generated using a dataview generated by a datasource, and the datasource is generated from a csv file by a foreach.
My problem is the following : I can only recover a single column.
Combobox:
$list1 = New-Object System.Windows.Forms.Combobox
$list1.Location = New-Object Drawing.Point 9,45
$list1.Size = New-Object System.Drawing.Size(250,30)
$list1.DropDownStyle = "DropDownList"
$list1.BindingContext = New-Object System.Windows.Forms.BindingContext
$list1.DataSource = $vu1
$list1.ValueMember = "Model"
$list1.DisplayMember = "Model"
$list1.SelectedValue = ""
$mainfrm.controls.add($list1)
Reading infos
Write-Host "$list1.SelectedValue"
Edit foreach and creation of the dataview
foreach:
$ImportData = import-csv "E:\PS\A faire\equipement.csv" -Delimiter ';' | Select Model,Type,Port,Firmware,Comware
$table1 = New-Object system.Data.DataTable
$colonne1 = New-Object system.Data.DataColumn Model,([string])
$table1.columns.add($colonne1)
$colonne2 = New-Object system.Data.DataColumn Port,([string])
$table1.columns.add($colonne2)
$colonne3 = New-Object system.Data.DataColumn Comware,([string])
$table1.columns.add($colonne3)
$colonne4 = New-Object system.Data.DataColumn Firmware,([string])
$table1.columns.add($colonne4)
foreach ($data in $ImportData)
{
$model = $data.Model
$type = $data.Type
$port = $data.Port
$firmware = $data.Firmware
$comware= $data.Comware
$ligne1 = $table1.NewRow()
$ligne1.Model = "$model "+"$type"
$ligne1.Port = "$port"
$ligne1.Comware = "$comware"
$ligne1.Firmware = "$firmware"
$table1.Rows.Add($ligne1)
}
Dataview
$vu1 = New-Object System.Data.DataView($table1)
Instead of using 4 colums in the datasource I put everything in one and then a split.
Code after :
$ligne1.Model = "$model "+"$type " + "$port " + "$comware " + "$firmware "
Then you can use a split() to have a usable value.

Powershell Open Port Profile, All (private public domain)

I've a powershell script that opens port 5555, but it defaults to profile = private, when I want it to be all (private, public, domain). How can I modify the script to achieve this?
$port = New-Object -ComObject HNetCfg.FWOpenPort
$port.Port = 5555
$port.Name = 'MyPort'
$port.Enabled = $true
$fwMgr = New-Object -ComObject HNetCfg.FwMgr
$profile = $fwMgr.LocalPolicy.CurrentProfile
$profile.GloballyOpenPorts.Add($port)
$port = New-Object -ComObject HNetCfg.FWOpenPort
$port.Port = 6521
$port.Name = 'ArkleSQL'
$port.Enabled = $true
$fwMgr = New-Object -ComObject HNetCfg.FwMgr
$profile = $fwMgr.LocalPolicy.CurrentProfile
$profile.GloballyOpenPorts.Add($port)
You can use FwPolicy2 and FWRule to create a rule for all profiles:
$fwPolicy = New-Object -ComObject HNetCfg.FwPolicy2
$rule = New-Object -ComObject HNetCfg.FWRule
$rule.Name = 'MyPort'
$rule.Profiles = $NET_FW_PROFILE2_ALL
$rule.Enabled = $true
$rule.Action = $NET_FW_ACTION_ALLOW
$rule.Direction = $NET_FW_RULE_DIR_IN
$rule.Protocol = $NET_FW_IP_PROTOCOL_TCP
$rule.LocalPorts = 5555
$fwPolicy.Rules.Add($rule)
Here are the used constants:
$NET_FW_PROFILE2_DOMAIN = 1
$NET_FW_PROFILE2_PRIVATE = 2
$NET_FW_PROFILE2_PUBLIC = 4
$NET_FW_PROFILE2_ALL = 2147483647
$NET_FW_IP_PROTOCOL_TCP = 6
$NET_FW_IP_PROTOCOL_UDP = 17
$NET_FW_IP_PROTOCOL_ICMPv4 = 1
$NET_FW_IP_PROTOCOL_ICMPv6 = 58
$NET_FW_RULE_DIR_IN = 1
$NET_FW_RULE_DIR_OUT = 2
$NET_FW_ACTION_BLOCK = 0
$NET_FW_ACTION_ALLOW = 1
(Source: http://www.ohmancorp.com/files/RefWin-AdvFirewall-JCopyFWRules.txt)
There are two values that the COM object for firewall management. 0 represents domain networks and 1 represents standard networks. There doesn't seem (in this API) to be a differentiation between this public and private profiles.
You can replace the last section of
$fwMgr = New-Object -ComObject HNetCfg.FwMgr
$profile = $fwMgr.LocalPolicy.CurrentProfile
$profile.GloballyOpenPorts.Add($port)
with
$Profiles = #{
NET_FW_PROFILE_DOMAIN = 0
NET_FW_PROFILE_STANDARD = 1
}
$fwMgr = New-Object -ComObject HNetCfg.FwMgr
$profile.GloballyOpenPorts.Add($port)
foreach ($ProfileKey in $Profiles.Keys)
{
$Profile = $fwMgr.LocalPolicy.GetProfileByType($profiles[$ProfileKey])
$Profile.GloballyOpenPorts.Add($Port)
}