아래 내용이 포함 된 텍스트 파일 (test.txt)이 있습니다.
User : MikeyMouse
Pswd : mycrazypswd
connectionstring : serverepor:80,pass=809hjhlkusfasdf,somepropert=somevalue
PS를 사용하여 위 파일의 키 값을 업데이트하여 아래와 같이 "---"로 암호를 마스킹해야합니다.
sser : MikeyMouse
pswd : my---wd
connectionstring : serverepor:80,pass=80---df,somepropert=somevalue
그렇게하는 방법에 대한 제안이 있습니까?
감사
Get/Set-Content
및 Regex -Replace
를 사용 하면 트릭을 수행 할 수 있습니다.
$Path = 'test.txt'
$NewContent = (Get-Content -Path $Path -Raw) -replace '(?<=Pswd : ..)(.*)(?=..\r)', '---' -replace '(?<=pass=..)(.*?)(?=..,)', '---'
Set-Content -Path $Path -Value $NewContent
참조 :
특별한 감사
@olaf : 예견 / 예상 방식을 보여줍니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다