Hi, this is my following code with two input parameters,
param(
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]
$textFilePath,
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]
$searchDirectory
)
foreach($FileName in [System.IO.File]::ReadLines($textFilePath)) {
# if the file could be found
if(Get-ChildItem -Path $searchDirectory -Filter $Filename -Recurse) {
return 1 # exit early from the script here
}
}
return 0 # return is not needed here
i want to input url for the second input parameter, but error occurs as below. Please let me know, what is missing in my code. I have following files listed in the LibraryChecker.SharedEnvironmentLog.txt (specified in the URL)
Exception calling "ReadLines" with "1" argument(s): "The given path's format is not supported."
At \Desktop\test.ps1:23 char:22
+ foreach($FileName in [System.IO.File]::ReadLines($textFilePath)) {
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : NotSupportedException
Before we proceed … When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.
Hi, I modified code like this, But its throwing error .
param(
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]
$SourceFilePath,
[string]
$DestFilePath,
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]
$searchDirectory
)
#if(-not (Test-Path -Path $searchDirectory)){
#Write-Host "The source folder specified is not valid"
#return
#$SourceFilePath = https://github.bnsf.com/raw/MW/tfsbuildrelease/master/LibraryChecker.SharedEnvironmentLog.txt
#$DestFilePath = c:\LibraryChecker.SharedEnvironmentLog.txt
#Download the file
Invoke-WebRequest -Uri $SourceFilePath -OutFile $DestFilePath
# Get-Content -Path $textFilePath
foreach($FileName in [System.IO.File]::ReadLines($DestFilePath)) {
# if the file could be found
if(Get-ChildItem -Path $searchDirectory -Filter $Filename -Recurse) {
return 1 # exit early from the script here
}
}
return 0 # return is not needed here
Supply values for the following parameters:
SourceFilePath: https://github.bnsf.com/raw/MW/tfsbuildrelease/master/LibraryChecker.SharedEnvironmentLog.txt
searchDirectory: D:\
StatusCode : 200
StatusDescription : OK
Content : Bnsf.Middleware.Log.Elk.Core.dll
a.txt
RawContent : HTTP/1.1 200 OK
Content-Security-Policy: default-src 'none'; style-src 'unsafe-inline'; sandbox
Strict-Transport-Security: max-age=31536000
Vary: Authorization,Accept-Encoding,Origin
X-Content-Typ...
Forms : {}
Headers : {[Content-Security-Policy, default-src 'none'; style-src 'unsafe-inline'; sandbox], [Strict-Transport-Security, max-age=31536000], [Vary,
Authorization,Accept-Encoding,Origin], [X-Content-Type-Options, nosniff]...}
Images : {}
InputFields : {}
Links : {}
ParsedHtml : mshtml.HTMLDocumentClass
RawContentLength : 41
Exception calling "ReadLines" with "1" argument(s): "Empty path name is not legal.
Parameter name: path"
At C:\Users\C990345\Desktop\test.ps1:29 char:22
+ foreach($FileName in [System.IO.File]::ReadLines($DestFilePath)) {
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ArgumentException
0