본문 바로가기

파워쉘(Powershell)43

파워쉘-엑셀파일 읽기 $fileName = 'c:\powershell\test.xlsx' $objExcel = New-Object -ComObject Excel.Application $WorkBook = $objExcel.Workbooks.Open($fileName) $workSheet = $Workbook.Sheets.Item(1) Write-Host $workSheet.Cells.Item(1,1).Text Write-Host $workSheet.Cells.Item(1,2).Text Write-Host $workSheet.Cells.Item(1,3).Text Write-Host $workSheet.Cells.Item(2,1).Text Write-Host $workSheet.Cells.Item(2,2).Text Write-H.. 2024. 4. 22.
파워쉘-원격 파일서버들의 공유폴더들 권한 읽기 원격 파일서버들의 모든 공유 폴더들의 permission 정보 읽는 방법 서버 이름으로 worksheet 만들고, 각 폴더의 공유권한 정보를 엑셀에 출력 $excel = New-Object -ComObject Excel.Application $excel.Visible = $true $workbook = $excel.Workbooks.add() #$servers = 'File_Server-1' #서버 한 대 #$servers = Get-Content .\Servers.txt # Servers.txt 파일에 저장된 서버들 목록 갖고오 $servers = 'File_Server-1','File_Server-2','File_Server-3' ForEach($com in $servers){ Write-host $.. 2024. 4. 19.
파워쉘 - 엑셀(Excel)에 쓰기 엑셀 실행후 데이터 넣기 $excel = New-Object -ComObject Excel.Application $excel.Visible = $true $workbook = $excel.Workbooks.add() $sheet = $workbook.worksheets.Add() $sheet.Name = "First" $sheet.Cells.Item(1,1) = '1,1' $sheet.Cells.Item(1,2) = '1,2' $sheet.Cells.Item(2,1) = '2,1' Cell 색깔 바꾸기 $sheet.Cells.Item(1,1) = '1,1' $sheet.Cells.Item(1,1).Interior.ColorIndex = 44 Color Index 사용예 $excel = New-Object.. 2024. 4. 19.
파워쉘 (Invoke-Command) : 원격 컴퓨터에서 실행 Invoke-Command를 사용하면 원격 컴퓨터에서 스크립트를 실행시킬 수 있습니다 1. 로컬 컴퓨터에 있는 파워쉘 스크립트를 원격 컴퓨터에서 실행 #test.ps1 파일내용 $env:COMPUTERNAME #현재 컴퓨터의 이름 #로컬에 있는 test.ps1파일을 원격 컴퓨터 com1에서 실행 Invoke-command -FilePat 'C:\Powershell\test.ps1' -ComputerName 'com1' 실행결과 com1 2. 원격 컴퓨터에서 실행 될 명령어들을 ScriptBlock에 넣고 실행 Invoke-Command -ComputerName 'com1' -ScriptBlock{ $env:COMPUTERNAME } 실행결과 com1 3. 하나 이상의 원격컴퓨터에 ScriptBlock에 .. 2024. 4. 18.