it-source

파워셸 출력 숨기기

criticalcode 2023. 9. 13. 22:40
반응형

파워셸 출력 숨기기

저는 다음과 같은 대본을 가지고 있습니다.

매개 변수([매개 변수(필수 = $true)][문자열]$dest)

New-Item -force -path "$dest\1\" -itemtype directory
New-Item -force -path "$dest\2\" -itemtype directory
New-Item -force -path "$dest\3\" -itemtype directory

Copy-Item -path "C:\Development\1\bin\Debug\*" -destination "$dest\1\" -container -recurse -force
Copy-Item -path "C:\Development\2\bin\Debug\*" -destination "$dest\2\" -container -recurse -force
Copy-Item -path "C:\Development\3\bin\Debug\*" -destination "$dest\3\" -container -recurse -force

스크립트는 문자열을 가져와 정적 원본 경로에서 지정된 루트 문자열로 모든 파일과 폴더를 복사하며, 구조를 명확하게 하기 위해 일부 폴더를 수정합니다.

잘 작동하지만 "New-Item" 명령에서 결과를 출력하고 그것을 숨기고 싶습니다.SE에 대한 넷과 다른 질문들을 살펴보았지만 제 문제에 대한 확실한 답을 찾지 못했습니다.

누군가 궁금해 할 경우 - 대상 폴더가 존재하지 않으면 PS의 -recurse 매개 변수가 모든 하위 폴더를 올바르게 복사하지 않는 결함을 피하기 위해 처음에 "New-item"을 사용합니다. (즉, 필수 사항입니다.)

옵션 1: 파이프를 아웃-널에 연결

New-Item -Path c:\temp\foo -ItemType Directory | Out-Null
Test-Path c:\temp\foo

옵션 2: 다음에 할당$null(옵션 1보다 작은 값)

$null = New-Item -Path c:\temp\foo -ItemType Directory
Test-Path c:\temp\foo

옵션 3: 캐스트 대상[void](또한 옵션 1보다 빠름)

[void](New-Item -Path c:\temp\foo -ItemType Directory)
Test-Path c:\temp\foo

참고 항목:PowerShell에서 출력을 무시하는 더 나은(깨끗한) 방법은 무엇입니까?

언급URL : https://stackoverflow.com/questions/46586382/hide-powershell-output

반응형