Reputation: 1341
I have a hash that should contain a lot of related stuff one thing is the 'handle' for a log-file:
$myHash = NewObject psobject -Property @{
# ...
"LogFile" = [System.IO.StreamWriter] $($Env:USERPROFILE+"\Documents\Logs\MsgLog.txt")
# ...
}
This fails with (my translation): The value "C:\Users..." cannot be converted into a "System.IO.StreamWriter"
The path is valid.
What do I have to change?
Thanks in advance
Gooly
Upvotes: 0
Views: 1332
Reputation: 201592
Try it like this:
$myHash = New-Object psobject -Property @{
# ...
LogFile = new-object System.IO.StreamWriter "$($Env:USERPROFILE)\Documents\Logs\MsgLog.txt"
# ...
}
Note: you don't have to quote the key/property names unless you're putting spaces in them.
Upvotes: 2