powershell
remote command 활성화
https://technet.microsoft.com/en-us/library/ff700227.aspx
get-service winrm
Start-Service winrm
get-service winrm
winrm s winrm/config/client '@{TrustedHosts="WIN-6S4NEPKTVUI"}'
winrm quickconfig
파일 / 새 원격 PowerShell 탭
인증 ...
PowerShell 책
http://www.reedbushey.com/86Windows%20Powershell%20Cookbook%203rd%20Edition.pdf
C# 으로 powershell 불러쓰기
https://blogs.msdn.microsoft.com/kebab/2014/04/28/executing-powershell-scripts-from-c/
sql parameter
http://sql-articles.com/articles/general/enable-disable-trace-flags-in-sql-server/
기본 쿼리
sql parameter 쿼리하기
[mon]: PS C:\Users\db\Documents> Get-ItemProperty -Path Registry::"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQLServer\Parameters"
파일 읽어서 반환하기
등등
using (PowerShell PowerShellInstance = PowerShell.Create())
{
string cmd = @"Get-Item -Path Registry::\'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server'";
PowerShellInstance.AddScript(cmd);
Console.WriteLine(cmd);
Collection<PSObject> PSOutput = PowerShellInstance.Invoke();
foreach (PSObject outputItem in PSOutput)
{
// if null object was dumped to the pipeline during the script then a null
// object may be present here. check for null to prevent potential NRE.
if (outputItem != null)
{
if (PowerShellInstance.Streams.Error.Count > 0)
{
Console.WriteLine("Error");
}
else
{
Console.WriteLine(outputItem.BaseObject.GetType().FullName);
Console.WriteLine(outputItem.BaseObject.ToString() + "\n");
if (outputItem.BaseObject is RegistryKey)
{
RegistryKey rk = outputItem.BaseObject as RegistryKey;
string[] valueNames = rk.GetValueNames();
foreach (string s in valueNames)
{
RegistryValueKind rvk = rk.GetValueKind(s);
switch (rvk)
{
case RegistryValueKind.MultiString:
string[] values = (string[])rk.GetValue(s);
Console.Write("\r\n {0} ({1}) =", s, rvk);
for (int i = 0; i < values.Length; i++)
{
if (i != 0) Console.Write(",");
Console.Write(" \"{0}\"", values[i]);
}
Console.WriteLine();
break;
case RegistryValueKind.Binary:
byte[] bytes = (byte[])rk.GetValue(s);
Console.Write("\r\n {0} ({1}) =", s, rvk);
for (int i = 0; i < bytes.Length; i++)
{
// Display each byte as two hexadecimal digits.
Console.Write(" {0:X2}", bytes[i]);
}
Console.WriteLine();
break;
default:
Console.WriteLine("\r\n {0} ({1}) = {2}", s, rvk, rk.GetValue(s));
break;
}
}
}
}
}
}
}