(강추)Active Directory의 컴퓨터 목록을 이용하여 원격 컴퓨터 제어하기 PowerShell따라하기

Active Directory 컴퓨터 목록을 불러 오는 방법은 다음과 같다.

Get-ADComputer-Filter * -Searchbase "ou=Lab, dc=test, dc=domain" | Select-Object –Property @{Label="ComputerName";Expression={$_.Name}} 

이렇게 불러 온 것을 변수로 지정한다.
$adcomGet-ADComputer -Filter * -Searchbase "ou=Lab, dc=test, dc=domain" | Select-Object –Property @{Label="ComputerName";Expression={$_.Name}} | New-PSsession 

그런 다음 Get-PSsession을 한다. 그러면 여러 대의 컴퓨터에 세션이 맺어진 것을 알 수 있다
그런 다음 enter-pssession -id 1 으로 접속하여 원격 컴퓨터에서 작업을 하면 된다.

더 좋은 방법은 invoke-command를 이용하는 것이다.
help invoke-command -full을 보면 invoke-command -session $adcom을 사용할 수 있다고 한다.
그러면 invoke-command -session $adcom -scripblock {get-service | where {$_.status -eq "stopped"}}를 하여 AD의 OU가 Lab에 소속된 컴퓨터 10대에 접속하여 10대의 컴퓨터의 서비스 정보를 불러 올 수 있다.
더 나아가서 invoke-command -session $adcom -FilePath c:\scripts\myscript.ps1을 실행하여 스크립트 내용에 대한 정보도 10대의 컴퓨터에서 불러 올 수 있다는 것이다.

대단하다!




공유하기 버튼

 

특정한 폴더에 있는 모든 ps1 스크립트 파일에 동시에 디지털 서명 추가하는 방법 PowerShell따라하기

아래 내용을 ps1 파일로 만들어 실행하면 된다.
======================================================================
## 이것을 실행하면 C:\Lab\Scripts 폴더에 있는 모든 .ps1 파일을 한꺼번에 디지털 서명을 추가할 수 있다.
# 모든 스크립트를 찾아서 content를 UTF8로 저장한다
foreach($File in get-childitem | where-object{($_.Extension -ieq '.PS1')})
{
 $FileName = $File.Name
 $TempFile = "$($File.Name).UTF8"
 get-content $FileName | out-file $TempFile -Encoding UTF8
 remove-item $FileName
 rename-item $TempFile $FileName
}
 
# 로컬 컴퓨터에 설치된 인증서를 찾는다
$cert = Get-ChildItem cert:\CurrentUser\my -codesigning
 
# 모든 스크립트를 찾는다
$Files = Get-ChildItem C:\lab\Scripts *.ps1 -Recurse
 
# 각 파일에 디지털 서명을 추가한다
Foreach($file in $Files) {$a = $file.fullname
Set-AuthenticodeSignature -filepath $a -Certificate $cert -IncludeChain ALL -force
}
 
==============
참고: http://bit.ly/IRnkJW



공유하기 버튼

 

PowerShell에서 사용하는 괄호 용어 정리하기 PowerShell따라하기

cmdlet를 사용하다 보면 다양한 종류의 괄호(Bracket)를 사용하게 된다.
각 괄호의 이름을 한 번 알아본다.
괄호의 대표 이름은 Bracket이다. 뭐든지 특별한 것은 별도의 이름이 붙는다.
영어로는 모두 Bracket가 붙는다. 
우리 말은 모두 괄호라는 이름이 붙는다.

(소)괄호: () bracket, round bracket, parenthesis

중괄호: {} curly bracket, brace

대괄호: [] square bracket

꺽쇠 괄호: <> angle bracket



공유하기 버튼

 

인증서를 다른 곳으로 복사하기 PowerShell따라하기

PowerShel에서 .ps1 파일을 실행하는 것을 제한하려면 모든 클라이언트 컴퓨터에 ExecutionPolicy를 AllSigned로 해두어야 한다.
이런 환경에서 sample.ps1 파일을 실행하려면 이 스크립트 안에 서명(Signature)가 있어야 한다. ps1 파일에 서명을 등록하려고 할 때 인증서가 필요하다. 이 인증서는 개인정보교환용으로 사용하는 pfx 파일만 가능하다. 그래서 그 인증서를 인증서 서버에서 받아서 그대로 활용해도 되고 다른 곳으로 이동하여 활용해도 된다. 다른 곳으로 이동하는 방법이 아래에 나와 있다.
그리고 이 인증서는 로컬 컴퓨터의 신뢰된 인증 기관에 등록도 시켜줘야 한다.




공유하기 버튼

 

[Active Directory Module for Windows PowerShell] 실행 오류 해결 PowerShell따라하기


[Active Directory Module for Windows PowerShell]을 실행할 때 ‘Unable to find a default server with Active Directory Web Service running’라는 오류가 발생하면 PowerShell Console에서 다음과 같이 작업을 한 후 services.msc에서 Active Directory Web Services에서 서비스를 시작시켜준다. 그런 다음 다시 [Active Directory Module for Windows PowerShell]을 실행하면 된다.

[System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()



























공유하기 버튼

 

Acrobat 프로그램으로 .pfx 인증서 만든 후 PowerShell에서 확인하기 PowerShell따라하기

Adobe Acrobat 프로그램을 사용하여 .pfx 인증서를 생성할 수 있다.
자세한 방법은 http://bit.ly/IpJmlP 참고한다.

생성한 인증서 내용을 보는 방법은...
Get-PfxCertificate -FilePath c:\lab\YongShik_Lee.pfx



공유하기 버튼

 

현재 세션에서 스크립트를 실행한 후 다시 스크립트를 실행하지 않도록 하기 PowerShell따라하기

PowerShell.exe -ExecutionPolicy RemoteSigned -File c:\GetProcess.ps1

공유하기 버튼

 

배치 파일 생성할 때 참고할 명령어 Windows

여기서 @echo off, echo, pause 등등을 이해할 수 있다

공유하기 버튼

 

HP Envy 노트북의 숫자 키패드 입력 문제 해결하기 Windows

메모장(notepad.exe)을 열어서 아래 내용을 입력하여 Numlock.vbs로 저장하여 실행하면 숫자 키패드를 사용할 수 있다.

set WshShell = CreateObject("WScript.Shell")
WshShell.SendKeys "{NUMLOCK}"

공유하기 버튼

 

PowerShell Script를 이용하여 메일 보내기 PowerShell따라하기

1) 먼저 smtp 메일 서버를 설치하여 운영한다.
2) 파워셀 스크립트를 작성한다. (HasLoggedOn.ps1)
Send-MailMessage -Body 'Lowoon has logged on her computer.' -From jesuswithme@hotmail.com -to jesuswithme@gmail.com -SmtpServer localhost  -Subject 'Lowoon has logged on her computer -From PowerShell'
3) Group Policy에서 Logon Scipt 에 이 스크립트 파일을 링크를 건다

4) 로그오프 할 때도 메일을 보내려면 동일하게 작업하면 도니다.
Send-MailMessage -Body 'My lovely daughter Lowoon has logged Off' -From jesuswithme@hotmail.com -to jesuswithme@gmail.com -SmtpServer localhost  -Subject 'My lovely daughter Lowoon has logged Off. From PowerShell'

공유하기 버튼

 

1 2 3 4 5 6 7 8 9 10 다음