I'm using the Invoke-Expression cmdlet in PowerShell to load modules.
The following code works as intended.
$url="http://pastebin.com/raw/FuxtpN69"
IEX (New-Object System.Net.Webclient).DownloadString($url)
But when I try using variables to split the domain and the page.
$u="http://pastebin.com"
$rl="/raw/FuxtpN69"
$url="$u$rl"
IEX (New-Object System.Net.Webclient).DownloadString($url)
I get the following path error:
Exception calling "DownloadString" with "1" argument(s): "The given path's format is not supported."
At line:8 char:53
+ IEX (New-Object System.Net.Webclient).DownloadString <<<< ($url)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Can someone help me? Thanks in advance.
I think you are running PowerShell as a different account (for example an administrator).
Maybe that account's proxy settings are different that your normal account's?
See the credentials part first,
$webClient.UseDefaultCredentials = $true
Then, Try setting
$client.Proxy = $null
before downloading and see if it helps.
Related
We have a powershell script which is used to call an API by establishing connection over SSL. The certificates are placed along powershell script to be used by it. And the password is mentioned in an ini file which script reads. It was working fine earlier but suddenly it has started giving below error:
Exception calling "Import" with "3" argument(s): "The specified network password is not correct.
"
At C:\Users\Administrator\Desktop\NewInstallIssue\Download\win\installCDWindows.ps1:70 char:3
+ $cert.Import($CertificatePath, $KeyStore_Password ,'DefaultKeySet')
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : CryptographicException
The part of powershell script throwing this error is:
$cert= New-Object System.Security.Cryptography.X509Certificates.X509Certificate2
$CertificatePath = Join-Path -Path $PSScriptRoot -ChildPath 'cdCert.pfx'
$cert.Import($CertificatePath, $KeyStore_Password ,'DefaultKeySet')
$KeyStore_Password contains correct password as I tested what is stored in this variable just before $cert.Import using echo.
I am trying to start the web automation with using Chrome driver and Selenium. But I am getting an error that, web driver was not loaded. Below is my code entered. If someone could help me to correct this and start to automate would be appreciated.
Import-Module 'C:\AHKM\ChromeAutomation\WebDriver.dll'
$WebDriver = New-Object OpenQA.Selenium.Chrome.ChromeDriver
$WebDriver.Navigate().GoToUrl('www.google.com')
Error is below:
You cannot call a method on a null-valued expression.
At line:3 char:9
+ $WebDriver.Navigate().GoToUrl('www.google.com')
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
We resolved this issue by supplying the folder where chromedriver.exe is located, e.g.
$WebDriver = New-Object OpenQA.Selenium.Chrome.ChromeDriver -ArgumentList "C:\TEMP"
WebClient.UploadFile: $client = New-Object System.Net.WebClient $client.Credentials = New-Object System.Net.NetworkCredential("user", "password") $client.UploadFile("ftp://ftp:50000/test.zip", "C:\HML-V-DC.zip")
When using this script on one computer I am able to upload a file directly to my FTP serve without any issues
But when running this on another machine in another location I get an error "You cannot call a null-valued expression"
Powershell version on computer that is not working: PSVersion 5.1.14393.3866
Powershell version on computer that is working: PSVersion 5.1.19041.610
You cannot call a method on a null-valued expression.
At line:1 char:1
WebClient.UploadFile: $client = New-Object System.Net.WebClient $clie ...
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Was hoping someone with some quick insight may be able to help me understand what I am missing here.
Thank you
Remove "WebClient.UploadFile: " from the line
$client = New-Object System.Net.WebClient
I am working on a deployment script for some software, and my script is working on probably 90% of the machines it runs on, but on the other 10%, I get a failure in the download portion. Here is what I have:
$tls = "Tls";
$Token = "#ZorusKey#";
[System.Net.ServicePointManager]::SecurityProtocol = $tls;
$source = <Source>
$destination = "C:\installers\ZorusInstaller.exe";
$WebClient = New-Object System.Net.WebClient
$WebClient.DownloadFile($source, $destination)
I have created the C:\installers folder on all target machines, so I don't think that's the problem. When run as a script, I get the following exception:
Exception calling "DownloadFile" with "2" argument(s): "An exception occurred during a WebClient request."
At C:\Windows\system32\config\systemprofile\AppData\Local\f1e96243cb9c4ef0b0336a152ed8827f.ps1:8 char:1
+ $WebClient.DownloadFile($source, $destination)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : WebException
Which then causes the following steps to fail, as the downloaded file doesn't exist.
I have also taken the step on several of the failing machines of running each line of the script above one at a time (copied / pasted from the same Powershell ISE window) and the download works without issue. looking for a possible reason / resolution.
Thanks in advance.
I am trying to validate the local user credential using the below code:
Add-Type -AssemblyName System.DirectoryServices.AccountManagement
$DS = New-Object System.DirectoryServices.AccountManagement.PrincipalContext('machine',$ComputerName)
$status=$DS.ValidateCredentials($UserName, $Password)
I am getting the below error:
Exception calling "ValidateCredentials" with "2" argument(s): "The specified network name is no longer available.
"
At line:1 char:1
+ $ds.ValidateCredentials('User','Password')
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : PrincipalOperationException
Please help me to fix this out.
Thanks in advance
Note: I am not getting this error in all the machine. Out of 87 machines i am getting this error in 12 machines alone.
Starting 'server' service fixed the issue