Running WinRM quickconfig for remote servers - powershell-remoting

I am writing a PowerShell script that reads in a list of hosts from a file. I have tried two separate methods, having issues with both.
First Method:
$WinRM = Invoke-Command -Computer $server -ScriptBlock { WinRM quickconfig }
This gives the following error message on some of the hosts:
WSManFault
+ CategoryInfo : NotSpecified: (WSManFault:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
+ PSComputerName : svclebetapool01.lehi.micron.com
Message = Access is denied.
Error number: -2147024891 0x80070005
Access is denied.
Second Method:
$WinRM = C:\PSTools\PsExec.exe \\$server -s winrm.cmd quickconfig -q
This sets $WinRM to the exit code (1 on successful execution). If I redirect the output with > or >>, then it displays the PsExec copyright. I am looking for the exact message that is created by the WinRM quickconfig command so that I know how to handle it in different situations.

if your intention is to enable PowerShell remoting, then you can
C:\PSTools\PsExec.exe \\$server PowerShell.exe -c "Enable-PSRemoting -Force"
or
wmic /node:$Server process call create "PowerShell.exe -c 'Enable-PSRemoting -Force'"

Related

I get "SSL Connection Error" when trying to connect to a MySql Server from Powershell

I am trying to work in a connection to a MySql Server database in a powershell script. This is my code:
Add-Type -Path 'C:\Program Files (x86)\MySQL\MySQL Connector Net 8.0.26\Assemblies\v4.5.2\MySql.Data.dll'
$Connection = [MySql.Data.MySqlClient.MySqlConnection]#{
ConnectionString="server=127.0.0.1;port=3306;uid=user;pwd=password;database=example_db"
}
$Connection.Open()
$sql = New-Object MySql.Data.MySqlClient.MySqlCommand
$sql.Connection = $Connection
$sql.CommandText = 'SHOW DATABASES'
$sql.ExecuteNonQuery()
# Close the MySQL connection.
$Connection.Close()
I downloaded the MySql Connector driver and all, but when I execute the code it gets this error output:
Exception calling "Open" with "0" argument(s): "SSL Connection error."
At C:\Users\Path\To\Code\db_con.ps1:9 char:1
+ $Connection.Open()
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : MySqlException
I checked the server, user, pwd and everything checks, I can connect using other clients. Also tried using other valid servers and users, but it just throws this same problem.
Does the server have SSL connections enabled? If not, try adding SslMode=none to the connection string.

Extra character placed in path of DSC config - Azure PS

I'm trying to work out why I'm getting the error below; the path to the configuration.ps1 file should be configuration\configuration.ps1, however its failing as its reading it as configuration.0\configuration.ps1.
the whole error message is below, has anyone else come across this?
"status": "Failed",
"error": {
"code": "ResourceDeploymentFailure",
"message": "The resource operation completed with terminal provisioning state 'Failed'.",
"details": [
{
"code": "VMExtensionProvisioningError",
"message": "VM has reported a failure when processing extension 'CreateADPDC'. Error message: \"The DSC Extension received an incorrect input: An error occurred while
executing script or module 'configuration.ps1': The term 'C:\\Packages\\Plugins\\Microsoft.Powershell.DSC\\2.77.0.0\\bin\\..\\DSCWork\\configuration.0\\configuration.ps1' is not
recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
again..\nPlease correct the input and retry executing the extension.\"."
}
]
}
}'
At line:4 char:14
+ ... New-AzureRmResourceGroupDeployment -Name "coredeployment1 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-AzureRmResourceGroupDeployment], Exception
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceGroupDeploymentCmdlet
New-AzureRmResourceGroupDeployment : 18:31:08 - VM has reported a failure when processing extension 'CreateADPDC'. Error message: "The DSC Extension received an incorrect input: An
error occurred while executing script or module 'configuration.ps1': The term
'C:\Packages\Plugins\Microsoft.Powershell.DSC\2.77.0.0\bin\..\DSCWork\configuration.0\configuration.ps1' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again..
Please correct the input and retry executing the extension.".
Thanks in advance :)

PowerShell: fatal errors don't get sent to STDERR, how to log them?

I have a PowerShell script on my desktop:
Write-Output "Some output"
Write-Error "Non-fatal error"
$ErrorActionPreference = "Stop" # Any further errors should be treated as fatal
Write-Output "Some more output"
Write-Error "Fatal error"
I call it this way from powershell.exe:
PS C:\Users\me\Desktop> .\test.ps1 2> err.txt 1> out.txt
Output:
C:\Users\vmadmin\Desktop\test.ps1 : Fatal error
At line:1 char:1
+ .\test.ps1 2> err.txt 1> out.txt
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,test.ps1
out.txt:
Some output
Some more output
err.txt:
C:\Users\vmadmin\Desktop\test.ps1 : Non-fatal error
At line:1 char:1
+ .\test.ps1 2> err.txt 1> out.txt
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,test.ps1
I would like the fatal error to get logged to err.txt. How can I accomplish that?
PowerShell has two different channels for error-handling: the first is STDERR, to which non-fatal errors get written. The second is an exception mechanism, similar to what you would see in programming languages like C# or Java.
Here's the trick: any error is in either one channel or the other, never both. This means that fatal errors do not go through STDERR!
Here's a workaround: wrap your PowerShell calls in a cmd call. Since the cmd language does not have exceptions, any PowerShell exceptions that go through it get piped into STDERR.
Example usage:
PS C:\Users\me\Desktop> cmd.exe /c "powershell.exe .\test.ps1" 2> err.txt 1> out.txt

HTTP-GET Request with Titanium.Network.createHTTPClient() to coutchdb?

Im trying to make a request to my database on Coutch db in Titanium Studio.
I have tried the code bellow, but I get error: Cant retriev data.
If I try with ex url http://www.appcelerator.com, I can get the data.
If I use coutch db url http://127.0.0.1:5984, I can not get any data + error.
Im wondering if I maybe should use another url?
var url = "http://www.appcelerator.com";
var client = Ti.Network.createHTTPClient({
onload : function(e) {
Ti.API.info("Received text: " + this.responseText);
alert('success' + this.responseText);
},
onerror : function(e) {
Ti.API.debug(e.error);
alert('error');
},
timeout : 5000
});
client.open("GET", url);
client.send();
Your CouchDB server is run on your local machine and you can access it through 127.0.0.1 or localhost.
When you are running your code in iOS Simulator you have to remember it's virtual environment with different IP. To make proper query from iOS Simulator to CouchDB you have to use your real IP which can be retrieved from ifconfig command
ifconfig | grep inet | grep -v inet6 | cut -d ' ' -f 2
if this 127.0.0.1 is your local address then you should use locallhost.
Example :
http://localhost

Exception while try to get jmeter directory

I would like to start jmeter load test via console but it's Data Driven Load Test, so I need to read some information from csv files. I found a solution to include into User Parameters row to get the path to the place where the script was launched:
${__BeanShell(newFile(org.apache.jmeter.gui.GuiPackage.getInstance().getTestPlanFile().toString()).getParent())}
but I got an error in logs:
2013/06/11 15:23:54 ERROR - jmeter.util.BeanShellInterpreter: Error
invoking bsh method: eval Sourced file: inline evaluation of:
``newFile(org.apache.jmeter.gui.GuiPackage.getInstance().getTestPlanFile().toStrin
. . . '' : Command not found: newFile( java.lang.String )
2013/06/11 15:23:54 WARN - jmeter.functions.BeanShell: Error running
BSH script org.apache.jorphan.util.JMeterException: Error invoking bsh
method: eval Sourced file: inline evaluation of:
``newFile(org.apache.jmeter.gui.GuiPackage.getInstance().getTestPlanFile().toStrin
. . . '' : Command not found: newFile( java.lang.String ) at
org.apache.jmeter.util.BeanShellInterpreter.bshInvoke(BeanShellInterpreter.java:192)
What's wrong with this method?
The issue is you have:
newFile
instead of:
new File