Comparing String values against a collection of Names in a Hash Table
Objective:
Is to make a script that will import a csv file containing two values: "Name" and "Price". This would ideally be stored in a hash table with the key name of "Name" and the value being "Price". The second part would be
importing a second csv file that has a list of names to compare too. If it finds a similar match to a key name in the hash table and then it will add that to a new array with the price. At the end it would add all the prices and give you a total value.
The Problem to Solve:
In the real world people have a tendency to not write names exactly the same way, for example I am looking at a list of books to buy in an eBay auction. In the auction they provide a text list of all the names of books for sale. In my price guide it has all
the names and dollar values of each book. The wording of the way each book is named could differ from the person who writes it and what is actually in my reference pricing list. An example might be "The Black Sheep" vs "Black Sheep" or
"Moby-Dick" vs "Moby Dick".
I've tried making a script and comparing these values using the -like operator and have only had about 70% accuracy. Is there a way to increase that by
comparing the characters instead of likeness of words? I'm not really sure how to solve this issue as it's very hard to do quality check on the input when your talking about hundreds of names in the list. Is there a better way to compare values in power-shell
then the "like" operator? Do I need to use a database instead of a hash table? In the real world I feel like a search engine would know the differences in these variations and still provide the desired results so why not for this type of application?
In other words, create a bit more intelligence to say well it's not a 100% match but 90% so that is close enough, add it to the array as a match and add the price etc..
I'd be curious as to any thoughts on this? Maybe a scripting language with better matching for text?
Have you considered setting up a manual correction process that "learns" as you make corrections, automatically building a look up table of possible spellings of each Name? If you get an exact match, use it. If not, go to the look up
table and see if there's been a previous entry with the same spelling and what it was corrected to.
[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
Similar Messages
-
Question about comparing an array of names to a hash table
I'm still learning Powershell but feel like I have the basics now. I have a new project I'm working on and want some input as the best way to do this:
The Problem:
Let's say you have a list of several hundred video game titles and the dollar value of each in a text or two column CSV file.
The example CSV file looks likes this:
Game, Price
Metroid, $15.00
The Legend of Zelda!, $12.00
Mike Tyson's Punch-Out!, $18.00
Super Mario Bros., $16.00
Kung Fu, $7.00
You have another list of just the video game titles, this most likely is just a text file with each title listed on its own line.
The example text file looks like this:
Kung Fu
Metroid
Mike Tysons Punch-Out
Legend of Zelda
What I think would happen in the Script:
Use import-csv and create a hash table that will contain a key = Title and the value = the price.
Use import-csv and create an array for the title names.
Foreach loop through each Game Title and match the value against the Hash Table, if there's a match found, put that into another array that will later add all prices of each item and give you a total sum.
The challenge:
So far when I try and do one line examples of comparing names against the hash table it seems to only work with exact name matches. In the above example I've purposely made the game titles slightly different because in the real world people just write things
differently.
With that said, I've tried using the following single line to match things up and it only seems to work if the values match exactly.
$hash_table.ContainsKey("Game Title")
Is there a regex I should use to change the input of the game titles before creating the hash table or doing the compare? Is there another matching operator that is better and matching with String values that have slightly different grammar. An example would
be the game "The Legend of Zelda". Sometimes people just put "Legend of Zelda", that's close but not exact. I think using a regex to remove extra spaces and symbols would work, but what about for matching of words or letters??
Any ideas would be very helpful and thanks!There's no pat answer for this.
You can create an array from the hash table keys:
$hashtable = @{"The Legend of Zelda" = 15.00}
$titles = $hashtable.getenumerator() | select -ExpandProperty Name
And then test that using a wildcard match:
$titles -like "*Game Title*"
and see if it returns just one match. If it does then use that match to do your lookup in the hash table. If it returns 0, or more than one match then you need to check the spelling or qualify the title search some more.
[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " " -
Producing a string of 3 random letters for a hash table
I'm pretty new to all this and i was wondering if anyone would be able to help me produce a random string of 3 letters to be inputted into a hash table. I already have the code for integers to be placed into the table but am having difficulty with letters. I've tried using the Random() function but am probably putting it into the wrong place.
I will place the code underneath so you can all have a look at it.
Any help would be greatly appreciated.
Thanks in advance
Code:
class HashTable
private DataItem[] hashArray; // array holds hash table
private int arraySize;
private DataItem nonItem; // for deleted items
public HashTable(int size) // constructor
arraySize = size;
hashArray = new DataItem[arraySize];
nonItem = new DataItem(-1); // deleted item key is -1
public void displayTable()
System.out.print("Table: ");
for(int j=0; j<arraySize; j++)
if(hashArray[j] != null)
System.out.print(hashArray[j].getKey() + " ");
else
System.out.print("** ");
System.out.println("");
public int hashFunc(int key)
return key % arraySize; // hash function
public void insert(DataItem item) // insert a DataItem
// (assumes table not full)
int key = item.getKey(); // extract key
int hashVal = hashFunc(key); // hash the key
// until empty cell or -1,
while(hashArray[hashVal] != null &&
hashArray[hashVal].getKey() != -1)
++hashVal; // go to next cell
hashVal %= arraySize; // wraparound if necessary
hashArray[hashVal] = item; // insert item
} // end insert()
public DataItem delete(int key) // delete a DataItem
int hashVal = hashFunc(key); // hash the key
while(hashArray[hashVal] != null) // until empty cell,
{ // found the key?
if(hashArray[hashVal].getKey() == key)
DataItem temp = hashArray[hashVal]; // save item
hashArray[hashVal] = nonItem; // delete item
return temp; // return item
++hashVal; // go to next cell
hashVal %= arraySize; // wraparound if necessary
return null; // can't find item
} // end delete()
public DataItem find(int key) // find item with key
int hashVal = hashFunc(key); // hash the key
while(hashArray[hashVal] != null) // until empty cell,
{ // found the key?
if(hashArray[hashVal].getKey() == key)
return hashArray[hashVal]; // yes, return item
++hashVal; // go to next cell
hashVal %= arraySize; // wraparound if necessary
return null; // can't find item
} // end class HashTable
class HashTableApp
public static void main(String[] args) throws IOException
DataItem aDataItem;
int aKey, size, n, keysPerCell;
// get sizes
System.out.print("Enter size of hash table: ");
size = getInt();
System.out.print("Enter initial number of items: ");
n = getInt();
keysPerCell = 10;
// make table
HashTable theHashTable = new HashTable(size);
for(int j=0; j<n; j++) // insert data
aKey = (int)(java.lang.Math.random() *
keysPerCell * size);
aDataItem = new DataItem(aKey);
theHashTable.insert(aDataItem);
while(true) // interact with user
System.out.print("Enter first letter of ");
System.out.print("show, insert, delete, or find: ");
char choice = getChar();
switch(choice)
case 's':
theHashTable.displayTable();
break;
case 'i':
System.out.print("Enter key value to insert: ");
aKey = getInt();
aDataItem = new DataItem(aKey);
theHashTable.insert(aDataItem);
break;
case 'd':
System.out.print("Enter key value to delete: ");
aKey = getInt();
theHashTable.delete(aKey);
break;
case 'f':
System.out.print("Enter key value to find: ");
aKey = getInt();
aDataItem = theHashTable.find(aKey);
if(aDataItem != null)
System.out.println("Found " + aKey);
else
System.out.println("Could not find " + aKey);
break;
default:
System.out.print("Invalid entry\n");
} // end switch
} // end while
} // end main()
public static String getString() throws IOException
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String s = br.readLine();
return s;
public static char getChar() throws IOException
String s = getString();
return s.charAt(0);
public static int getInt() throws IOException
String s = getString();
return Integer.parseInt(s);
} // end class HashTableApppublic class Foo {
private java.util.Random rand = new Random();
public static void main(String[] args) throws Exception {
new Foo().go();
void go() throws Exception {
String allowedChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
System.out.println(getRandomString(allowedChars, 3));
String getRandomString(String allowedChars, int length) {
StringBuffer buf = new StringBuffer();
int charCount = allowedChars.length();
for (int count = 0; count < length; count++) {
int index = rand.nextInt(charCount);
buf.append(allowedChars.charAt(index));
return buf.toString();
} -
Collection MAP HASh map hash table
Hi
i wan to be familiar with Collection MAP API hasp map & hash table
please guide me...
tell me resource link where i can get more information about it.
BuntyThanks Jos
it is more theortical You just skimmed through it for at most eleven minutes. How can you
tell it's 'more theoretical'? It is a tutorial you know ...
kind regards,
Jos -
How to compare the value of a specied attribute to a string
I am looking for an example of how to compare the value of an attribute to a string. (I think)
I have been trying to:
if (attrs.get("title")== "Vampire") -- you already know this did not work.
How can I check to see if the title="Vampire"?
The code below will get me the title of admin (which should be Vampire)
import javax.naming.Context;
import javax.naming.directory.InitialDirContext;
import javax.naming.directory.DirContext;
import javax.naming.directory.Attributes;
import javax.naming.NamingException;
import java.util.Hashtable;
class Giles {
public static void main(String[] args) {
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://192.168.1.55:389/o=sunnydale");
try {
DirContext ctx = new InitialDirContext(env);
Attributes attrs = ctx.getAttributes("cn=admin");
System.out.println("Title: " + attrs.get("title").get());
ctx.close();
} catch (NamingException e) {
System.err.println("Problem getting attribute: " + e);
Thank you!!
SteveI guess, you are looking for searching for attributes of an user object.
Here is the sample code to list all the attributes of an 'user' objectclass.
Tell me if it helps or not.
import java.util.Hashtable;
import javax.naming.ldap.*;
import javax.naming.directory.*;
import javax.naming.*;
public class GetAttributes
public static void main (String[] args)
Hashtable env = new Hashtable();
//Must use either the userPrincipalName or samAccountName,
//Cannot use the distinguished name
String adminName = "cn=abcd,cn=Users,dc=ssotest,dc=com";
String adminPassword = "DEF1234";
String ldapURL = "ldap://pni3w067:389";
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.SECURITY_AUTHENTICATION,"simple");
env.put(Context.SECURITY_PRINCIPAL,adminName);
env.put(Context.SECURITY_CREDENTIALS,adminPassword);
//connect to my domain controller
env.put(Context.PROVIDER_URL,ldapURL);
try {
// Create the initial directory context
DirContext ctx = new InitialLdapContext(env,null);
// Create the search controls
SearchControls searchCtls = new SearchControls();
//Specify the search scope
searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);
//specify the LDAP search filter
String searchFilter = "(&(objectClass=user))";
//Specify the Base for the search
//cn=policygroup,ou=policyusers,ou=ssoanay,;
//String searchBase = "ou=policyusers,ou=ssoanay,dc=ssotest,dc=com";
String searchBase = "cn=abcd,cn=users,dc=ssotest,dc=com";
//initialize counter to total the results
int totalResults = 0;
// Search for objects using the filter
NamingEnumeration answer = ctx.search(searchBase, searchFilter, searchCtls);
//Loop through the search results
while (answer.hasMoreElements()) {
SearchResult sr = (SearchResult)answer.next();
totalResults++;
System.out.println("\nName of Object : " + sr.getName());
// Print out some of the attributes, catch the exception if the attributes have no values
Attributes attrs = sr.getAttributes();
//System.out.println("6");
if (attrs != null) {
try {
/*NamingEnumeration enum = attrs.getIDs();
while(enum.hasMore()) {
System.out.println("IDs:"+enum.next().toString());
NamingEnumeration enum2 = attrs.getAll();
while(enum2.hasMore()) {
System.out.println("Attribute - "+enum2.next().toString());
catch (Exception e) {
System.out.println("Exception:" +e.getMessage());
else {
System.out.println("attribute is null");
System.out.println("Total results: " + totalResults);
ctx.close();
catch (NamingException e) {
System.err.println("Problem searching directory: " + e);
//return 0;
} -
I'm using TestStand 2.0/Labview 6i to do a string value test. Is there any way to use a string variable in the edit string value test instead of an actual string?? This forces you to hard code a string to test against.
Hi ART,
You can also use the LimitLoader step to load your string into to step similar to the Numeric Step type.
There should be an example of this in the Resource Library | TestStand
Regards
Ray Farmer
Regards
Ray Farmer -
Compare String in a table and insert the common values into a New table
Hi all,
Anyone has idea on how to compare a string value in a table.
I have a Students Table with Student_id and Student_Subject_list columns as below.
create table Students( Student_id number,
Student_Subject_list varchar2(2000)
INSERT INTO Students VALUES (1,'Math,Science,Arts,Music,Computers,Law,Business,Social,Language arts,History');
INSERT INTO Students VALUES (2,'Math,Law,Business,Social,Language arts,History,Biotechnology,communication');
INSERT INTO Students VALUES (3,'History,Spanish,French,Langage arts');
INSERT INTO Students VALUES (4,'History,Maths,Science,Chemistry,English,Reading');
INSERT INTO Students VALUES (5,'Math,Science,Arts,Music,Computer Programming,Language arts,History');
INSERT INTO Students VALUES (6,'Finance,Stocks');
output
Student_id Student_Subject_list
1 Math,Science,Arts,Music,Computers,Law,Business,Social,Language arts,History
2 Math,Law,Business,Social,Language arts,History,Biotechnology,communication
3 History,Spanish,French,Langage arts
4 History,Maths,Science,Chemistry,English,Reading
5 Math,Science,Arts,Music,Computer Programming,Language arts,History
6 Finance,Stocks
I need help or some suggestion in write a query which can compare each row string value of Student_Subject_list columns and insert the
common subjects into a new table(Matched_Subjects).The second table should have the below colums and data.
create table Matched_Subjects(Student_id number,
Matching_studesnt_id Number,
Matched_Student_Subject varchar2(2000)
INSERT INTO Matched_Subjects VALUES (1,2,'Math,Law,Business,Social,Language arts,History');
INSERT INTO Matched_Subjects VALUES (1,3,'History,Langage arts');
INSERT INTO Matched_Subjects VALUES (1,4,'History,Maths,Science');
INSERT INTO Matched_Subjects VALUES (1,5,'Math,Science,Arts,Music,Language arts,History');
INSERT INTO Matched_Subjects VALUES (2,3,'History,Langage arts');
INSERT INTO Matched_Subjects VALUES (2,4,'History,Maths');
INSERT INTO Matched_Subjects VALUES (2,5,'Math,Language arts,History');
INSERT INTO Matched_Subjects VALUES (3,4,'History');
INSERT INTO Matched_Subjects VALUES (3,5,'Language arts,History');
INSERT INTO Matched_Subjects VALUES (4,5,'Math,Science');
output:
Student_id Match_Student_id Matched_Student_Subject
1 2 Math,Law,Business,Social,Language arts,History
1 3 History,Langage arts
1 4 History,Maths,Science
1 5 Math,Science,Arts,Music,Language arts,History
2 3 History,Langage arts
2 4 History,Maths
2 5 Math,Language arts,History
3 4 History
3 5 Language arts,History
4 5 Math,Science
any help will be appreciated.
Thanks.
Edited by: user7988 on Sep 25, 2011 8:45 AMuser7988 wrote:
Is there an alternate approach to this without using xmlagg/xmlelement What Oracle version are you using? In 11.2 you can use LISTAGG:
insert
into Matched_Subjects
with t as (
select student_id,
column_value l,
regexp_substr(student_subject_list,'[^,]+',1,column_value) subject
from students,
table(
cast(
multiset(
select level
from dual
connect by level <= length(regexp_replace(student_subject_list || ',','[^,]'))
as sys.OdciNumberList
select t1.student_id,
t2.student_id,
listagg(t1.subject,',') within group(order by t1.l)
from t t1,
t t2
where t1.student_id < t2.student_id
and t1.subject = t2.subject
group by t1.student_id,
t2.student_id
STUDENT_ID MATCHING_STUDESNT_ID MATCHED_STUDENT_SUBJECT
1 2 Math,Law,Business,Social,Language arts,History
1 3 Language arts,History
1 4 Science,History
1 5 Math,Science,Arts,Music,Language arts,History
2 3 Language arts,History
2 4 History
2 5 Math,Language arts,History
3 4 History
3 5 History,Language arts
4 5 History,Science
10 rows selected.
SQL> Prior to 11.2 you can create your own string aggregation function STRAGG - there are plenty of example on this forum. Or use hierarchical query:
insert
into Matched_Subjects
with t1 as (
select student_id,
column_value l,
regexp_substr(student_subject_list,'[^,]+',1,column_value) subject
from students,
table(
cast(
multiset(
select level
from dual
connect by level <= length(regexp_replace(student_subject_list || ',','[^,]'))
as sys.OdciNumberList
t2 as (
select t1.student_id student_id1,
t2.student_id student_id2,
t1.subject,
row_number() over(partition by t1.student_id,t2.student_id order by t1.l) rn
from t1,
t1 t2
where t1.student_id < t2.student_id
and t1.subject = t2.subject
select student_id1,
student_id2,
ltrim(sys_connect_by_path(subject,','),',') MATCHED_STUDENT_SUBJECT
from t2
where connect_by_isleaf = 1
start with rn = 1
connect by student_id1 = prior student_id1
and student_id2 = prior student_id2
and rn = prior rn + 1
STUDENT_ID MATCHING_STUDESNT_ID MATCHED_STUDENT_SUBJECT
1 2 Math,Law,Business,Social,Language arts,History
1 3 Language arts,History
1 4 Science,History
1 5 Math,Science,Arts,Music,Language arts,History
2 3 Language arts,History
2 4 History
2 5 Math,Language arts,History
3 4 History
3 5 History,Language arts
4 5 History,Science
10 rows selected.SY. -
How to pass dynamically generated string value as array name in TestStand?
Hi All,
I have a string variable which holds an array name as its value. The string value is a dynamically generated one. Now my problem is how to retrieve the values within the array where as the array name is stored in a string variable.
for eg:
fileglobals.InfoName = "Array_Name" --> fileglobals.InfoName is a string variable, Array_Name is the array name generated dynamically and it is known only at run-time.
Array_Name[0] = "a";
Array_Name[1] = "b";
Array_Name[2] = "c";
In the above case, I have to retrieve the values of a, b and c
Any help is greatly appreciated
Thanks
Arun Prasath E GHi,
Looking at your sequencefile.
You seem to be trying to save into FlieGlobals.InfoName a string with the values of "FileGlobals.Info_0".."FileGlobals.Info_n" where n is the value of Parameter.TestSocket.Index.
Then you are setting the value into FileGlobals.TempName from "StationGlobals.FileGlobals.Info_0" assuming Parameter.TestSocket.Index is 0.
Is this correct?
I realise this is a cutdown sequence file but you must make sure These variable actually exist in either FileGlobals or StationGlobals. Also with FileGlobals each SequenceFile has its own FileGlobals unless you have set the properties of the SequencFile to use a common FileGlobals.
What was the precise error you was seeing as it will properly telling you what variable of property it can't find.
Regards
Ray Farmer
Regards
Ray Farmer -
SSRS Compare a string value in an column
I need to show a text box that shows a message if the string values of a column on SSRS report have mixed values.
I need to compare the first three letters of a string to see if its different. If different then unhid Textbox and show a message. How can I do this in SSRS or SQL (if sql how do I feed it to SSRS)?
For example
Substring(alloy,1,3) <> Substring(alloy,1,3)
ALLOY
KZA1
KZD1 << is different
KZA2If your scope is the whole dataset then you can add a total row to the tablix outside any groups or
simply add a textbox below the tablix and apply the same principle:
=IIf(Min(Fields!Alloy.Value,"DatasetName") <> Max(Fields!Alloy.Value,"DatasetName"), "Mixed Alloy", "")
=IIf(Min(Left(Fields!Alloy.Value,3),"DatasetName") <> Max(Left(Fields!Alloy.Value,3),"DatasetName"), "Mixed Alloy", "")
This should do what you are asking. The only way that the minimum value for alloy will equal the maximum value for allow is if all values for alloy in the dataset are the same. When that happens, empty string is displayed in your text box rendering it invisible
if you set borders appropriately. Otherwise you will see "Mixed Alloy" in the text box.
"You will find a fortune, though it will not be the one you seek." -
Blind Seer, O Brother Where Art Thou
Please Mark posts as answers or helpful so that others may find the fortune they seek. -
How to Export local security setting all filed name & value against filed.
HI all,
I am trying to export local security setting from local policy using bellow scrip. but it is showing only these are configured. I need expert help which allowed me to export all filed with value where it is configure or not. Please give me.
$output=@()
$temp = "c:\"
$file = "$temp\privs.txt"
[string] $readableNames
$process = [diagnostics.process]::Start("secedit.exe", "/export /cfg $file /areas USER_RIGHTS")
$process.WaitForExit()
$in = get-content $file
foreach ($line in $in) {
if ($line.StartsWith("Se")) {
$privilege = $line.substring(0,$line.IndexOf("=") - 1)
switch ($privilege){
"SeCreateTokenPrivilege " {$privilege = "Create a token object"}
"SeAssignPrimaryTokenPrivilege" {$privilege = "Replace a process-level token"}
"SeLockMemoryPrivilege" {$privilege = "Lock pages in memory"}
"SeIncreaseQuotaPrivilege" {$privilege = "Adjust memory quotas for a process"}
"SeUnsolicitedInputPrivilege" {$privilege = "Load and unload device drivers"}
"SeMachineAccountPrivilege" {$privilege = "Add workstations to domain"}
"SeTcbPrivilege" {$privilege = "Act as part of the operating system"}
"SeSecurityPrivilege" {$privilege = "Manage auditing and the security log"}
"SeTakeOwnershipPrivilege" {$privilege = "Take ownership of files or other objects"}
"SeLoadDriverPrivilege" {$privilege = "Load and unload device drivers"}
"SeSystemProfilePrivilege" {$privilege = "Profile system performance"}
"SeSystemtimePrivilege" {$privilege = "Change the system time"}
"SeProfileSingleProcessPrivilege" {$privilege = "Profile single process"}
"SeCreatePagefilePrivilege" {$privilege = "Create a pagefile"}
"SeCreatePermanentPrivilege" {$privilege = "Create permanent shared objects"}
"SeBackupPrivilege" {$privilege = "Back up files and directories"}
"SeRestorePrivilege" {$privilege = "Restore files and directories"}
"SeShutdownPrivilege" {$privilege = "Shut down the system"}
"SeDebugPrivilege" {$privilege = "Debug programs"}
"SeAuditPrivilege" {$privilege = "Generate security audit"}
"SeSystemEnvironmentPrivilege" {$privilege = "Modify firmware environment values"}
"SeChangeNotifyPrivilege" {$privilege = "Bypass traverse checking"}
"SeRemoteShutdownPrivilege" {$privilege = "Force shutdown from a remote system"}
"SeUndockPrivilege" {$privilege = "Remove computer from docking station"}
"SeSyncAgentPrivilege" {$privilege = "Synchronize directory service data"}
"SeEnableDelegationPrivilege" {$privilege = "Enable computer and user accounts to be trusted for delegation"}
"SeManageVolumePrivilege" {$privilege = "Manage the files on a volume"}
"SeImpersonatePrivilege" {$privilege = "Impersonate a client after authentication"}
"SeCreateGlobalPrivilege" {$privilege = "Create global objects"}
"SeTrustedCredManAccessPrivilege" {$privilege = "Access Credential Manager as a trusted caller"}
"SeRelabelPrivilege" {$privilege = "Modify an object label"}
"SeIncreaseWorkingSetPrivilege" {$privilege = "Increase a process working set"}
"SeTimeZonePrivilege" {$privilege = "Change the time zone"}
"SeCreateSymbolicLinkPrivilege" {$privilege = "Create symbolic links"}
"SeDenyInteractiveLogonRight" {$privilege = "Deny local logon"}
"SeRemoteInteractiveLogonRight" {$privilege = "Allow logon through Terminal Services"}
"SeServiceLogonRight" {$privilege = "Logon as a service"}
"SeIncreaseBasePriorityPrivilege" {$privilege = "Increase scheduling priority"}
"SeBatchLogonRight" {$privilege = "Log on as a batch job"}
"SeInteractiveLogonRight" {$privilege = "Log on locally"}
"SeDenyNetworkLogonRight" {$privilege = "Deny Access to this computer from the network"}
"SeNetworkLogonRight" {$privilege = "Access this Computer from the Network"}
$sids = $line.substring($line.IndexOf("=") + 1,$line.Length - ($line.IndexOf("=") + 1))
$sids = $sids.Trim() -split ","
$readableNames = ""
foreach ($str in $sids){
$str = $str.substring(1)
$sid = new-object System.Security.Principal.SecurityIdentifier($str)
$readableName = $sid.Translate([System.Security.Principal.NTAccount])
$readableNames = $readableNames + $readableName.Value + ", "
$output += New-Object PSObject -Property @{
privilege = $privilege
readableNames = $readableNames.substring(0,($readableNames.Length - 1))
#else = $line."property"
$outputAs an alternate approach wee can preset the hash and just update it. This version also deal with trapping the errors.
function Get-UserRights{
Param(
[string]$tempfile="$env:TEMP\secedit.ini"
$p=Start-Process 'secedit.exe' -ArgumentList "/export /cfg $tempfile /areas USER_RIGHTS" -NoNewWindow -Wait -PassThru
if($p.ExitCode -ne 0){
Write-Error "SECEDIT exited with error:$($p.ExitCode)"
return
$selines=get-content $tempfile|?{$_ -match '^Se'}
Remove-Item $tempfile -EA 0
$dct=$selines | ConvertFrom-StringData
$hash=@{
SeCreateTokenPrivilege =$null
SeAssignPrimaryTokenPrivilege=$null
SeLockMemoryPrivilege=$null
SeIncreaseQuotaPrivilege=$null
SeUnsolicitedInputPrivilege=$null
SeMachineAccountPrivilege=$null
SeTcbPrivilege=$null
SeSecurityPrivilege=$null
SeTakeOwnershipPrivilege=$null
SeLoadDriverPrivilege=$null
SeSystemProfilePrivilege=$null
SeSystemtimePrivilege=$null
SeProfileSingleProcessPrivilege=$null
SeCreatePagefilePrivilege=$null
SeCreatePermanentPrivilege=$null
SeBackupPrivilege=$null
SeRestorePrivilege=$null
SeShutdownPrivilege=$null
SeDebugPrivilege=$null
SeAuditPrivilege=$null
SeSystemEnvironmentPrivilege=$null
SeChangeNotifyPrivilege=$null
SeRemoteShutdownPrivilege=$null
SeUndockPrivilege=$null
SeSyncAgentPrivilege=$null
SeEnableDelegationPrivilege=$null
SeManageVolumePrivilege=$null
SeImpersonatePrivilege=$null
SeCreateGlobalPrivilege=$null
SeTrustedCredManAccessPrivilege=$null
SeRelabelPrivilege=$null
SeIncreaseWorkingSetPrivilege=$null
SeTimeZonePrivilege=$null
SeCreateSymbolicLinkPrivilege=$null
SeDenyInteractiveLogonRight=$null
SeRemoteInteractiveLogonRight=$null
SeServiceLogonRight=$null
SeIncreaseBasePriorityPrivilege=$null
SeBatchLogonRight=$null
SeInteractiveLogonRight=$null
SeDenyNetworkLogonRight=$null
SeNetworkLogonRight=$null
for($i=0;$i -lt $dct.Count;$i++){
$hash[$dct.keys[$i]]=$dct.Values[$i].Split(',')
$privileges=New-Object PsObject -Property $hash
$privileges
Get-UserRights
A full version would be pipelined and remoted or, perhaps use a workflow to access remote machines in parallel.
¯\_(ツ)_/¯ -
Compares single value content property to single value property
Hi,
I am using WLPS 3.2 with weblogic apps 5.1.
This is when regarding content selection rules. When u go into the rules
management and try to create a content selection rule : Then display content
based on:
we see 3 templates to choose from. Now if u look at template 2 it says
:Value with Property Example
This template compares a single-value content property to another
single-value property. content.investor_type equals user.investor_type
It says this template compares "single value" content property to another
"single-value property". What i did was set up a rule that comared a single
value content property to a "multiple" value user property (i.e. the user
property was allowed to have multiple values-check boxes). The rule was set
up fine. When i ran the rule with the <pz:contentselector> tag it dint
return the desired content object. Now if i set up the same rule to match a
single valued user property then it worked!!! Could you please let me know
why this happens and is this a limitation of the tool. What is an
alternative solution for me to compare a content property to a multi valued
user property.
Thanks,
--KapilHi Kapil,
You're correct on all counts. This workaround does move the content
selection into the JSP, rather than using a rule -- which is not ideal.
Also, your suggestion to build one query string to cut down on the number of
database calls is a good improvement.
- Ginny
"kapil khanna" <[email protected]> wrote in message
news:[email protected]...
Hi Ginny,
I really appreciate ur response. This work around was not knew to me. Iwas
expecting a better work around from some reasons:
i) The definition of this rule is hard coded and not administered thu the
tools interface.
ii) There are multiple database calls for each property value retrieved
every time the <cm:select> tag is executed which is very expensive.
iii) The query that i build for the <cm:select> or <pz:contentQuery> tag
doesnt support the in statement.
My work around was something like this:
Build the query string first which would look something like this
CONTENT.interest like '*Science*' || CONTENT.interest like '*Astronomy*'
Then run the <cm:select> or <pz:contentQuery> tag so that i have only one
database call.
Considering the user has 2 interests chosen Science and astronomy. I usethe
like so that CONTENT can be tagged to accomodate multiple values which is
very possible in a real life situation. For eg: <meta name="interest"
content="Science,Astronomy" >
Is this a better work around or am i totally out of line.
Thanks for your help and time
--Kapil
"Ginny Peterson" <[email protected]> wrote in message
news:[email protected]...
Hi Kapil,
Yes -- this is a limitation with the phrase templates. The "Value with
Property" phrase template compares a single-value content property to
another single-value property. What's key here (and often overlooked)
is
that fact that the property you're using must be a single-valueproperty.
>>
There is a workaround using the <cm:select> tag rather than the <pz>tags.
Basically, it involves getting a list of the values for yourmultiple-value
property, and iterating over that list, selecting the content for each
of
the items in the list.
Here's some sample code. Assume you have a text, multiple, unrestricted
property called "MyInterests" in property set "TestPropertySet"; a user
might have values like this: "Science, Astronomy, Cooking".
<%@ page extends="com.beasys.commerce.axiom.p13n.jsp.P13NJspBase"%>
<%@ page import="com.beasys.commerce.content.ContentHelper"%>
<%@ taglib uri="es.tld" prefix="es" %>
<%@ taglib uri="cm.tld" prefix="cm" %>
<%@ taglib uri="um.tld" prefix="um" %>
<!-- Get the user and group names -->
<%
String userName = (String)getSessionValue(SERVICEMANAGER_USER,request);
String groupName = (String)getSessionValue(SERVICEMANAGER_SUCCESSOR,
request);
%>
<!-- Get the profile for the user -->
<%
// Check to see if logged in, then getProfile for the user with groupas
successor
if(getLoggedIn(request))
%>
<um:getProfile scope="session" profileKey="<%= userName %>"
successorKey="<%= groupName %>" />
<%
else // use the default profile for the group
%>
<um:getProfile scope="session" profileKey="<%= groupName %>"
groupOnly="true" />
<%
%>
<!-- Get the property value for the user -->
<um:getProperty id="areas" propertySet="TestPropertySet"
propertyName="MyInterests" />
<br><br>Interests for <%= userName %>:
<%
// Multi-valued properties are retrieved as an ArrayList, so cast to a
Collection so we can iterate through
Collection c = (Collection)areas;
String queryString;
Iterator i = c.iterator();
while(i.hasNext())
String nextVal = (String)i.next();
queryString = "CONTENT.interests == '" + nextVal + "'";
%>
<cm:select contentHome="<%= ContentHelper.DEF_CONTENT_MANAGER_HOME %>"
query="<%= queryString %>" id="docList"/>
<es:forEachInArray id="aDoc" array="<%= docList %>"
type="com.beasys.commerce.axiom.content.Content">
<li>Matched document message:
<cm:printProperty id="aDoc" name="message" encode="html"/>
</es:forEachInArray>
<%
%>
FYI, this limitation is not present in WLCS 3.5; it's much more flexiblein
terms of using mutli-valued properties (and multi-valued meta tags) in
rules.
I hope this helps!
- Ginny
"kapil khanna" <[email protected]> wrote in message
news:[email protected]...
Hi,
I am using WLPS 3.2 with weblogic apps 5.1.
This is when regarding content selection rules. When u go into the
rules
management and try to create a content selection rule : Then displaycontent
based on:
we see 3 templates to choose from. Now if u look at template 2 it says
:Value with Property Example
This template compares a single-value content property to
another
single-value property. content.investor_type equalsuser.investor_type
It says this template compares "single value" content property toanother
"single-value property". What i did was set up a rule that comared asingle
value content property to a "multiple" value user property (i.e. the
user
property was allowed to have multiple values-check boxes). The rule
was
set
up fine. When i ran the rule with the <pz:contentselector> tag it dint
return the desired content object. Now if i set up the same rule to
match
a
single valued user property then it worked!!! Could you please let me
know
why this happens and is this a limitation of the tool. What is an
alternative solution for me to compare a content property to a multivalued
user property.
Thanks,
--Kapil -
How can i compare the values of the objects in a class?
hi ,
i am testing how to test the values of the two objects
this is the code i have return below.....
class Sample{
String name;
int age;
Sample(String name,int age){
this.name=name;
this.age=age;
public class sample2{
public static void main (String []arg){
Sample one = new Sample("cat",20);
Sample two = new Sample("cat",20);
how can i test that object one and two are equal.
can anyone clarify me about this?hansbig wrote:
Um, this part doesn't work, it will never return true.
public boolean equals(Object obj) {
if (obj == this) {
return true;
It will :) try for example objectOne.equals(objectOne); and add a System.out.println() at that part. It will return there.
>
but this part, woah dude, that's some pretty slick code you got here:
I couldn't figure out how to do the compare inside the class, but I think I see how this works.
Not sure how I would do it for an object with more than one value to check though.
if (obj instanceof EqualsExample) { //Not the best implementation considering possible subclasses but the easiest.
EqualsExample temp = (EqualsExample) obj;
return (this.name.equals(temp.name)); //Always use the equals function when comparing strings!
} else {
return false;
You could add them in one massive return (this.something == temp.something && etc). Or you could split it in a series of if statements. It's really dependant on what kind of variables there are in your class.
Maybe you have an ArrayList you need to compare but also an id. then it would make more sense to check the id first and then possibly loop through the arraylist.
Hope it's a bit more clear :)
Edited by: hms on Jan 16, 2008 11:25 AM -
Compare two values input by user in JavaScript
Hi, there,
I have two text input boxes in my form, and user can input some value in the boxes. I want to check if the values in these two boxes are numerical and compare them in my JavaScript function. How can I do this?
Thanks in advance.
FredHi,
You can make use of this code. You can user parseInt, which parses a string argument and returns an integer of the specified base.
<html>
<head>
<script>
function testCompare()
var x = parseInt(document.myFrm.a.value);
var y = parseInt(document.myFrm.b.value);
if( x > y)
alert ("X is greater");
else
alert("Y is greater");
</script>
</head>
<body>
<form name = myFrm>
<input type = text name = a value = 100>
<input type = text name = b value = 200 >
<input type = button value = click onclick = testCompare()>
</form>
</body>
</html>
Hope this helps.
Thanks,
Senthil_Slash -
How to compare string in a case-insensitive manner using JavaScript?
Hello everyone,
Now I have a javascript to compare checkbox's value with user's input, but now seems it only can compare case-sensitively, does some one know if there is a function in javascript that it can compare string case-insensitively ?
Here is my script :
function findOffice(field)
var name;
name=prompt("What is the office name?");
var l = field.length;
for(var i = 0; i < l; i++)
if(field.value==name)
field[i].checked=true;
field[i].focus();
field[i].select();
break;
<input type="button" name="Find" value="Find And Select" onClick="findOffice(form1) >
Thanks in advance !
RachelThank you so much, I already solved the problem with your advice.
You really have a beautiful mind, :-).
I appreciate your help !
Rachel -
Newbie Question: Rules: Functions: How to compare String based type?
I have some XML facts in my rules dictionary defined by the following schema (fragments shown)
<xs:simpleType name="VarType">
<xs:restriction base="xs:string">
<xs:enumeration value="Foo"/>
<xs:enumeration value="Bar"/>
<xs:enumeration value="Baz"/>
<xs:enumeration value="Qux"/>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="ProgType">
<xs:sequence>
<xs:element name="ID" type="xs:string"/>
<xs:element name="var" type="VarType" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
Which means that a Prog of ProgType has an ID and a "list" of "var" strings restricted to bounds specified by VarType.
The issue comes when I try to create a Rules Function operating on these types.
Function-> boolean containsVar(ProgType prog,VarType var) (built using the Functions tab of the Rules editor)
for (String v : prog.var ){
if (v == var){
return true
return false
The problem we run into here is typing. If v is declared a String, as here, then v == var is invalid because types don't match. But I can't declare v a VarType due to
RUL-05583: a primitive type or fact type is expected, but neither can be found.
This problem may stem from the fact the Java's String is declared final and can't be subclassed, so the JAXB translation to Java may have to wrap it, futzing ==/equals() in the process.
SO... How do I create this method and compare these values?
TIA
Edited by: wylderbeast on Mar 10, 2011 9:15 AM - typos
Edited by: wylderbeast on Mar 10, 2011 9:18 AMAnd here's the answer.
var.value() seems to return the String value of the type
so the comparison becomes
(v == var.value())
Live and learn....
Maybe you are looking for
-
I have a ipod nano(1st Gen.). I bought a itunes card, and have $15.34 as a balance. It won't let me purchase songs and deduct the money from my account balance. I get a message saying "we can not download [title of song] to this device") why? I've do
-
In the simple example below I define three classes: MyComputerRoleClass (with base Microsoft.Windows.ComputerRole) MyLocalApplicationClass (with base Microsoft.Windows.LocalApplication) MyApplicationComponentClass (with base Microsoft.Windows.Applica
-
%DOT11-7-AUTH_FAILED: %DOT11-6-DISASSOC:
Hello again, Thought this issue was fixed yesterday after finding out my printer was the MAC address flashing up on the log, however it seems that every device is playing up. Thanks James These are my wirless devices, APPLE IPHONE 6809.2780.219a
-
How to Implement Auto tabbing feature in a table region???
Hi All, I am trying to implement auto tabbing feature in one of my OAF page using java script which is actually working for individual items but while implementing the same for a table bean its not working. is there any way to implement this feature
-
Timeout during a remote portlet request
I'm facing a problem on portal consuming a remote portlet on wlp 8.1 SP4/5. We ask me to prevent a communication leak during a wsrp communication between me (the consumer) and a producer. I have seen this parameter that can be add to my wsrp-producer