Array in Powershell - powershell

I used to work with array in VBSCRIPT like below… I am not sure how I should do it in PowerShell… Can any help me out…?
CODE --> VBSCRIPT
dim arrErrors(12)
arrErrors(0) = "APP0"
arrErrors(1) = " APP1"
arrErrors(2) = " APP2"
arrErrors(3) = " APP3”
arrErrors(4) = "APP4"
arrErrors(5) = "APP5"
arrErrors(6) = "APP6"
arrErrors(7) = "APP7"
arrErrors(8) = "APP8"
arrErrors(9) = "APP9"
arrErrors(10) = "APP10"
arrErrors(11) = "APP11"
arrErrors(12) = "APP12"
for i = 0 to ubound(arrErrors)
strError = arrErrors(i)
if (left(lcase(strErrorLine), len(strError)) = lcase(strError)) then
objErrorLog.WriteLine strErrorLine & vbTab & strComputer & vbTab & "Found Error number" & vbTab & i
exit for
end If

Create a hash table. Populate it with error names and values. Parse the error string and look if the hash table contains it. Like so,
$htErr = #{ "app0" = 0; "app1" = 1; "app2" = 2 } # Populate hash table
$error = ... # get the error string from somewhere.
if($htErr[$error]) {
"Found error, code " + $htErr[$error] # Get code based on error string
}

Related

Get data return from call function from soap is difference language

I have my project about soap.
I can call function from wsdl successfully but the string return is "????" which "???" is thai language.
server.php
<?php
require_once("lib/nusoap.php");
$server = new soap_server();
//$server->soap_defencoding = 'utf-8';
$server->decode_utf8 = false;
//$server->configureWSDL("Testing WSDL ","urn:Testing WSDL ");
$server->configureWSDL("GetInformation","urn:GetInformation");
//Create a complex type
//----------------------------------
//Add ComplexType with Array
$server->wsdl->addComplexType("ArrayOfString",
"complexType",
"array",
"",
"SOAP-ENC:Array",
array(),
array(array("ref"=>"SOAP- ENC:arrayType","wsdl:arrayType"=>"xsd:string[]")),
"xsd:string");
//----------------------------------
$server->register('getInfo',array('CASE_ID' => 'xsd:string'),array('return' => 'tns:ArrayOfString'),'urn:Info','urn:Info#getInfo');
function getInfo($case_id) {
include("ConnectSQL.php");
$dbhandle = mssql_connect($myServer, $myUser, $myPass)
or die("Couldn't connect to SQL Server on $myServer");
//select a database to work with
$selected = mssql_select_db($myDB, $dbhandle)
or die("Couldn't open database $myDB");
$strCase_ID = $case_id;
// Query
$qry = "SELECT * ";
$qry .= "FROM tbCustomer WHERE CASE_ID = '$strCase_ID' ";
//$arr[0]= $qry;
//execute the SQL query and return records
$result = mssql_query($qry);
//$arr[0] = $strCase_ID;
$i = 0;
$recordcount = mssql_num_rows($result);
if ($recordcount != 0)
{
//display the results
while($row = mssql_fetch_array($result))
{
$myname = $row["PREFIX"] ." ". $row["NAME"] ." ". $row["MIDDLE"]." " ;
$arr[$i] = $myname;
$i = $i+1;
}
//close the connection
mssql_close($dbhandle);
//return $myname; //iconv("ISO-8859-1", "UTF-8", $myname );
return $arr;
}
else
{
return $arr;
//echo "<font color=red>**</font> Username & Password is wrong";
}
}
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
exit();
?>
client side:
Dim clnt As New SoapClient30
Dim strText
Dim strID As String
clnt.MSSoapInit "http://localhost/MyProject4/server.php?wsdl"
strID = "001"
strText = clnt.getInfo(strID)
MsgBox strText(0)
I don't know way for encode from vb6 client.
thank you

PDF email from Access

I am trying to email a submission form based on the click of a command button. I have created the code to filter the form based on the 4 primary keys. But when I run the code the FleetID portion is pulling up as blank in the Immediate Pane. The FleetID portion is provided in a combobox. Can somebody help me?
Thanks
On Error GoTo errhandle
Me.Filter = "CurrentDate= #" & Format(Me!CurrentDate, "yyyy\-mm\-dd") & "# and DiscoverTime= '" & Me!DiscoverTime & "' And TailNumber= '" & Me!TailNumber & "' And FleetID= '" & Me!FleetID & "'"
Debug.Print Me.Filter
Me.FilterOn = True
DoCmd.SendObject acSendForm, "frmETIC", acFormatPDF, "EMAIL", "", "", "Recovery Report", "Attached is the submitted Recovery Report"
exiterr:
Exit Sub
errhandle:
If Err.Number <> 2501 Then
MsgBox ("Email cancelled!")
End If
Resume exiterr
Apart from my suggestions in the comment section. I would personally create a query and a desired report from that query. Reports gives you a very neat and professional look unlike forms with their extra controls.
First create a query same like your forms datasource
Create report out of that query. Design your report with your logo footer and all other stuffs you would like to have also the printing margin.
Generate your report with where condition and use the docmd.sendobject
Alternatively
Generate your report hidden with your where condition
Save the report as PDF file using docmd.outputTo
create new outlook email object and attach the PDF file
both ways have their own advantages. i personally use the second one because its much easier for me to customize the email content/template.
Here is a function to create emails:
Function SEND_EMAIL_MESSAGE(mTo As String, mCC As String, mBC As String, mSubject As String, mBody As String, Optional useOwnSignature As Boolean = False, Optional DisplayMsg As Boolean = False, Optional isHTML As Boolean = False, Optional AttachmentPath = "") As Boolean
' Please check the reference for Microsoft Outlook 14.0 object library for outlook 2010.
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookAttach As Outlook.Attachment
Dim mSignature As String
On Error GoTo ERROR_EMAIL
' Create the Outlook session.
Set objOutlook = New Outlook.Application
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
' Add the To recipient(s) to the message.
.To = mTo
.CC = mCC
.BCC = mBC
.Subject = mSubject
If useOwnSignature Then .BodyFormat = olFormatHTML
.Display
If useOwnSignature Then
If isHTML Then
mSignature = .HTMLBody
.HTMLBody = mBody & mSignature
Else
mSignature = .Body
.Body = mBody & mSignature
End If
Else
.Body = mBody
End If
' Add attachments to the message.
If Not IsMissing(AttachmentPath) Then
Dim mFiles() As String
If (VBA.Right(AttachmentPath, 1)) <> ";" Then AttachmentPath = AttachmentPath & ";"
mFiles = VBA.Split(AttachmentPath, ";")
Dim i As Integer
For i = 0 To UBound(mFiles) - 1
If Not mFiles(i) = "" Then Set objOutlookAttach = .Attachments.Add(mFiles(i))
Next i
End If
' Should we display the message before sending?
If DisplayMsg Then
.Display
Else
.Send
End If
End With
SEND_EMAIL_MESSAGE = True
EXIT_ROUTINE:
On Error GoTo 0
Set objOutlook = Nothing
Set objOutlookMsg = Nothing
Exit Function
ERROR_EMAIL:
SEND_EMAIL_MESSAGE = False
GoTo EXIT_ROUTINE
End Function
and you here some code you can generate the report and send to email:
strReportName = "rpt_incident_view_single"
DoCmd.OpenReport strReportName, acViewPreview, , strCriteria, acHidden
Dim tmpPath As String
tmpPath = VBA.Environ("temp")
strMyPath = tmpPath
If VBA.Right(strMyPath, 1) = "\" Then
strMyPath = strMyPath & "_" & incident_id & "_" & VBA.Format(Now, "yyyy-dd-mm") & ".pdf"
Else
strMyPath = strMyPath & "\" & "_" & incident_id & "_" & VBA.Format(Now, "dd-mm-yyyy") & ".pdf"
End If
DoCmd.OutputTo acOutputReport, strReportName, acFormatPDF, strMyPath, False
after saving the report just send it to the email function which will create new email and show it to the user:
SEND_EMAIL_MESSAGE mTo, mCC, mBcc, mSubject, mBody,,,, strMyPath
DoCmd.Close acReport, strReportName
on error resume next
VBA.Kill strMyPath
just modify your code as per your needs. good luck :)

Assign Unicode Literals to PowerShell Hash Table

It's late and I am done for tonight--can someone please lend a hand on getting this to work? Do I need to do some additional work to get these Unicode strings assigned as literals?
First attempt at creating a hash table of double-encoded and desired key-value pairs:
[string] $double_encoded_values = #{
"€" = "€";
"‚" = "‚";
"Æ’" = "ƒ";
"„" = "„";
"…" = "…";
"â€" = "†";
"‡" = "‡";
"ˆ" = "ˆ";
"‰" = "‰";
"Å" = "Š";
"‹" = "‹";
"Å’" = "Œ";
"Ž" = "Ž";
"‘" = "‘";
"’" = "’";
"“" = "“";
"â€" = "”";
"•" = "•";
"–" = "–";
"—" = "—";
"Ëœ" = "˜" ;
"â„¢" = "™";
"Å¡" = "š";
"›" = "›";
"Å“" = "œ";
"ž" = "ž";
"Ÿ" = "Ÿ";
"¡" = "¡";
"¢" = "¢";
"£" = "£";
"¤" = "¤";
"Â¥" = "¥";
"¦" = "¦";
"§" = "§";
"¨" = "¨";
"©" = "©";
"ª" = "ª";
"«" = "«";
"¬" = "¬";
"®" = "®";
"¯" = "¯";
"°" = "°";
"±" = "±";
"²" = "²";
"³" = "³";
"´" = "´";
"µ" = "µ";
"¶" = "¶";
"·" = "·";
"¸" = "¸";
"¹" = "¹";
"º" = "º";
"»" = "»";
"¼" = "¼";
"½" = "½";
"¾" = "¾";
} # $double_encoded_values
My version:
PS C:\Windows\system32> $PSVersionTable.PSVersion
Major Minor Build Revision
----- ----- ----- --------
4 0 -1 -1
Error received:
At line:20 char:12
+ "–" = "–";
+ ~
Missing '=' operator after key in hash literal.
At line:20 char:12
+ "–" = "–";
+ ~
The hash literal was incomplete.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingEqualsInHashLiteral
Reference: http://www.i18nqa.com/debug/utf8-debug.html
PowerShell treats the “ in – as a double quote, effectively escaping the closing " in "–"
Use single quotes to avoid having PowerShell trying to parse the key names and values:
#{
'–' = '-'
}

Sending email with multiple attachments vb6

Can someone help me.How to send an email with multiples attachments.
I am using cdo and SMTP Send Mail for VB6. Everything works great except I am only able to send one attachment at a time.
here's the code
Public Function SendMail(sTo As String, sSubject As String, sFrom As String, _
sBody As String, sSmtpServer As String, iSmtpPort As Integer, _
sSmtpUser As String, sSmtpPword As String, _
sFilePath As String, bSmtpSSL As Boolean) As String
On Error GoTo SendMail_Error:
Dim lobj_cdomsg As CDO.Message
Set lobj_cdomsg = New CDO.Message
lobj_cdomsg.Configuration.Fields(cdoSMTPServer) = sSmtpServer
lobj_cdomsg.Configuration.Fields(cdoSMTPServerPort) = iSmtpPort
lobj_cdomsg.Configuration.Fields(cdoSMTPUseSSL) = bSmtpSSL
lobj_cdomsg.Configuration.Fields(cdoSMTPAuthenticate) = cdoBasic
lobj_cdomsg.Configuration.Fields(cdoSendUserName) = sSmtpUser
lobj_cdomsg.Configuration.Fields(cdoSendPassword) = sSmtpPword
lobj_cdomsg.Configuration.Fields(cdoSMTPConnectionTimeout) = 30
lobj_cdomsg.Configuration.Fields(cdoSendUsingMethod) = cdoSendUsingPort
lobj_cdomsg.Configuration.Fields.Update
lobj_cdomsg.To = sTo
lobj_cdomsg.From = sFrom
lobj_cdomsg.Subject = sSubject
lobj_cdomsg.TextBody = sBody
If Trim$(sFilePath) <> vbNullString Then
lobj_cdomsg.AddAttachment (sFilePath)
End If
lobj_cdomsg.Send
Set lobj_cdomsg = Nothing
SendMail = "ok"
Exit Function
SendMail_Error:
SendMail = Err.Description
End Function
Private Sub cmdSend_Click()
Dim retVal As String
Dim objControl As Control
For Each objControl In Me.Controls
If TypeOf objControl Is TextBox Then
If Trim$(objControl.Text) = vbNullString And LCase$(objControl.Name) <> "txtAttach" Then
Label2.Caption = "Error: All fields are required!"
Exit Sub
End If
End If
Next
Frame1.Enabled = False
Frame2.Enabled = False
cmdSend.Enabled = False
Label2.Caption = "Sending..."
retVal = SendMail(Trim$(txtTo.Text), _
Trim$(txtSubject.Text), _
Trim$(txtFromName.Text) & "<" & Trim$(txtFromEmail.Text) & ">", _
Trim$(txtMsg.Text), _
Trim$(txtServer.Text), _
CInt(Trim$(txtPort.Text)), _
Trim$(txtUsername.Text), _
Trim$(txtPassword.Text), _
Trim$(txtAttach.Text), _
CBool(chkSSL.Value))
Frame1.Enabled = True
Frame2.Enabled = True
cmdSend.Enabled = True
Label2.Caption = IIf(retVal = "ok", "Message sent!", retVal)
End Sub
Private Sub cmdBrowse_Click()
Dim sFilenames() As String
Dim i As Integer
On Local Error GoTo Err_Cancel
With cmDialog
.FileName = ""
.CancelError = True
.Filter = "All Files (*.*)|*.*|HTML Files (*.htm;*.html;*.shtml)|*.htm;*.html;*.shtml|Images (*.bmp;*.jpg;*.gif)|*.bmp;*.jpg;*.gif"
.FilterIndex = 1
.DialogTitle = "Select File Attachment(s)"
.MaxFileSize = &H7FFF
.Flags = &H4 Or &H800 Or &H40000 Or &H200 Or &H80000
.ShowOpen
' get the selected name(s)
sFilenames = Split(.FileName, vbNullChar)
End With
If UBound(sFilenames) = 0 Then
If txtAttach.Text = "" Then
txtAttach.Text = sFilenames(0)
Else
txtAttach.Text = txtAttach.Text & ";" & sFilenames(0)
End If
ElseIf UBound(sFilenames) > 0 Then
If Right$(sFilenames(0), 1) <> "\" Then sFilenames(0) = sFilenames(0) & "\"
For i = 1 To UBound(sFilenames)
If txtAttach.Text = "" Then
txtAttach.Text = sFilenames(0) & sFilenames(i)
Else
txtAttach.Text = txtAttach.Text & ";" & sFilenames(0) & sFilenames(i)
End If
Next
Else
Exit Sub
End If
Err_Cancel:
End Sub
You are only passing in one file. Try passing in an array of files and loop through the array. Or, since it looks like its semicolon delimiting the list of files selected, try to just split the list...
For Each s As String in sFilePath.Split(";"c)
lobj_cdomsg.AddAttachemt(s)
Next
I have no idea how to run a vb 6 app anymore, but if this helps, please mark it so.

key value relation on Skip List (DXL/DOORS)

I am trying to find the same login id users in database.
First I put every user to skiplist then I want to compare one by one. My question is how can i get the key value on Skiplist.
The piece of my code is here :
for lUser in userList do {
string uName = lUser.name
string uEmail = lUser.email
string uSys = lUser.systemLoginName
string uAdr = lUser.address
outBuf += uName sep uSys sep uEmail sep uAdr
outBuf += "\n"
// Here I have to add some code, I can put the values but not get again or compare
// I need some for loop and get every key value
put(skiplist,count,uSys)
print count
print "\n"
count++
}
Could someone give tips for this, I am new on this language. Thanks in advance.
EDIT: NOW IT IS WORKING
pragma runLim,0
string sep = ";"
string dbName = getDatabaseName
print "\n" "List of doors user in database " getDatabaseName ": \n\n"
int count = 0
User lUser
Group lGroup
Skip skiplist = create
for lUser in userList do {
string uName = lUser.name
string uEmail = lUser.email
string uSys = lUser.systemLoginName
string uAdr = lUser.address
if(null uSys)
{
print uName " doesn't have a System Name.\n"
} else {
bool flagDuplicate = false
string nameDuplicate = ""
string s = ""
for s in skiplist do {
if(s == uSys) {
flagDuplicate = true
nameDuplicate = (string key skiplist)
break
}
}
if(flagDuplicate) print "Users '" uName "' and '" nameDuplicate "' have the same System Name (" uSys ").\n"
else put(skiplist,uName,uSys)
}
}
pragma runLim,0 this line is for avoiding the execution time warning.
It sounds like what you are looking for is this:
for lUser in userList do {
string uName = lUser.name
string uEmail = lUser.email
string uSys = lUser.systemLoginName
string uAdr = lUser.address
outBuf += uName sep uSys sep uEmail sep uAdr
outBuf += "\n"
if(null uSys)
{
print uName " doesn't have a System Name.\n"
} else {
bool flagDuplicate = false
string nameDuplicate = ""
string s = ""
for s in skiplist do {
if(s == uSys) {
flagDuplicate = true
nameDuplicate = (string key skiplist)
break
}
}
if(flagDuplicate) print "Users '" uName "' and '" nameDuplicate "' have the same System Name (" uSys ")."
else put(skiplist,uName,uSys)
print "\n"
}
}
EDIT: I added a check for a blank uSys, you can do anything you want there, if you want to just add all the empty ones to a list then print it out at the end that would work too.
This should at least point you in the right direction.
NOTE: I don't have the ability to test this code currently so I apologize if there are any errors or typos. But I think it will get you close enough.
Good luck!