Cloud & Platform
PowerShell 및 Azure 명령어 정리
PowerShell 및 Azure 명령어 정리 학습 내용을 정리한 백필 노트입니다.
이 글은 2025년 학습 기록을 블로그 형식으로 정리한 백필 노트입니다.
1. PowerShell 파일/디렉터리 작업
- 폴더 및 파일 생성
New-Item -Path "C:\" -Name "PowerShell" -ItemType "Directory"
New-Item -Path ".\PowerShell\" -Name "test00.txt" -ItemType "File" -Value "PS 시작"
Get-Content -Path .\PowerShell\test00.txt -TotalCount 1
- 내용 포함 파일 생성
cd /
New-Item -Path "C:\" -Name "PowerShell" -ItemType "Directory"
New-Item -Path ".\PowerShell\" -Name "test00.txt" -ItemType "File" -Value "1: Tom
2: Alice
3: Jane"
- 파일 내용 확인
Get-Content -Path .\PowerShell\test00.txt
Get-Content -Path .\PowerShell\test00.txt -TotalCount 3
- 파일 삭제
Remove-Item .\PowerShell\*.*
- 백틱(`) 사용한 줄바꿈 포함 파일 생성
New-Item -Path ".\PowerShell\" -Name "test00.txt" -ItemType "File" -Value "1: Tom`n2: Alice`n3: Jane"
Get-Content -Path .\PowerShell\test00.txt
Get-Content -Path .\PowerShell\test00.txt -TotalCount 2
- 현재 폴더 확인
Get-ChildItem
2. Azure 로그인 및 구독 선택
- Azure 계정 연결
Connect-AzAccount
- 문제가 있을 경우:
Connect-AzAccount -TenantId <TenantId>
Connect-AzAccount -TenantId 0aff2c88-993e-41ba-bfc4-4fd6fad97ccc
- 구독 선택
Select-AzSubscription -Subscription <구독 ID>
Select-AzSubscription -Subscription 4ac3198f-4982-4a06-8afa-f98ba88c4f87
3. 리소스 그룹 및 VM 생성 (PowerShell)
- 리소스 그룹 생성
New-AzResourceGroup -Name rg-myPowerShell -Location KoreaCentral
Get-AzResourceGroup | Format-Table
- 가상머신 생성
New-AzVm `
-ResourceGroupName "rg-myPowerShell" `
-Name "vm-myVMPS" `
-Location "KoreaCentral" `
-VirtualNetworkName "vnet-myVnetPS" `
-SubnetName "snet-mySubnetPS" `
-SecurityGroupName "nsg-myPS" `
-PublicIpAddressName "pip-myPublicIpPS"
- 계정 정보 입력:
- 사용자:
azureuser - 비밀번호:
Pa$$w0rd.1234
- 사용자:
4. 네트워크 및 변수 구성 (PowerShell)
- 공용 변수 선언
$location = "KoreaCentral"
$rgName = "rg-myPowerShell"
- 리소스 그룹 제거
Remove-AzResourceGroup -Name rg-myPowerShell
Get-AzResourceGroup | Format-Table
- 리소스 그룹 생성 및 확인
$rg = New-AzResourceGroup -Name $rgName -Location $location
Get-AzResourceGroup | Format-Table
- 서브넷 구성
$Subnet00 = New-AzVirtualNetworkSubnetConfig -Name frontendSubnet -AddressPrefix "10.0.0.0/24"
- 가상 네트워크 구성
New-AzVirtualNetwork `
-Name vnet-MyPSNet `
-ResourceGroupName $rg.ResourceGroupName `
-Location $location `
-AddressPrefix "10.0.0.0/16" `
-Subnet $Subnet00
5. Azure CLI 명령어
- 리소스 그룹 생성
az group create --name rg-myCLI --location KoreaCentral
-
가상머신 생성
(
^→ Windows CMD / ``` → PowerShell 줄바꿈)
az vm create ^
--name vm-myVMCLI ^
--resource-group rg-myCLI ^
--image UbuntuLTS ^
--location KoreaCentral ^
--admin-username azureuser ^
--admin-password Pa$$w0rd.1234
6. VS Code 확장 도구
- 설치 후 필요한 도구
- Azure CLI Tools
- PowerShell