Code working in Powershell ISE 2.0 but not ISE 4.0 - powershell-2.0

The following code open a random number generator, selects the button to run the generator, and returns a random number.
#Start-Process
$ie = New-Object -com InternetExplorer.Application
$ie.Navigate("https://www.random.org/widgets/integers/iframe.php?title=True+Random+Number+Generator&buttontxt=Generate&width=160&height=200&border=on&bgcolor=%23FFFFFF&txtcolor=%23777777&altbgcolor=%23CCCCFF&alttxtcolor=%23000000&defaultmin=1&defaultmax=100&fixed=off")
$ie.visible = $true
echo "Random.org opening"
while( $ie.busy){Start-Sleep 1}
sleep 10
echo "Random.org open"
$FindBtn = $ie.Document.getElementByID("true-random-integer-generator-button").click()
sleep 5
$result = $ie.Document.getElementByID("true-random-integer-generator-result").innerHTML
echo $result
This works fine for me in powershell 2.0, however, when I run in 4.0, iget the following errors:
You cannot call a method on a null-valued expression.
At line:13 char:1
+ $FindBtn = $ie.Document.getElementByID("true-random-integer-generator-button").c
...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:15 char:1
+ $result = $ie.Document.getElementByID("true-random-integer-generator-result").in
...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
What is the reason behind this? Is there a big formatting difference between powershell 4.0 and 2.0? 4.0 is on a different VM to 2.0, could that be having an affect?

Related

Error in Upload watchdog: [System.Object[]] no method with the name "op_Addition"

I need help with a script that monitors the upload.
The script is intended to prevent crashes of OBS, where OBS simply stops sending data. I have already run this script on several streaming PCs - without problems. But on a new streaming PC it just won't run.
Here is the script for now:
$threshold = 6000
$timer = new-timespan -Seconds 10
$wmi = 0
$count = 0
$clock = [diagnostics.stopwatch]::StartNew()
while ($clock.elapsed -lt $timer){
$wmi += (Get-WMIObject -Class Win32_PerfFormattedData_Tcpip_NetworkInterface | Select-Object BytesSentPerSec).BytesSentPerSec
$count++
}
$kbytes = ($wmi/$count) / 1kb * 8 #to kbit/s
if($kbytes -le $threshold)
{
Write-Output $kbytes
Write-Host "Neustart"
taskkill /f /im obs64.exe
timeout /t 5
Start-Process -FilePath "obs64.exe" -WorkingDirectory "C:\Program Files\obs-studio\bin\64bit\" --startstreaming
}
else
{
Write-Output $kbytes
Write-Host "Alles OK"
}
As an error I get this:
Code:
Error when calling the method. [System.Object[]] no method with the name "op_Addition".
In C:\Users\stream1\Desktop\watchdog.ps1:8 Zeichen:5
+ $wmi += (Get-WMIObject -Class Win32_PerfFormattedData_Tcpip_Netwo ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (op_Addition:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
The program was written for me by someone. Unfortunately, I myself have no experience in programming in Powershell. I would be very grateful for any help.
I hope someone can help me.
Thanks a lot
Greeting
Thomas
"$wmi = 0" --> "$wmi = #()"
Error:
Error calling the method because [System.Object[]] does not contain a method named "op_Division".
In C:\Users\stream1\Desktop\watchdog.ps1:12 character:1
+ $kbytes = ($wmi/$count) / 1kb * 8 #to kbit/s
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (op_Division:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound

appium-java Unknown HttpClient factory apache when initializing driver

I'm trying to migrate from appium-java client 7.0 to 8.3 - After updating to 8.3 version I get an error when initializing appium driver (for iOS)
java.lang.IllegalArgumentException: Unknown HttpClient factory apache
at org.openqa.selenium.remote.http.HttpClient$Factory.create(HttpClient.java:57)
at org.openqa.selenium.remote.http.HttpClient$Factory.createDefault(HttpClient.java:73)
at io.appium.java_client.remote.AppiumCommandExecutor.<init>(AppiumCommandExecutor.java:108)
at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:92)
at io.appium.java_client.ios.IOSDriver.<init>(IOSDriver.java:106)
Command to start appium server is build smth like this
command = nodePath + " " + appiumMainJS + " ";
command = command + " -a " + hostName + " -p " + availablePort + " ";
command = command + " -cp " + (availablePort + 1000) + " -bp " + (availablePort + 2000);
command = command + " --chromedriver-port " + (availablePort + 3000);
command = command + " " + appiumArgs;
Capabilities
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "iOS");
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, OS_VERIOSN);
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "XCUITest");
capabilities.setCapability("appium:keychainPath", KEYCHAIN_PATH);
capabilities.setCapability("appium:keychainPassword", KEYCHAIN_PASSWORD);
capabilities.setCapability("appium:xcodeOrgId", XCODE_ORG_ID);
capabilities.setCapability("appium:xcodeSigningId", XCODE_SIGNING_ID);
capabilities.setCapability("appium:deviceName", DEVICE_NAME);
capabilities.setCapability("appium:showXcodeLog", true);
capabilities.setCapability("appium:noReset", false);
capabilities.setCapability("appium:simpleIsVisibleCheck", false);
capabilities.setCapability(MobileCapabilityType.UDID, DEVICE_ID);
capabilities.setCapability("appium:newCommandTimeout", "2000000");
capabilities.setCapability("appium:launchTimeout", "120000");
capabilities.setCapability("appium:shouldUseSingletonTestManager", false);
capabilities.setCapability("appium:wdaConnectionTimeout", 15*60*1000);
capabilities.setCapability("appium:sendKeyStrategy", "setValue");
capabilities.setCapability("appium:session-override", true);
capabilities.setCapability("appium:webkitResponseTimeout", 20000);
capabilities.setCapability("appium:useJSONSource", true);
capabilities.setCapability("appium:sendKeyStrategy", "grouped");
capabilities.setCapability("appium:commandTimeouts", "1000000");
capabilities.setCapability("appium:webDriverAgentUrl", customWdaUrl);
capabilities.setCapability("appium:webDriverAgentUrl", WDA_SERVER_URL);
capabilities.setCapability(IOSMobileCapabilityType.WDA_LOCAL_PORT, wdaPort);
Driver is initialized like this
IOSDriver iosDriver = new IOSDriver(url, capabilities);
What could be the issue here?

Backup SSRS Encryption Keys Using Powershell

I have made the following script from google for backing up the SSRS Encryption keys:
cls
$pwd = "sa#123#123"
$SSRSClass = Get-Wmiobject -namespace "root\microsoft\sqlserver\reportserver\rs_BPSSRS\v10\admin" -class "MSReportServer_ConfigurationSetting"
$key = $SSRSClass.BackupEncryptionKey($pwd)
$stream = [System.IO.File]::Create("c:\\SSRS.snk", $key.KeyFile.Length)
$stream.Write($key.KeyFile, 0, $key.KeyFile.Length)
$stream.Close()
But I'm getting the following errors:
Method invocation failed because [System.Object[]] doesn't contain a method named 'BackupEn
cryptionKey'.
At line:5 char:38
+ $key = $SSRSClass.BackupEncryptionKey <<<< ($results)
+ CategoryInfo : InvalidOperation: (BackupEncryptionKey:String) [], RuntimeEx
ception
+ FullyQualifiedErrorId : MethodNotFound
Exception calling "Create" with "2" argument(s): "Positive number required.
Parameter name: bufferSize"
At line:6 char:35
+ $stream = [System.IO.File]::Create <<<< ("c:\\SSRS.snk", $key.KeyFile.Length)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
You cannot call a method on a null-valued expression.
At line:7 char:14
+ $stream.Write <<<< ($key.KeyFile, 0, $key.KeyFile.Length)
+ CategoryInfo : InvalidOperation: (Write:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:8 char:14
+ $stream.Close <<<< ()
+ CategoryInfo : InvalidOperation: (Close:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
I'm using powershell v2. I tried finding about this but no luck. There are around 50+ SSRS servers in our environment and doing backup manually is tiresome. Hence, we came up with this automation. Kindly provide your comments.
Thanks
This piece of code should do the trick:
$ComputerName = "."
$KeyFolder = "C:\Temp"
$KeyPassword = "sa#123#123"
$TimeStamp = Get-Date -Format "-yyyyMMdd-HHmmss"
Get-WmiObject -Namespace "Root\Microsoft\SqlServer\ReportServer" -Class "__Namespace" -ComputerName $ComputerName |
Select-Object -ExpandProperty Name |
% {
$NameSpaceRS = $_
$InstanceName = $NameSpaceRS.SubString(3)
$KeyFileName = Join-Path -Path $KeyFolder -ChildPath ($InstanceName + $Timestamp + ".snk")
"Found Reporting Services in instance '$($InstanceName)' on $($ComputerName); will save key to '$($KeyFileName)' ..."
$SQLVersion = (Get-WmiObject -Namespace "Root\Microsoft\SqlServer\ReportServer\$($NameSpaceRS)" -Class "__Namespace" -ComputerName $ComputerName).Name
$SSRSClass = Get-WmiObject -Namespace "Root\Microsoft\SqlServer\ReportServer\$($NameSpaceRS)\$($SQLVersion)\Admin" -Query "SELECT * FROM MSReportServer_ConfigurationSetting WHERE InstanceName='$($InstanceName)'" -ComputerName $ComputerName
$Key = $SSRSClass.BackupEncryptionKey($KeyPassword)
If ($Key.HRESULT -ne 0) {
$Key.ExtendedErrors -join "`r`n" | Write-Error
} Else {
$Stream = [System.IO.File]::Create($KeyFileName, $Key.KeyFile.Length)
$Stream.Write($Key.KeyFile, 0, $Key.KeyFile.Length)
$Stream.Close()
}
}
The errors that you have mentioned are because your code is trying to fetch information from duplicate entries. Meaning, if you try the above code on the server where only one named instance of SSRS is running, then I suppose it will succeed. Just try this piece and give your comments.
CHEERS.

Detecting memory leak in cocos2dx project for WP8

I want to locate few memory leaks in my cocos2dx application for windows phone 8. IDE is Visual studio express 2012. I saw this link for app profiling. But as written on the page, "Only the Execution option is available for Direct3D apps". I am not able to figure out the option for memory profiling as cocos2dx uses directx in windows phone. How should I detect memory leak?
You can detect the application memory usage by following code.
Add the following code in App.xaml.cs
public partial class App : Application
{
private static Timer timer = null;
public static void BeginRecording()
{
if (System.Diagnostics.Debugger.IsAttached)
{
// start a timer to report memory conditions every 2 seconds
timer = new Timer(state =>
{
// every 2 seconds do something
string report =
DateTime.Now.ToLongTimeString() + " memory conditions: " +
Environment.NewLine +
"\tApplicationCurrentMemoryUsage: " +
getExactValue(DeviceStatus.ApplicationCurrentMemoryUsage) + " MB" +
Environment.NewLine +
"\tApplicationPeakMemoryUsage: " +
getExactValue(DeviceStatus.ApplicationPeakMemoryUsage) + " MB" +
Environment.NewLine +
"\tApplicationMemoryUsageLimit: " +
getActualValue(DeviceStatus.ApplicationMemoryUsageLimit) + " MB" +
Environment.NewLine +
"\tDeviceTotalMemory: " + getActualValue(DeviceStatus.DeviceTotalMemory) + " MB" + Environment.NewLine +
"\tApplicationWorkingSetLimit: " +
getActualValue(Convert.ToInt64(DeviceExtendedProperties.GetValue("ApplicationWorkingSetLimit"))) + " MB" +
Environment.NewLine;
// write to IsoStore or debug conolse
Debug.WriteLine(report);
},
null,
TimeSpan.FromSeconds(2),
TimeSpan.FromSeconds(2));
}
}
public static decimal getExactValue(long stats)
{
return Math.Round(((decimal)(stats) / (decimal)(1048576.00)), 2);
}
public static int getActualValue(long stats)
{
return ((int)Math.Ceiling(getExactValue(stats)));
}
now call the BeginRecording() function in application_launching.
this will give you the exact memory stats after every 2 seconds and you can identify the memory leaks.

Google Analytics & Blackberry UserAgent

I'm using this code to get the blackberry info on google analytics
private static String getUserAgent()
{
String userAgent = "Blackberry" + DeviceInfo.getDeviceName() + "/" +
getOsVersion() + " Profile/" + System.getProperty(
"microedition.profiles" ) + " Configuration/" + System.getProperty(
"microedition.configuration" ) + " VendorID/" +
Branding.getVendorId();
return userAgent;
}
And then using it here :
conn.setRequestProperty("User-Agent", userAgent);
The problem is that it doesn't recognize the terminal like a mobile phone , but it takes difference in browser .
Browser:
Navegador Visitas % Visitas
1. Blackberry8900 36 100,00%
Any idea if google analytics have some params to know that is a mobile phone ? or if i'm using a badformated useraggent.
Thanks for your answers.

Resources