Windows PowerShell Language Specification Version 3.0 다운로드하기


다운로드: http://www.microsoft.com/en-us/download/details.aspx?id=36389

이것을 다운로드하면 Powershell 3.0의 기본 명령어 대한 세부적인 설명을 볼 수 있다. 참 유용한 자료다. 이것 하나면 명령어를 공부하는데 도움이 많이 된다.

Powershell v3.0의 여러 가지의 Profile 이해 및 사용하기


참고: http://goo.gl/ew4d0

참 유용한 글이다.

Profile은 Powershell console이나 ISE를 실행할 때 자동으로 실행하는 파일이다. 이 파일에 어떤 내용(예; module, 네트워크 드라이브 연결…)을 포함시키면 Powershell Console을 실행할 때 마다 자동으로 동시에 실행되는 장점이 있다.

1) Current User, Current Host – console : $Home\[My ]Documents\WindowsPowerShell\Profile.ps1
2) Current User, All Hosts   : $Home\[My ]Documents\Profile.ps1
3) All Users, Current Host – console   :  $PsHome\Microsoft.PowerShell_profile.ps1
4) All Users, All Hosts : $PsHome\Profile.ps1
5) Current user, Current Host – ISE : $Home\[My ]Documents\WindowsPowerShell\Microsoft.P owerShellISE_profile.ps1
6) All users, Current Host – ISE  : $PsHome\Microsoft.PowerShellISE_profile.ps1

** 참고1: $Home, $PSHome의 경로를 확인해 본다.
$Home: 현재 로그온 한 사용자의 프로파일 폴더 위치(C:\Users\Administrator)
$PSHome: Powershell이 설치된 폴더 위치(C:\Windows\System32\WindowsPowerShell\v1.0)

** 참고2: $Profile의 경로를 확인해 본다.
$Profile: 현재 로그온한 사용자의 Powershell Profile (~.ps1)

어떤 Profile들이 있는지 확인하려면…
$PROFILE | Get-Member -MemberType noteproperty | Select-Object -Property name

Profile 파일 종류들을 확인하려면…
$PROFILE | Format-List * -Force

이 파일들을 편집하여 내용을 넣으면 유용하게 활용할 수 있다.

이러한 프로파일을 직접 확인하려면…
$PROFILE.CurrentUserAllHosts
$PROFILE.CurrentUserCurrentHost
(=$Profile)

$PROFILE.AllUsersAllHosts
$PROFILE.AllUsersCurrentHost

이러한 파일(.ps1)이 있는지 확인만 하기 위해서는…
Test-Path $Profile
(= Test-Path $PROFILE.CurrentUserCurrentHost)
Test-Path $PROFILE.CurrentUserAllHosts
Test-Path $PROFILE.AllUsersAllHosts
Test-Path $PROFILE.AllUsersCurrentHost
이것들의 결과가 False가 나오면 프로파일 파일(.ps1)이 없는 것이다.
이것을 Invoke-Command -computername pc1,pc2 {Test-Path $Profile}로 실행하여 원격 컴퓨터 PC1, PC2에 확인해 볼 수 있다.

** 현재 로그온한 사용자만을 위한 Profile 파일을 만들려면…
New-Item –Type File –Path $Profile –Force
또는 
New-Item –Type File –Path $Profile.CurrentUserCurrentHost –Force 을 실행한다. 그러면 Microsoft.PowerShell_profile.ps1 파일이 생성된다.
생성된 파일을 수정하기 위해서는 Notepad.exe  $Profile.CurrentUserCurrentHost
** 모든 사용자에게
적용되는 Profile을 만들려면…
New-Item –Type File –Path $Profile.AllUsersCurrentHost –Force 을 실행한다. 그러면 Microsoft.PowerShell_profile.ps1 파일이 생성된다.
생성된 파일을 수정하기 위해서는 Notepad.exe $Profile.AllUsersCurrentHost

(** How to Create Profile: http://technet.microsoft.com/en-us/library/ee692764.aspx)

  • -path $profile We’re passing the full path, stored in the $profile variable, of the item we want to create.
  • -type file This tells New-Item what type of item we’re creating, in this case a file.
  • -force This parameter tells New-Item to create the full path and file no matter what.

=======================================================================

그렇다면 Powershell Console을 실행하면 어떤 Profile 파일이 순서적으로 자동으로 실행되는가?

첫 번째, 모든 사용자에게 적용되는 프로파일인 다음 파일들이 순서대로 실행된다.
1) $PROFILE.AllUsersAllHosts (Profile.ps1)
2) $PROFILE.AllUsersCurrentHost (Microsoft.PowerShell_profile.ps1)

두번째, 현재 로그온 한 사용자에게 적용되는 프로파일인 다음 파일들이 순서대로 실행된다.
3) $PROFILE.CurrentUserAllHosts (Profile.ps1)
4) $PROFILE.CurrentUserCurrentHost (Microsoft.PowerShell_profile.ps1)

그러므로 이 컴퓨터를 사용하는 모든 사용자에게 동일한 설정을 부여하기 위해서는 경로가 정해져 있는 C:\Windows\System32\WindowsPowershell\v1.0\ 2개의 파일(Microsoft.PowerShell_profile.ps1, Profile.ps1)을 수정하면 된다. 이 중에서 하나만 수정하여 사용해도 된다.

 

** 참고: http://community.spiceworks.com/scripts/show/726-my-powershell-profile

Powershell cmdlet를 사용하여 Domain Controller 생성하기


Powershell cmdlet를 사용하여 Server Core 버전이나 Full version에서 DC를 생성할 수 있다. 반드시 다음과 같이 2단계를 거쳐야 한다. 첫번째 단계를 거치지 않으면 두번째 cmdlet를 사용할 수 없으니 주의한다.

1) Install-WindowsFeature -Name AD-Domain-Services
2) Install-ADDSDomainController -DomainName “Powershell.kr”

** 주의 사항: 이 cmdlet는 Powershell v 3.0에서만 가능하다

설치된 Windows Feature(기능) 및 Role(역할) 확인하기


Powershell을 사용하면 쉽게 확인할 수 있다. 그리고 Powershell 버전에 따라 조금 다르게 사용할 수도 있다.

Import-Module -Name ServerManager ; Get-WindowsFeature | Where-Object {$_.Installed -eq $true}  –Powershell v 2.0 / 3.0 모두 가능

Import-Module -Name ServerManager ; Get-WindowsFeature | Where-Object {$_.InstallState -eq “Installed”}  –Powershell v3.0만 가능

 

netdom.exe를 사용하여 컴퓨터 이름 변경하기


로컬 및 원격 컴퓨터의 컴퓨터 이름을 빨리 변경해보자.
여러 가지 방법이 있겠지만 netdom.exe 명령을 사용하면 좋다.
즉, Windows를 설치한 후 컴퓨터 이름을 변경하고자 하거나, 원격 컴퓨터의 컴퓨터 이름을 변경하고자 할 때(Using Powershell) 사용하면 좋다.
보통 컴퓨터 이름을 변경하고 나면 반드시 재시작을 해야만이 적용되기 때문에 아래 명령어를 그냥 외워두면 좋다.

Netdom RenameComputer %computername% /NewName:jesuswithmePC /Force /Reboot 0

** 이 작업을 하려면 반드시 관리자 권한을 가진 사용자 계정으로 로그온해야 한다.
** %computername%은 현재 컴퓨터 이름을 일컫는다. 직접 현재 컴퓨터 이름을 입력해도 되지만 그러면 일일이 컴퓨터 이름을 확인하는 절차를 거쳐야 하는 번거로움이 있다.