简体   繁体   English

一键查找并替换所有内容

[英]powershell find and replace all in one line

I have this line of code which gives me domain\\username. 我有这行代码,它为我提供了域\\用户名。 However, I need to replace the \\ with _. 但是,我需要用_替换\\。 Do I have to do this multiple lines or I can do this in one line? 我必须做多行还是可以在一行中完成?

$UAN = $userProfile["AccountName"].Value
$UAN = $UAN.Replace("/","_")

The above does not work even if it's multiple line. 即使是多行,以上内容也不起作用。

使用- -replace

$UAN = ($userProfile["AccountName"].Value) -replace "\\", "_"

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

相关问题 Powershell仅查找和替换CSV的第一行 - Powershell Find and replace first line of CSV only 查找和替换所有文件的PowerShell脚本 - PowerShell Script to Find and Replace for all Files PowerShell-打开文件,在一行中找到一个字符串,并替换上一行中的字符串 - PowerShell - open a file, find a string in a line and replace a string in a previous line 全部放到一个文件中 - out put to a file all on one line powershell 在PowerShell中使用回车符和换行符查找/替换字符串 - Find/replace string with carriage return and line feed in PowerShell 通过powershell在XML字符串中将所有换行符替换为\\ n,并将制表符替换为\\ t - Replace all line breaks with \n and tabulations with \t in a XML string by powershell 使用Powershell中的不同值查找并替换JSON中值的所有实例 - Find and Replace all instances of a value in JSON with different value in Powershell 如何从 Powershell 中的已知文件列表中查找和替换所有子字符串? - How to find and replace all substrings from a list of known files in Powershell? 用于查找和替换具有特定扩展名的所有文件的 PowerShell 脚本 - PowerShell Script to Find and Replace for all Files with a Specific Extension 需要查找并替换 PowerShell 脚本中出现的字符串 - Need to find and replace one occurrence of a string in a PowerShell script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM