I'm trying to find the log firectory location by connecting to SQL database and store the log file in that location.We have standard log directory with naming convention. After i get the director from sql database, i need to create two more subdirectories and append the log file into that location ( for log file i'm using add-log file and pslogging function ).
I'm able to get the log directory information from sql database but script is failing to create the new directories and append the path near add-file command.
Here's the error :
Cannot convert 'System.Object' to the type 'System.String' required by parameter 'FilePath'. Specified method is not supported.
The error you've posted doesn't appear to have anything to do with the attached script, which has no calls to Out-File.
Focusing just on what you've attached, I can see a few apparent errors:
Try making these changes:
# Change this line: $InstanceName = $($Dataset.Tables.Rows) # To this: (Note, the subexpression operator $() isn't necessary here, but it doesn't hurt anything either) $InstanceName = $($Dataset.Tables.Rows) # Change these lines: $logFolder_Path = @() $logFolder_Path = $logFolder_Path +$InstanceName # To this: (Note: the [string] cast is to make sure you get the right type, regardless of what the $InstanceName variable holds. That # doesn't guarantee that the value of the string will be correct, but it's a start. [string]$logFolder_Path = $InstanceName # Change this line: $logFile = Add-LogFile -Path $logFolder_Path:\dbrestorelog_$Timestamp.txt # To this: $logFile = Add-LogFile -Path $logFolder_Path\dbrestorelog_$Timestamp.txt
That's probably the minimum changes you need to make to have a chance at getting this working. I have a few other comments, though:
Thank you very much David for your detail response....I really appreciate it
I have some questions regarding your post above...
And regarding the out-file...i'm creating an xml file and saving the xml file at $logfolder_path ( same location )..
$filename = '\template_restore_' + $Timestamp + '.xml' ——- ( $timestamp is a function created in the script....when log file or xml file is generated it will be stored with timestamp )
Please let me know your thoughts... and let me know if you need more information
I just looked over your code again, and realized that I missed some parts of it earlier. I had assumed that the line "$logFolder_Path = @()" was the first time you were doing anything with the $logFolder_Path variable, when it was not.
This time I'll just attach my recommended updates. I've replaced "Rows" with "Rows" in all places that occurs, and any time you were appending to the path variable, I've updated those lines to use the Join-Path cmdlet.
Give it a shot and let me know if you have any problems.
AWESOME....it worked this time.
thank you very much David...appreciate your help..
You must be logged in to reply to this topic.