简体   繁体   English

Powershell MySQL完整路径

[英]Powershell MySQL full path

Im trying to insert a full directory path into MySQL from a Powershell script. 我试图从Powershell脚本向MySQL中插入完整的目录路径。 The connection and insert work great but i'm hitting a snag with the readability of the filepath. 连接和插入效果很好,但我遇到了文件路径可读性的障碍。 I've looked around online for some time and can't find anyone with this exact problem: Either powershell or mysql is dropping the \\ (backslash) characters from the file path variable on insert. 我已经在线浏览了一段时间,找不到任何人遇到这个确切的问题:Powershell或mysql从插入时的文件路径变量中删除\\(反斜杠)字符。 In the console they appear fine as objects so I am think this is SQL related? 在控制台中,它们看起来像对象一样好,所以我认为这与SQL有关吗? Im not finding a whole lot about escaping on insert which just loops me back to powershell replacing (which does not work work either. 我没有找到关于转义插入的很多内容,这只会使我回到Powershell替换(这也不起作用)。

I know how to escape and replace characters IF I know where they are going to be but how do I escape baackslashes that appear in different parts of the file path? 如果知道字符的位置,我知道如何转义和替换字符,但是如何转义出现在文件路径不同部分的反斜杠呢?

Thanks in advance 提前致谢

I achieved this by using a -split operator in PS. 我是通过在PS中使用-split运算符来实现的。 After I split the file path at all the backslashes I just built a string to cat my variable back together. 在所有反斜杠处分割文件路径后,我仅构建了一个字符串以将变量重新组合在一起。 Hacky...but it works. 哈克...但它有效。 :) The var $RemoteName inserts into the DB as \\\\path1\\path2$ :)变量$ RemoteName作为\\\\ path1 \\ path2 $插入数据库

           $shared = gwmi Win32_NetworkConnection -ComputerName $hostname | select LocalName,RemoteName
                foreach($sharemap in $shared){
                    $localname = $sharemap.LocalName
                    $RemoteName_nonstring = $sharemap.RemoteName
                    $RemoteName = $RemoteName_nonstring
                    $file = $RemoteName.Split("\")

                        $b = $file[2]
                        $c = $file[3]

                        $RemoteName = "\\\\$b\\$c$"

Thanks for the sugestions and if anyone has a more efficient way im all ears... 感谢您的建议,如果有人能以更有效的方式来听...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM