Read Exchange using VBScript - coldfusion

I wrote this code in ColdFusion to read data from Exchange and am wondering if anyone can help me to code this using Visual Basic Script:
<cfldap
server="insert_my_server_name_here"
username="zzz\zzzzzz"
password="xxxx"
port = "123"
action = "query"
name = "data"
attributes = "company"
filter = "(&(objectclass=group))"
returnAsBinary = "objectSID"
>
I got this far, but it returns a table not found error:
Dim UserID
UserID = "my_user_ID"
Set objConn = CreateObject("ADODB.Connection")
objConn.Provider = "ADsDSOObject"
objConn.Open "Active Directory Provider"
Dim Base, Filter, Attr, Level, Server
Server = "insert_my_server_name_here"
Base = "<LDAP://" & Server & "/DC=dot,DC=com>;"
Filter = "(&(objectClass=user)(objectCategory=person)(samAccountName=" & UserID & "));"
Attr = "distinguishedName;"
Level = "SubTree"
Set RecordSet = objConn.Execute(Base & Filter & Attr & Level)
RecordSet.MoveFirst
While Not RecordSet.EOF
Wscript.echo RecordSet.Fields(0).Value
RecordSet.MoveNext
Wend

The code you've posted is fine.
I think you must have an incorrect reference to your domain in the LDAP query string. You are using the variable 'Server' to provide the name of a domain controller which is fine (but usually unnecessary), but are you changing 'DC=dot,DC=com' to reflect the name of your domain? EG if your domain is My.Domain it should be 'DC=My,DC=Domain'

Related

Generating a data table to iterate through in a Django Template

I have this function that uses PrettyTables to gather information about the Virtual Machines owned by a user. Right now, it only shows information and it works well. I have a new idea where I want to add a button to a new column which allows the user to reboot the virutal machine. I already know how to restart the virtual machines but what I'm struggling to figure out is the best way to create a dataset which i can iterate through and then create a HTML table. I've done similar stuff with PHP/SQL in the past and it was straight forward. I don't think I can iterate through PrettyTables so I'm wondering what is my best option? Pretty tables does a very good job of making it simple to create the table (as you can see below). I'm hoping to use another method, but also keep it very simple. Basically, making it relational and easy to iterate through. Any other suggestions are welcome. Thanks!
Here is my current code:
x = PrettyTable()
x.field_names = ["VM Name", "OS", "IP", "Power State"]
for uuid in virtual_machines:
vm = search_index.FindByUuid(None, uuid, True, False)
if vm.summary.guest.ipAddress == None:
ip = "Unavailable"
else:
ip = vm.summary.guest.ipAddress
if vm.summary.runtime.powerState == "poweredOff":
power_state = "OFF"
else:
power_state = "ON"
if vm.summary.guest.guestFullName == None:
os = "Unavailable"
else:
os = vm.summary.guest.guestFullName
x.add_row([vm.summary.config.name, os, ip, power_state])
table = x.get_html_string(attributes = {"class":"table table-striped"})
return table
Here is a sample of what it looks like and also what I plan to do with the button. http://prntscr.com/nki3ci
Figured out how to query the prettytable. It was a minor addition without having to redo it all.
html = '<table class="table"><tr><th>VM Name</th><th>OS</th><th>IP</th><th>Power
State</th></tr>'
htmlend = '</tr></table>'
body = ''
for vmm in x:
vmm.border = False
vmm.header = False
vm_name = (vmm.get_string(fields=["VM Name"]))
operating_system = (vmm.get_string(fields=["OS"]))
ip_addr = ((vmm.get_string(fields=["IP"])))
body += '<tr><td>'+ vm_name + '</td><td>' + operating_system + '</td> <td>'+ ip_addr +'</td> <td>ON</td></tr>'
html += body
html += htmlend
print(html)

How can I use code to export a SharePoint list to Excel

I found a previous question and it looks to be what I'm looking for. However when I run the code, I get a debug error (Highlights the last line from "Set ObjMyList . . . . ("A1"))". Below is the code I'm using with the specific path & GUIDs. I tried adjusting the sharepoint address, but the one listed is the one that points to the library. I also tried just the home address (Stopping at "TEP") and all the way to including "All Items.aspx". I'm sure I am missing something "simple", but just thought I'd try to ask here.
Dim objMyList As ListObject
Dim objWksheet As Worksheet
Dim strSPServer As String
Const SERVER As String = "https://twdc.sharepoint.com/sites/WDPR-dclrecruiting/Test/TEP/Trip%20Event%20Planning%20Library"
Const LISTNAME As String = "{6B39FDF1-29AE-418C-9D99-92293FED5C81}"
Const VIEWNAME As String = "{CCFD1C7F-74CA-4921-A599-628C800C818A}"
strSPServer = "http://" & SERVER & "/_vti_bin"
Set objWksheet = Worksheets.Add
Set objMyList = objWksheet.ListObjects.Add(xlSrcExternal, _
Array(strSPServer, LISTNAME, VIEWNAME), False, xlYes, Range("A1"))
Below code works in my local
Sub ExportList()
Dim objWksheet As Worksheet
Dim strSPServer As String
Const SERVER As String = "sp/sites/team"
Const LISTNAME As String = "{3e47ff9c-9aab-4a40-9d6a-c47e9b793484}" 'From source code
Const VIEWNAME As String = "{67709eda-c975-4669-85e5-d95e263dadc6}" 'From source code
' The SharePoint server URL pointing to the SharePoint list to import into Excel.
strSPServer = "http://" & SERVER & "/_vti_bin"
Set objWksheet = Sheets("Sheet1")
' Add a list range to the newly created worksheet
' and populated it with the data from the SharePoint list.
Set objMyList = objWksheet.ListObjects.Add(xlSrcExternal, Array(strSPServer, LISTNAME, VIEWNAME), True, , Range("A1"))
Set objMyList = Nothing
Set objWksheet = Nothing
End Sub

Salesforce APEX Unit Test Error with REST Services / Error at SELECT of Case Object

I've succeeded to successfully construct a REST API using APEX language defined with an annotation: #RestResource.
I also wrote a matching Unit test procedure with #isTest annotation. The execution of the REST API triggered by a HTTP GET with two input parameters works well, while the Unit Test execution, returns a "null" value list resulting from the SOQL query shown below:
String mycase = inputs_case_number; // for ex. '00001026'
sObject[] sl2 = [SELECT Id, CaseNumber FROM Case WHERE CaseNumber = :mycase LIMIT 1];
The query returns:
VARIABLE_ASSIGNMENT [22]|sl2|[]|0x1ffefea6
I've also tried to execute it with a RunAs() method (see code below), using a dynamically created Salesforce test user, not anonymous, connected to a more powerful profile, but still receiving a "null" answer at the SOQL query. The new profile defines "View All" permission for Cases. Other SOQL queries to objects like: "User" and "UserRecordAccess" with very similar construction are working fine, both for REST APEX and Test APEX.
Is there a way to configure an access permission for Unit test (#isTest) to read the Case object and a few fields like: Id and CaseNumber. Is this error related to the "Tooling API" function and how can we fix this issue in the test procedure?
Code attachment: Unit Test Code
#isTest
private class MyRestResource1Test {
static testMethod void MyRestRequest() {
// generate temporary test user object and assign to running process
String uniqueUserName = 'standarduser' + DateTime.now().getTime() + '#testorg.com';
Profile p = [SELECT Id FROM Profile WHERE Name='StandardTestUser'];
User pu = new User(Alias='standt',Email='standarduser#testorg.com',LastName='testing',EmailEncodingKey='UTF-8',LanguageLocaleKey='en_US',LocaleSidKey='en_US',ProfileId=p.Id,TimeZoneSidKey='America/New_York',UserName=uniqueUserName);
System.RunAs(pu) {
RestRequest req = new RestRequest();
RestResponse res = new RestResponse();
req.requestURI = '/services/apexrest/sfcheckap/';
req.addParameter('useremail','testuserid#red.com');
req.addParameter('casenumber','00001026');
req.httpMethod = 'GET';
RestContext.request = req;
RestContext.response = res;
System.debug('Current User assigned is: ' + UserInfo.getUserName());
System.debug('Current Profile assigned is: ' + UserInfo.getProfileId());
Test.startTest();
Map<String, Boolean> resultMap = MyRestResource1.doGet();
Test.stopTest();
Boolean debugflag = resultMap.get('accessPermission');
String debugflagstr = String.valueOf(debugflag);
System.assert(debugflagstr.contains('true'));
}
}
}
Found a solution path by using: #isTest(SeeAllData=true)
See article: "Using the isTest(SeeAllData=true) Annotation"
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_seealldata_using.htm

Fetch Data From MS SQL DB Using Ajax Auto Complete extender

I have an .aspx page that calls the .asmx web method to extract data from the MS SQL DB. I have tested the result without the connectionstring and it works.
I think my problem is with my connection string within the web.config, but i am not sure how to set it up. When i try to run the search with the SQL command i either get 500 server error or just nothing. Can someone please provide some advise?
partial web.config
<connectionStrings>
<add name="myConn" connectionString="Data Source=D:\\root\\Database\\; Initial Catalog=myData.mdb;Integrated Security=sspi;" />
</connectionStrings>
Web Method
Dim customers As List(Of String) = New List(Of String)
Dim conn As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection
conn.ConnectionString = ConfigurationManager.ConnectionStrings("myConn").ConnectionString
Dim cmd As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand
cmd.CommandText = "SELECT col1, col2 from myTable where" &
" , like #SearchText + '%'"
cmd.Parameters.AddWithValue("#SearchText", prefixText)
cmd.Connection = conn
conn.Open()
Dim sdr As System.Data.SqlClient.SqlDataReader = cmd.ExecuteReader
While sdr.Read
Dim item As String = AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(sdr("col1").ToString, sdr("col2").ToString)
customers.Add(item)
End While
conn.Close()
Return customers
OK, since i was trying to connection to an Access database, I was suppose to use OleDB connection instead of SqlClient.
So I replaced all Sqlclient with OldDb and it promptly solved the problem. So it turns out, it is very important to know which database type you are connecting to before you try to make that connection.

Unable to access WMI on remote machine using vb.net

I've had a scout around and can't seem to find the answer anywhere, so need to ask.
I'm trying to query the WMI on a remote machine, but I need to do so as the admin account and I'm having problems doing so.
The code I am using is:
Public Sub OperatingSystem(ByVal computeritem As String)
'set Username and Password which system will access the network with.
Dim options As ConnectionOptions
options = New ConnectionOptions()
options.Authority = "ntdlmdomain:" & ipaddress
options.Username = "Username"
options.Password = "Password"
scope = New ManagementScope("\\" & ipaddress & "\root\cimv2", options)
scope.Connect()
Dim query As ObjectQuery
query = New ObjectQuery("SELECT * FROM Win32_OperatingSystem")
Dim searcher As ManagementObjectSearcher
searcher = New ManagementObjectSearcher(scope, query)
the query continues to go and pull all kinds of information through to a spradsheet.. well it would if it worked!
The line of code that is falling over is:
scope = New ManagementScope("\\" & ipaddress & "\root\cimv2", options)
scope.Connect()
It's giving me an error message that just says 'Invalid parameter'. When I go to view detail, there's nothing in inner exception and the only thing that I can see of any value is ErrorCode:ManagementStatus.InvalidParameter
I apologize if this is something really simple.. I am still fairly new to this but if someone could give me some guidance that would really be appreciated.
Many Thanks.
It looks like the reference to ipaddress is not initialized. Since computeritem is passed as a parameter to the sub, your code might work better with:
scope = New ManagementScope("\\" & computeritem & "\root\cimv2", options)