get sub OUs description within a given OU - list

Is there any simple way of getting a list of all the OUs located one level under a given OU?
i.e. I have an OU called "Clients" and one level under this OU there are multiple OUs , one for each client. i.e. CAS, ADI, PMA
I would like to get a list with the description of these sub OUs.
Following the previous example, the result would be: "Casio, Adidas, Puma"
I tried Get-ADOrganizationalUnit but I couldn't figure out a way of doing this.
Thanks

Would this help you out:
$OU = 'OU=Europe,OU=World,DC=domain,DC=net'
Get-ADOrganizationalUnit -SearchBase $OU -SearchScope Subtree -Filter * |
Select-Object DistinguishedName, Name
You can find information on how to use the CmdLet Get-ADOrganizationalUnit by typing:
help Get-ADOrganizationalUnit -Example

Related

Regexmatch in Google Sheet to find 2 sections of my website

I'm trying to find the number of users coming to 2 different parts of my website:
/blog/
resources.company
To do this I use REGEXMATCH with | separator:
=SUMPRODUCT(('raw data'!$B$2:$B),REGEXMATCH('RAW - New Users'!$A$2:$A,"/blog/|resources.company"))
However, when I check with this formula:
=SUMPRODUCT(('raw data'!$B$2:$B),REGEXMATCH('RAW - New Users'!$A$2:$A,"/blog/") + REGEXMATCH('RAW - New Users'!$A$2:$A,"resources.company"))
I find more users.
I'm pretty sure the . messes up with the 1st formula. I've tried /blog/|resources\.company but it didn't help. How can I change my first formula so the REGEXMATCH finds everything that contains "resources.company" as well as "/blog"?

PowerShell Sort by 2nd Index

I'm trying to sort servers by the 2nd index of the name.
The server names are taken from file paths where they are the BaseName of the file.
I know that Select-Object has the parameter -Index, but I don't think that will work.
I am assuming that the best approach is with a PowerShell RegEx like "(?:^a-z))". This returns an unsorted list and I'm still googling around for a pattern that will sort by the 2nd Index.
Example of the Intended Output
Group the servers by name CC or DD
Server
------
ABCCWS01
CDCCWS01
ABDDWS01
CDDDWS01
Current Output
Sorts alphabetically by -Property name
$servers = Get-Item -Path
C:\ABDDWS01.ServerData,
C:\ABCCWS01.ServerData,
C:\CDCCWS01.ServerData,
C:\CDDDWS01.ServerData | Group BaseName -AsHashtable
foreach($computer in $servers.GetEnumerator() | Sort-Object -Property name)
{ ...DoSomething... }
Server
------
ABCCWS01
ABDDWS01
CDCCWS01
CDDDWS01
Then I tried to implement a PowerShell RegEx. But I'm stuck on how to properly use this to sort by the 2nd index. This example has no affect and returns the list unsorted. I've tried subbing in different patterns at the end "(?:^a-z))". So far my attempts either return the list unsorted or just a segment of the list.
I've googled around and tried many different things. If someone else wants to help puzzle this out, it is much appreciated.
Sort-Object -Property #{Expression={[RegEx]::Match($_.basename, "(?:^a-z))")}}
Sort-Object works by "ranking" each input according to the resulting value of calculating one or more property expressions against each input item - in your existing example, based on the the value of the name property.
As you've already found, property expressions doesn't have to be the value of any existing property though - they can be made up of anything - just pass a script block in place of the property name:
... |Sort-Object -Property {$_.name[1]}
The reason it doesn't work in your example is that the expression [RegEx]::Match($_.basename, "(?:^a-z))") returns a [System.Text.RegularExpressions.Match] object - and those can't be meaningfully compared to one another.
If you change the expression to resolve to a string instead (the matched value for example), it'll work:
... |Sort-Object -Property #{Expression={[RegEx]::Match($_.basename, "(?:^a-z))").Value}}
# or
... |Sort-Object -Property {[RegEx]::Match($_.basename, "(?:^a-z))").Value}

How to get every combination of a combolist

I have a program where you can import a combolist, ex.
test:lol
hello:hi
sup:hey
The first one being the "username" and last one being the "password".
I want so that every single username will have a line with each password of the list. I would like all of this put into a separate string list.
Such as:
test:lol
test:hi
test:hey
hello:lol
hello:hi
hello:hey
sup:lol
sup:hi
sup:hey
I think this might be a really simple code, something to do with first separating the list into two lists, then for each username, add every password, but my brains can't really think of anything to come up with a solution for this.
thank you in advance :)
Yes, you're right.
Firs - get two lists users and passwords by separating each string by column.
Second traverse users and passwords and combine them. In pseudocode
foreach uName in users do
foreach pwd in passwords do
print user.concat(":").concat(pwd)
end
end
Explanation:
Get first `uName` from `users`
Get first `pwd` from `passwords`
output "`user`:`pwd`"
Get second `pwd` from `passwords`
output "`user`:`pwd`"
...
Get second `uName` from `users`
Get first `pwd` from `passwords`
output "`user`:`pwd`"
...
Feel free to ask, if something left unclear

cts:value-match on xs:dateTime() type in Marklogic

I have a variable $yearMonth := "2015-02"
I have to search this date on an element Date as xs:dateTime.
I want to use regex expression to find all files/documents having this date "2015-02-??"
I have path-range-index enabled on ModifiedInfo/Date
I am using following code but getting Invalid cast error
let $result := cts:value-match(cts:path-reference("ModifiedInfo/Date"), xs:dateTime("2015-02-??T??:??:??.????"))
I have also used following code and getting same error
let $result := cts:value-match(cts:path-reference("ModifiedInfo/Date"), xs:dateTime(xs:date("2015-02-??"),xs:time("??:??:??.????")))
Kindly help :)
It seems you are trying to use wild card search on Path Range index which has data type xs:dateTime().
But, currently MarkLogic don't support this functionality. There are multiple ways to handle this scenario:
You may create Field index.
You may change it to string index which supports wildcard search.
You may run this workaround to support your existing system:
for $x in cts:values(cts:path-reference("ModifiedInfo/Date"))
return if(starts-with(xs:string($x), '2015-02')) then $x else ()
This query will fetch out values from lexicon and then you may filter your desired date.
You can solve this by combining a couple cts:element-range-querys inside of an and-query:
let $target := "2015-02"
let $low := xs:date($target || "-01")
let $high := $low + xs:yearMonthDuration("P1M")
return
cts:search(
fn:doc(),
cts:and-query((
cts:element-range-query("country", ">=", $low),
cts:element-range-query("country", "<", $high)
))
)
From the cts:element-range-query documentation:
If you want to constrain on a range of values, you can combine multiple cts:element-range-query constructors together with cts:and-query or any of the other composable cts:query constructors, as in the last part of the example below.
You could also consider doing a cts:values with a cts:query param that searches for values between for instance 2015-02-01 and 2015-03-01. Mind though, if multiple dates occur within one document, you will need to post filter manually after all (like in option 3 of Navin), but it could potentially speed up post-filtering a lot..
HTH!

about .replace in Velocity

I have a Pipe | delimited file I'm sending out and in a string field the client is using Pipes as just a random character to separate points.
Example. This is what text they have in the field.
Encore AWD | Leather | Navigation | Sunroof | Back Up Camera | USB | Bluetooth
I need to replace the | with a - and this is the code I'm trying.
#set ($va.list_comment = $va.listing_comment.replace("|", "-"))
it is still outputting the | characters.
Anyone have any ideas what I could be doing wrong here?
You cannot assign a new value into an object. If you're using the latest version of Velocity, then such an assignment would work if there is a setList_comment method, or if $va is a Map. Otherwise, you would have to just create a new variable that would host the new value and use it:
#set ($fixedListing = $va.listing_comment.replace("|", "-"))
$fixedListing
Or if you don't need that value for anything else than just printing it once, skip the assignment completely and just print the outcome:
$va.listing_comment.replace("|", "-")
If that still doesn't work, make sure the value returned is indeed a java.lang.String and not something else:
$va.listing_comment.class