본문 바로가기

반응형

Windows 10

(18)
PowerShell : IEX (문자열을 명령어로 실행하기) - String으로 된 명령어 실행 $msg = "Write-Host `"글자를 출력하세요.`" # $msg와 iex $msg를 비교해보세요. $msg iex $msg Invoke-Expression (Microsoft.PowerShell.Utility) The Invoke-Expression cmdlet evaluates or runs a specified string as a command and returns the results of the expression or command. Without Invoke-Expression, a string submitted at the command line would be returned (echoed) unchanged. docs.microsoft.com
PowerShell : 기초 명령어 (복사, 삭제, 이동) - 복사 # 복사 Copy D:\test1.txt D:\test2.txt # 강제 복사 (읽기 속성이 있는 경우) Copy D:\test1.txt D:\test2.txt -Force # 폴더 복사 Copy D:\folder1 D:\folder2 # 폴더내 파일까지 복사(폴더 하위 폴더 파일은 제외) Copy D:\folder1\* D:\folder2 # 폴더 전체 복사 Copy D:\folder1 D:\folder2 -Recurse Copy-Item (Microsoft.PowerShell.Management) The Copy-Item cmdlet copies an item from one location to another location in the same namespace. For instance,..
PowerSehll : Try, Catch, Finally (예외 처리) - Try, Catch, Finally Try{ 에러나는이상한문자 } Catch{ Write-Host "이상한 문자가 있던데요?" Write-Host $_ }finally{ Write-Host "에러와 상관없이 실행할꺼야!" } $_ : 에러 표출을 위해 사용 about_Try_Catch_Finally About Try Catch Finally In this article --> SHORT DESCRIPTION Describes how to use the Try, Catch, and Finally blocks to handle terminating errors. LONG DESCRIPTION Use Try, Catch, and Finally blocks to respond to or handle term..
PowerShell : Array, 동적 배열 - 배열 선언 # 첫 번째 방법 $arr = 1, 2, 3, 4, 5 # 두 번째 방법 $arr = 1..5 # 세 번째 방법 (Size가 0인 Array) $arr = @() # 네 번째 방법 (동적 할당) $arr = New-Object System.Collections.ArrayList [void]$arr.Add(1) $arr.Add(2) [void]$arr.Add(3) $arr.Add(4) [void]$arr.Add(5) - 배열 출력 $arr = 10, 20, 30, 40 # 첫 번째 방법 $arr # 두 번째 방법 $arr[0..2] # 세 번째 방법 for($i=0; $i -lt $arr.count; $i++) { Write-Host $arr[$i] } # 네 번째 방법 (숫자 형식인 경우에..
PowerShell : Switch - Switch $i=0 switch($i) { 0 {Write-Host "0000"} 1 {Write-Host "1111"} 2 {Write-Host "2222"} } switch("도망") { '도망' {Write-Host "Run"} 0 {Write-Host "0000"} 1 {Write-Host "1111"} 2 {Write-Host "2222"} } about_Switch About Switch In this article --> SHORT DESCRIPTION Explains how to use a switch to handle multiple If statements. LONG DESCRIPTION To check a condition in a script or function, use an..
PowerSehll : For, While, Break - For For($i=0; $i -lt 10; $i++){ Write-Host $i } about_For About For In this article --> Short description Describes a language command you can use to run statements based on a conditional test. Long description The For statement (also known as a For loop) is a language construct you can use to create a loop that docs.microsoft.com - While $i=0 While($i -lt 6){ Write-Host $i $i++ } about_While ..
PowerShell : If, ElseIf, Else - 조건문 비교 연산자 조건문 비교시 보통의 연산자인 =, 기호 대신 약자를 사용한다. -eq : == -ne : != -lt : = - IF문 $name = "Seoul" if($name -eq "seoul"){ Write-Host "seoul == Seoul" } if($name -eq "Seoul"){ Write-Host "Seoul == Seoul" } - IF & ELSEIF $name = "Seoul" if($name -eq "Busan"){ Write-Host "Busan != Seoul" }elseif($name -eq "Seoul"){ Write-Host "Seoul == Seoul" } - IF & ELSE $name = "Seoul" if($name -eq "Busan"){ Write..
PowerShell : 주석 처리 - 한줄 주석 처리 #한줄 주석 처리 - 블록 주석 처리 방법 about_Comment_Based_Help In this article --> SHORT DESCRIPTION Describes how to write comment-based help topics for functions and scripts. LONG DESCRIPTION You can write comment-based help topics for functions and scripts by using special help comment keywords. The Get-Help cmdlet docs.microsoft.com

반응형