PowerShell out-file not working when variable has a "/" in filename -
i have powershell script running , saving results file. name of file using variable url however, forward slash exist "/". file not saved because not forward slash.
$hosturl = "my_webserver" $methtype = "get" $api4 = "/sasl_logs/debug" $txt | out-file ".\$api4.txt"
results file called /sasl_logs/debug.txt or /sasl_logs_debug.txt. have tried replace function working must doing wrong.
$api4.replace("//","_") $api4.replace("/","_") $api4.replace("\/","_")
the problem here not slash. not in way think is. windows (and powershell) support /
delimited path names fine (as many/most other windows applications).
the problem here path /sasl_logs/debug
being seen absolutel path (it starts slash) , being seen c:\sasl_logs\debug
, out-file
refuses create sasl_logs
directory can put debug
file in location.
create c:\sasl_logs
directory , should work correctly.
if don't want directory (or indeed directory @ all) , $api4
value isn't being set literally (so can't change code) want attempting.
$api4 = $api4.substring(1) -replace "/","_"
substring
strips off leading /
, -replace
operator replacement. use $api4.substring(1).replace("/","_")
of course.
Comments
Post a Comment