Can anyone explain why calling the CSVDE utility from an elevated Windows command prompt would differ than using the same string from an elevated Powershell console? The issue I have is that I can successfully export from Active Directory via the command prompt method, but Powershell returns an authentication error, "Simple bind returned 'Invalid Credentials'.
Here is the command used for both, edited for sensitive pieces:
c:\csvde.exe -s domain.company.org -f ExportFile.csv -l "givenName,sn,ipPhone,title,department,company,physicalDeliveryOfficeName,mail" -d "OU=ABC Group,OU=ABC Users,DC=DomainName,DC=org" -a UserDistinguishedName Password
Both sessions are running with Administrator privileges. I am a Powershell novice, and for the life of me, I can't figure this out.
Thanks!
I can see two potential issues. First thought is that it is taking your user name and password as separate arguments, or as Adi Inbar suggested: you've got some special characters that are causing issues. Either way I'd enclose things in single quotes so that arguments are passed as expected, and taken literally.
c:\csvde.exe -s 'domain.company.org' -f 'ExportFile.csv' -l 'givenName,sn,ipPhone,title,department,company,physicalDeliveryOfficeName,mail' -d 'OU=ABC Group,OU=ABC Users,DC=DomainName,DC=org' -a 'UserDistinguishedName' 'Password'
See if that doesn't resolve the issue. In my experience that is usually a safe way to run a executable from PowerShell. I suppose alternatively you can assign them to variables, and then pass those.
$Server = 'domain.company.org'
$OutFile = 'ExportFile.csv'
$Attributes = 'givenName,sn,ipPhone,title,department,company,physicalDeliveryOfficeName,mail'
$SearchRoot = 'OU=ABC Group,OU=ABC Users,DC=DomainName,DC=org'
$UserID = 'CN=TMTech,OU=Users,DC=Some,DC=Company,DC=org'
$Password = 'P#$$w0rd'
CSVDE.exe -s $Server -f $OutFile -l $Attributes -d $SearchRoot -a $UserID $Password
Related
I'm still very much learning Powershell and I'm a bit lost regarding a command to use.
I have this
docker login -u AWS -p PASSWORD -e none number.dkr.ecr.REGION.amazonaws.com
and I want to select PASSWORD.
Ideally, I would like this PASSWORD to get into a file, and use it after (but that I can do).
I am lost on what command to use. I know awk '{print $6}' would work but I need the powershell as I'm using a windows machine.
I know it's a really simple question, I have been reading answers, but I am just confused by the different parameters, and the different ways by different people and well, Powershell is wonderful but I'm still learning.
Thanks a lot!!
The default field separator(s) in awk is whitespace, so we can do the same in PowerShell and then grab the 6th resulting substring.
For this, we can use the -split regex operator - it supports the following syntaxes:
[strings] -split [pattern]
or
-split [strings]
When used as in the second example above, it defaults to splitting on whitespace just like awk:
-split "docker login -u AWS -p PASSWORD -e none number.dkr.ecr.REGION.amazonaws.com"
If we wrap the expression in #(), we can index into it:
$Password = #(
-split "docker login -u AWS -p PASSWORD -e none number.dkr.ecr.REGION.amazonaws.com"
)[5]
or we can use the Select-Object cmdlet to grab it:
$Password = -split "docker login -u AWS -p PASSWORD -e none number.dkr.ecr.REGION.amazonaws.com" |Select-Object -Index 5
If, however, we always want to grab the substring immediately after -p instead of whatever the 6th string is, we could use the -replace regex operator instead:
$string = "docker login -u AWS -p PASSWORD -e none number.dkr.ecr.REGION.amazonaws.com"
$string -replace '^.*-p\s+(\S+).*$','$1'
You can make this more complex :) I just used simple regexp, but you can make it better :)
$x = "docker login -u AWS -p PApSSWORD -e none number.dkr.ecr.REGION.amazonaws.com "
$x -match "(\-p[a-z0-9 ]*\-e)"
$matches[1] -replace '(\-p) ([a-z0-9 ]*) (\-e)' , ' $2'
Another solution using a Regular Expression,
here with lookarounds
$string = 'docker login -u AWS -p PASSWORD -e none number.dkr.ecr.REGION.amazonaws.com'
if ($string -match '(?<=-p\s+).*(?=\s+-e)'){
$Password = $Matches.Value
} else {
"No password found"
}
I am trying to put below command in perl system() function.But getting so many compilation errors (syntax).
./istool export -domain serviceshost:9080 -u dsadm -p password -ar test.isx -pre -ds '-base="ENGINEHOST/Dev_Project" Jobs/Batch/\*.*'
I was using it like in perl:
system("./istool export -domain serviceshost:9080 -u dsadm -p password -ar test.isx -pre -ds '-base="ENGINEHOST/Dev_Project" Jobs/Batch/\*.*'");
can some one guide me exactly how to use it in system function?I tried escaping . also with backslash(\) in front of it.
Replace system with print, and it's obvious you didn't build the string correctly.
If you want to include a " in a string quoted with ", you need to escape it.
If you want to include a \ in a double-quoted string, you need to escape it.
So I have been trying to write a script where I run an executable with arguments to return some information I need for our monitoring. Not long ago I have written a script that successfully managed to do that, using the following command:
$command = "-t vtl -p {1} -m {0} -s"
$check = Invoke-Expression -command ("$exemap\$exe $command" -f $server,$poort)
This worked perfectly. However I am in the process of writing a new script and the exact same thing does not seem to be working anymore. Here is a script I have to reproduce the problem:
$omgeving = "A"
$exemap = "\\cfc01.corp\rpa-{0}\Scripts\Check_actualiteit_RPA" -f $omgeving
#$exe = "echoargs.exe"
$exe = "stmmon.exe"
$exepath = "$exemap\"+"$exe"
$commando = "-t {0} -p {1} -m {2} -s"
$poort = "5062"
$berichttype = "VTL"
$server = "rpa-a-ap001"
$command = ($commando -f $berichttype,$poort,$server) -split " "
#$command = "-t VTL -p 5062 -m rpa-a-ap001 -s"
& $exepath $command
So I have negated some lines that are there for troubleshooting. I have tried using the Invoke-Expression command above and using the & operator. I have googled and tried a lot. I have tried using jobs and Invoke-Command. But all of them have the same result, an explanation from the exe telling me how to use it:
Usage: \\cfc01.corp\rpa-A\Scripts\Check_actualiteit_RPA\stmmon.exe [-v] [-h] -t <type> -p <port> -m <machine> -k <key> [-s]
This makes me believe that the executable is not really acknowleding any arguments. I tried using echoargs and the output from the script above is:
Arg 0 is <-t>
Arg 1 is <VTL>
Arg 2 is <-p>
Arg 3 is <5062>
Arg 4 is <-m>
Arg 5 is <rpa-a-ap001>
Arg 6 is <-s>
Or, if I dont use the -split " " in the $command variable, the echoargs is this:
Arg 0 is <-t VTL -p 5062 -m rpa-a-ap001 -s>
The script above may not be very dynamic, but the actual script im trying to make is going to be. The argumentlist should be configurable and dynamic, which is why im using the -f command on different occasions.
Can anyone see what I am doing wrong here and why the executable won't even acknowledge the existence of arguments?
Use the call operator (&) for running external commands. Use Join-Path for building paths. Use splatting for passing arguments to a program or function.
$omgeving = "A"
$exemap = "\\cfc01.corp\rpa-$omgeving\Scripts\Check_actualiteit_RPA" -f
$exe = "stmmon.exe"
$exepath = Join-Path $exemap $exe
$params = '-t', 'VTL',
'-p', 5062,
'-m', 'rpa-a-ap001',
'-s'
& $exepath #params
Also, judging from the help output, you seem to be missing a required parameter:
Usage: \\...\stmmon.exe [-v] [-h] -t <type> -p <port> -m <machine> -k <key> [-s]
If everything else fails, try this as a workaround:
$type = 'VTL'
$port = 5062
$server = 'rpa-a-ap001'
& cmd /c ('"{0}" -t {1} -p {2} -m {3} -s' -f $exepath, $type, $port, $server)
I am sorry to have wasted people's time here.
I have discovered the problem here. Apparently the 'type' arguments does not allow capital letters. I had not yet tried to change those, but it seems to have fixed the issue.
How to run a remote script in PowerShell with arguments.
For linux I'm using curl http://www.example.com/script.sh | bash -s <arguments>.
Is there a similar equivalent in PowerShell.
Use Case: User-Data script for Amazon EC2
Thanks
You'll often find examples out there like this:
iex (New-Object System.Net.WebClient).DownloadString('http://domain/script.ps1')
iex is an alias for Invoke-Expression (think of it like exec or eval in some other languages).
The rest of it is creating a [System.Net.WebClient] object, which has a method to download the contents of a URL and return it as a string.
I followed a few examples here, but I still can not get my sqlcmd work after runas.
I can make it work with two steps:
Step one: Use runas to login into a new login and open a command prompt:
runas.exe /savecred /user:DOMAIN_NAME\login_name cmd.exe
Step two: execute the sqlcmd in a script
sqlcmd -S server_name -E /Q"exit(SELECT ##version )"
But I want to make it one step to get the results. I tried to add " " after the runas command as listed below, but it did not work:
runas.exe /savecred /user:DOMAIN_NAME\login_name "sqlcmd -S server_name -E /Q"exit(SELECT ##version )""
Any ideas?
Take a look at this article describing RunAs. Toward the end of the article, he specifically addresses needing to use quotes inside of quotes:
Fortunately, it’s fairly easy to make RunAs happy. All you need to do is use the \ character to “escape” any double quote marks that must to be embedded within the process path.
So, it looks like your command should be:
runas.exe /savecred /user:DOMAIN_NAME\login_name "sqlcmd -S server_name -E /Q\"exit(SELECT ##version )\""
Notice the \ before both of the nested double quotes.