I am using a Powershell (.ps1) script for scanning the physical application and web servers to identify the configuration files related to our application which have hard coded IP addresses specified in them.
Powershell version -1.0 for the Windows server on which i am executing the script and getting error.
I am getting " You cannot call a method on a null valued expression "
The scenario is: running the script on my local physical machine works fine, however, running it on my application server gives me the above error.
$itemsFromFolder = Get-ChildItem -path $drive -include *.txt, *web.config, *.htm, *.html, *.asp, *.ascx, *.aspx, *.xml, *.js, *.css, *.sql -recurse -errorAction SilentlyContinue
Write-host -message "initializing object"
$itemsToScan = New-Object System.Collections.Generic.List[string]
Write-host -message "initializing object $itemsToScan
foreach($item in $itemsFromFolder)
{
$itemsToScan.Add($item.FullName)
#Write-host -message "itemstoscan loop $itemsToScan"
}
I am instantiating an object for System.Collections.Generic.List[string] which will be contained in variable $itemstoscan which will have items to scan for the IP pattern which I am providing.
Questions:
$itemsToScan = New-Object System.Collections.Generic.List[string]is this the right way to instantiate object in powershell 1.0 which is restricting me running the same script on machines of different config?$itemsToScan.Add($item.FullName)I am getting error in evaluating this expression on my App server which is running fine on my local.
$item? It seems you are things more complicating than they are. Could you post a more of your script?