달력

4

« 2024/4 »

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
2015. 8. 12. 09:20

PowerShell로 SQL 쿼리 Etc.2015. 8. 12. 09:20

Param(

  [Parameter(Mandatory=$True)]

  [string]$SQLServer,

  [Parameter(Mandatory=$True)]

  [string]$SQLDBName,

  [Parameter(Mandatory=$True)]

  [string]$UserID,

  [Parameter(Mandatory=$True)]

  [string]$UserPW

)


$SqlQuery = "SELECT * FROM TABLE_VIEW"


$SqlConnection = New-Object System.Data.SqlClient.SqlConnection

# $SqlConnection.ConnectionString = "Server = $SQLServer; Database = $SQLDBName; Integrated Security = True"

$SqlConnection.ConnectionString = "Server = $SQLServer; Database = $SQLDBName; uid="+$UserID+"; pwd="+$UserPW


$SqlCmd = New-Object System.Data.SqlClient.SqlCommand

$SqlCmd.CommandText = $SqlQuery

$SqlCmd.Connection = $SqlConnection

$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter

$SqlAdapter.SelectCommand = $SqlCmd

$DataSet = New-Object System.Data.DataSet

$SqlAdapter.Fill($DataSet) | Out-Null

$SqlConnection.Close()


foreach ($row in $DataSet.Tables[0].Rows) {

  $Row1 = $row[0].ToString().Trim()

  $Row2 = $row[1].ToString().Trim()

  $Row3 = $row[2].ToString().Trim()

  Write-Host $Row1, $Row2, $Row3

}




:
Posted by 커널64
2015. 3. 26. 09:39

AWS EC2 리눅스 인스턴스 로그인 방식 변경 Etc.2015. 3. 26. 09:39

기본적으로 AWS에서 Linux EC2 인스턴스를 생성하면, 인증서를 이용해 로그인하도록 되어 있습니다.


보안적으로는 이 방법이 권장되나, 테스트 환경 등에서는 불편할 수 있습니다.

로그인 방식을 기존 인증서 방식과 더불어 ID, P/W로 로그인할 수 있도록 아래와 같이 합니다.


우선 Linux 인스턴스에 로그인 후


1) root 계정에 대한 암호를 설정합니다.

sudo passwd root


2) sshd 설정 파일을 열어

sudo vi /etc/ssh/sshd_config


3) 아래 부분을 수정합니다.

# Change to no to disable tunnelled clear text passwords

PasswordAuthentication no


# Change to no to disable tunnelled clear text passwords

PasswordAuthentication yes


4) 마지막으로, 인증서를 root 계정에 복사합니다.

sudo cp /home/<User Account>/.ssh/authorized_keys /root/.ssh/




:
Posted by 커널64

' Event Log is Full, Export and Clear (이벤트 기록: ID 9002)

' Event Log: Operations Manager, Event Source: Health Service Script


CONST EventID = 9002

CONST USAGE_LIMIT = 95

CONST MAX_FILES = 5


ScriptName = ""


Set oArgs = WScript.Arguments

TargetBackupPath = ""

If oArgs.Count > 1 Then

  For i = 0 to oArgs.Count-1

    TargetBackupPath = TargetBackupPath & oArgs(i) & " "

  Next

  TargetBackupPath = Trim(TargetBackupPath)

Else

  TargetBackupPath = Trim(oArgs(0))

End If


CONST INFORMATION = 0

CONST ERROR = 1

CONST WARNING = 2


Set oFSO = CreateObject("Scripting.FileSystemObject")


On Error Resume Next


Set objFolder = oFSO.GetFolder(TargetBackupPath)

If Err.Number <> 0 Then

  Set objFolder = NOTHING

  Set oFSO = NOTHING

  WScript.Quit

Else

  Set wshNetwork = WScript.CreateObject( "WScript.Network" )

  strComputerName = Ucase(wshNetwork.ComputerName)

  Set wshNetwork = NOTHING

  

  Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")

  Set colItems = objWMIService.ExecQuery ("Select * from Win32_NTEventLogFile Where LogfileName = 'Application' OR LogfileName = 'System'")

  

  For Each Item in colItems

    tmpUsage = Round((Item.FileSize/Item.MaxFileSize)*100,0)

    tmpLogName = Item.LogfileName

    tmpLogExt = Item.Extension

    

    If tmpUsage > USAGE_LIMIT Then

      Set colLogFiles = objWMIService.ExecQuery("Select * from Win32_NTEventLogFile Where LogFileName='"&tmpLogName&"'")

      For Each objLogfile in colLogFiles

        PreDateTime = cDate(Now)

        PreDateTime = Year(PreDateTime)&Right("0"&Month(PreDateTime),2)&Right("0"&Day(PreDateTime),2)&Right("0"&Hour(PreDateTime),2)&Right("0"&Minute(PreDateTime),2)

        objLogFile.BackupEventLog(TargetBackupPath & "\" & strComputerName & "_" & tmpLogName & "_" & PreDateTime & "." & tmpLogExt)

        objLogFile.ClearEventLog()

        strMessage = tmpLogName & " event log has been cleared. Export path: " & TargetBackupPath & "\" & strComputerName & "_" & tmpLogName & "_" & PreDateTime & "." & tmpLogExt

        Set oAPI = CreateObject("MOM.ScriptAPI")

        Call oAPI.LogScriptEvent(ScriptName, EventID, INFORMATION, strMessage)

        Set oAPI = NOTHING

      Next

      Set colLogFiles = NOTHING

    End If

    

  Next

  Set colItems = NOTHING

  Set objWMIService = NOTHING

  Set colFiles = objFolder.Files

  

  Do While colFiles.Count > MAX_FILES

    Set colFiles = objFolder.Files

    dtmOldestDate = Now

    For Each objFile in colFiles

      If objFile.DateCreated < dtmOldestDate Then

        dtmOldestDate = objFile.DateCreated

        strOldestFile = objFile.Path

      End If

    Next

    oFSO.DeleteFile(strOldestFile)

  Loop

  Set colFiles = NOTHING

  objFolder = NOTHING

  Set oFSO = NOTHING

End If


:
Posted by 커널64

Set oArgs = WScript.Arguments


If oArgs.Count = 0 Then

  WScript.Echo "Argument was not provided."

  WScript.Quit

End If


strDirectory = ""

If oArgs.Count > 1 Then

  For i = 0 to oArgs.Count - 1

    strDirectory = strDirectory & oArgs(i) & " "

  Next

Else

  strDirectory = oArgs(0)

End If


Set oFSO = CreateObject("Scripting.FileSystemObject") 


Set Folder = oFSO.GetFolder(strDirectory)

Set Files = Folder.Files

NumOfFiles = Files.Count


Set Files = NOTHING

Set Folder = NOTHING

Set oFSO = NOTHING


WScript.Echo strDirectory & vbCRLF

WScript.Echo "# of Files: " & NumOfFiles





:
Posted by 커널64
2015. 1. 13. 21:47

VBS - 파일 수정 날짜 쿼리 (매개 변수) Etc.2015. 1. 13. 21:47

Set oArgs = WScript.Arguments


If oArgs.Count = 0 Then

  WScript.Echo "Argument was not provided."

  WScript.Quit

End If


strFilePath = ""

If oArgs.Count > 1 Then

  For i = 0 to oArgs.Count - 1

    strFilePath = strFilePath & oArgs(i) & " "

  Next

Else

  strFilePath = oArgs(0)

End If


Set sFSO = CreateObject("Scripting.FileSystemObject")

Set f = sFSO.GetFile(strFilePath)

FileModifiedDate = cDate(f.DateLastModified)


Set f = NOTHING

Set sFSO = NOTHING


WScript.Echo strFilePath & vbCRLF

WScript.Echo "Modified Date: " & FileModifiedDate



:
Posted by 커널64

On Error Resume Next


Set objFwMgr = CreateObject("HNetCfg.FwMgr")

Set objProfile = objFwMgr.LocalPolicy.CurrentProfile


If Err <> 0 Then

  WScript.Echo "Windows Firewall Service is not running."

  WScript.Quit

End If


If objProfile.FirewallEnabled = True Then

  WScript.Echo "Windows Firewall is enabled."

Else

  WScript.Echo "Windows Firewall is disabled."

End If




:
Posted by 커널64

Const DOMAIN_PROFILE = 1

Const PRIVATE_PROFILE = 2

Const PUBLIC_PROFILE = 4


Set fwPolicy2 = CreateObject("HNetCfg.FwPolicy2")


CurrentProfile = fwPolicy2.CurrentProfileTypes

Select Case CurrentProfile

  Case DOMAIN_PROFILE

    WScript.Echo "현재 프로필: 도메인"

  Case PRIVATE_PROFILE

    WScript.Echo "현재 프로필: 개인"

  Case PUBLIC_PROFILE

    WScript.Echo "현재 프로필: 공용"

End Select


WScript.Echo "==================="


If fwPolicy2.FirewallEnabled(DOMAIN_PROFILE) = TRUE Then

  WScript.Echo "도메인 프로필: 사용"

Else

  WScript.Echo "도메인 프로필: 사용 안 함"

End If


If fwPolicy2.FirewallEnabled(PRIVATE_PROFILE) = TRUE Then

  WScript.Echo "개인 프로필: 사용"

Else

  WScript.Echo "개인 프로필: 사용 안 함"

End If


If fwPolicy2.FirewallEnabled(PUBLIC_PROFILE) = TRUE Then

  WScript.Echo "공용 프로필: 사용"

Else

  WScript.Echo "공용 프로필: 사용 안 함"

End If


Set fwPolicy2 = NOTHING




:
Posted by 커널64
2015. 1. 8. 11:07

VBS - Windows 업데이트 설정 쿼리 Etc.2015. 1. 8. 11:07

Set objAutoUpdate = CreateObject("Microsoft.Update.AutoUpdate")

Set objSettings = objAutoUpdate.Settings


WUSetting = objSettings.NotificationLevel


Set objSettings = NOTHING

Set objAutoUpdate = NOTHING


Select Case WUSetting

  Case 1

    strSetting = "업데이트를 확인하지 않음"

    strState = "GOOD"

  Case 2

    strSetting = "업데이트를 확인하지만 다운로드 및 설치 여부는 직접 선택"

    strState = "GOOD"

  Case 3

    strSetting = "업데이트를 다운로드하지만 설치 여부는 직접 선택"

    strState = "GOOD"

  Case 4

    strSetting = "업데이트 자동 설치"

    strState = "BAD"

End Select



WScript.Echo strSetting

WScript.Echo strState





:
Posted by 커널64
제목과 같이 Azure, System Center, Windows Server에 대한 포스터가 나왔네요.
Microsoft의 전반적인 클라우드 기술들을 한 눈에 볼 수 있도록 잘 설명되어 있는 것 같습니다.

다운로드는 아래 링크에서 가능합니다.
http://www.microsoft.com/en-us/download/details.aspx?id=43718






:
Posted by 커널64
테스트 환경에 단독으로 운영 중인 Windows Server 2012 R2 기반의 Hyper-V 호스트 서버에서 가상 하드 디스크 공유 기능을 사용해 보려고 하는데 다음과 같이 오류가 발생하네요.

첨부 파일 'xxxx.vhdx'에 대한 정보를 가져올 수 없습니다.
가상 하드 디스크가 있는 저장소가 가상 하드디스크 공유를 지원하지 않습니다.


로컬 디스크에 대한 요구 사항(SCSI 영구 예약 등)이 맞지 않나... 하고 고민하던 중 다음과 같은 방법으로 해결하였습니다.

먼저, 명령 프롬프트에서 fltmc 명령을 입력해 보면 svhdxflt 필터가 목록에 없습니다.


이 필터를 설치하기 위해서는 장애 조치 클러스터링을 설치해야만 합니다. PowerShell을 실행한 후 다음 명령을 사용하거나 또는 서버 관리자 GUI를 통해 기능을 설치합니다.
Install-WindowsFeature Failover-Clustering -IncludeManagementTools


기능을 설치한 후 다시 fltmc 명령을 실행해 보면 svhdxflt 필터가 목록에 표시됨을 확인할 수 있습니다.


이제 해당 필터를 볼륨에 Attach 합니다. 명령은 다음과 같습니다.
fltmc attach svhdxflt <볼륨>


이제 다시 Hyper-V 관리자를 통해 가상 하드 디스크 공유 기능을 사용하면 정상적으로 설정됩니다.




 
:
Posted by 커널64