【PoweShell】Get-Comandでコマンドレットを絞り込む

結論から言うと2通りあります

ここではこれらを取得する方法とその構成を説明します
コマンドレットのContentに注目します

PowerShellでは特に指定しない限りコマンド中の大文字小文字は区別されません

もっとも簡単な方法

コマンド

>gcm -noun content
  • 短縮コマンドの説明
短縮名 コマンドレット 説明
gcm Get-Command コマンドレットの情報を取得する

結果

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Cmdlet          Add-Content                                        7.0.0.0    Microsoft.PowerShell.Management
Cmdlet          Clear-Content                                      7.0.0.0    Microsoft.PowerShell.Management
Cmdlet          Get-Content                                        7.0.0.0    Microsoft.PowerShell.Management
Cmdlet          Set-Content                                        7.0.0.0    Microsoft.PowerShell.Management

表示をスマートに

コマンド

>gcm -noun contnt | select name,version

結果

Name          Version
----          -------
Add-Content   7.0.0.0
Clear-Content 7.0.0.0
Get-Content   7.0.0.0
Set-Content   7.0.0.0

他の方法

コマンド

>gcm | ?{$_.noun -eq "content"} | select name,version

結果

Name          Version
----          -------
Add-Content   7.0.0.0
Clear-Content 7.0.0.0
Get-Content   7.0.0.0
Set-Content   7.0.0.0

コマンド

>gcm | ?{$_.name -like "*content"} | select name,version
>gcm | ?{$_.commandtype -eq "cmdlet" -and $_.name -like "*content"} | select name,version

結果

Name                    Version
----                    -------
Add-Content             7.0.0.0
Clear-Content           7.0.0.0
Get-Content             7.0.0.0
Get-WindowsImageContent 3.0
Set-Content             7.0.0.0
  • 短縮コマンドの説明
短縮名 コマンドレット 説明
? Where-Object オブジェクトを列挙する
select Select-Object オブジェクトプロパティを選択する

正式なコマンドレット名に展開すると上の2つのコマンドは次のようになります

>Get-Command | Where-Object{$PSItem.Noun -eq "Content"} | Select-Object Name,Version
>Get-Command | Where-Object{$PSItem.Name -like "*Content"} | Select-Object name,version

フィルタに使えるメンバー名(表タイトル)

  • 短縮コマンドの説明
短縮名 コマンドレット 説明
gm Get-Member メンバーの情報を取得する

コマンド

>gcm | gm

結果

   TypeName: System.Management.Automation.AliasInfo

Name                MemberType     Definition
----                ----------     ----------
Equals              Method         bool Equals(System.Object obj)
GetHashCode         Method         int GetHashCode()
GetType             Method         type GetType()
ResolveParameter    Method         System.Management.Automation.ParameterMetadata ResolveParameter(string name)
ToString            Method         string ToString()
CommandType         Property       System.Management.Automation.CommandTypes CommandType {get;}
Definition          Property       string Definition {get;}
Description         Property       string Description {get;set;}
Module              Property       psmoduleinfo Module {get;}
ModuleName          Property       string ModuleName {get;}
Name                Property       string Name {get;}
Options             Property       System.Management.Automation.ScopedItemOptions Options {get;set;}
OutputType          Property       System.Collections.ObjectModel.ReadOnlyCollection[System.Management.Automation.PSTy…
Parameters          Property       System.Collections.Generic.Dictionary[string,System.Management.Automation.Parameter…
ParameterSets       Property       System.Collections.ObjectModel.ReadOnlyCollection[System.Management.Automation.Comm…
ReferencedCommand   Property       System.Management.Automation.CommandInfo ReferencedCommand {get;}
RemotingCapability  Property       System.Management.Automation.RemotingCapability RemotingCapability {get;}
ResolvedCommand     Property       System.Management.Automation.CommandInfo ResolvedCommand {get;}
Source              Property       string Source {get;}
Version             Property       version Version {get;}
Visibility          Property       System.Management.Automation.SessionStateEntryVisibility Visibility {get;set;}
DisplayName         ScriptProperty System.Object DisplayName {get=if ($this.Name.IndexOf('-') -lt 0)…
HelpUri             ScriptProperty System.Object HelpUri {get=$oldProgressPreference = $ProgressPreference…
ResolvedCommandName ScriptProperty System.Object ResolvedCommandName {get=$this.ResolvedCommand.Name;}

   TypeName: System.Management.Automation.FunctionInfo

Name                MemberType     Definition
----                ----------     ----------
Equals              Method         bool Equals(System.Object obj)
GetHashCode         Method         int GetHashCode()
GetType             Method         type GetType()
ResolveParameter    Method         System.Management.Automation.ParameterMetadata ResolveParameter(string name)
ToString            Method         string ToString()
CmdletBinding       Property       bool CmdletBinding {get;}
CommandType         Property       System.Management.Automation.CommandTypes CommandType {get;}
DefaultParameterSet Property       string DefaultParameterSet {get;}
Definition          Property       string Definition {get;}
Description         Property       string Description {get;set;}
HelpFile            Property       string HelpFile {get;}
Module              Property       psmoduleinfo Module {get;}
ModuleName          Property       string ModuleName {get;}
Name                Property       string Name {get;}
Noun                Property       string Noun {get;}
Options             Property       System.Management.Automation.ScopedItemOptions Options {get;set;}
OutputType          Property       System.Collections.ObjectModel.ReadOnlyCollection[System.Management.Automation.PSTy…
Parameters          Property       System.Collections.Generic.Dictionary[string,System.Management.Automation.Parameter…
ParameterSets       Property       System.Collections.ObjectModel.ReadOnlyCollection[System.Management.Automation.Comm…
RemotingCapability  Property       System.Management.Automation.RemotingCapability RemotingCapability {get;}
ScriptBlock         Property       scriptblock ScriptBlock {get;}
Source              Property       string Source {get;}
Verb                Property       string Verb {get;}
Version             Property       version Version {get;}
Visibility          Property       System.Management.Automation.SessionStateEntryVisibility Visibility {get;set;}
HelpUri             ScriptProperty System.Object HelpUri {get=$oldProgressPreference = $ProgressPreference…

   TypeName: System.Management.Automation.CmdletInfo

Name                MemberType     Definition
----                ----------     ----------
Equals              Method         bool Equals(System.Object obj)
GetHashCode         Method         int GetHashCode()
GetType             Method         type GetType()
ResolveParameter    Method         System.Management.Automation.ParameterMetadata ResolveParameter(string name)
ToString            Method         string ToString()
CommandType         Property       System.Management.Automation.CommandTypes CommandType {get;}
DefaultParameterSet Property       string DefaultParameterSet {get;}
Definition          Property       string Definition {get;}
HelpFile            Property       string HelpFile {get;}
ImplementingType    Property       type ImplementingType {get;}
Module              Property       psmoduleinfo Module {get;}
ModuleName          Property       string ModuleName {get;}
Name                Property       string Name {get;}
Noun                Property       string Noun {get;}
Options             Property       System.Management.Automation.ScopedItemOptions Options {get;set;}
OutputType          Property       System.Collections.ObjectModel.ReadOnlyCollection[System.Management.Automation.PSTy…
Parameters          Property       System.Collections.Generic.Dictionary[string,System.Management.Automation.Parameter…
ParameterSets       Property       System.Collections.ObjectModel.ReadOnlyCollection[System.Management.Automation.Comm…
PSSnapIn            Property       System.Management.Automation.PSSnapInInfo PSSnapIn {get;}
RemotingCapability  Property       System.Management.Automation.RemotingCapability RemotingCapability {get;}
Source              Property       string Source {get;}
Verb                Property       string Verb {get;}
Version             Property       version Version {get;}
Visibility          Property       System.Management.Automation.SessionStateEntryVisibility Visibility {get;set;}
DLL                 ScriptProperty System.Object DLL {get=$this.ImplementingType.Assembly.Location;}
HelpUri             ScriptProperty System.Object HelpUri {get=$oldProgressPreference = $ProgressPreference…

上の方法では余分な情報があるのでCmdletInfoに絞り込みます
コマンド

>gcm|gm|?{$_.typename -eq "system.management.automation.cmdletinfo"}
>gcm|gm|?{$_.typename -like "*cmdletinfo"}

結果

   TypeName: System.Management.Automation.CmdletInfo

Name                MemberType     Definition
----                ----------     ----------
Equals              Method         bool Equals(System.Object obj)
GetHashCode         Method         int GetHashCode()
GetType             Method         type GetType()
ResolveParameter    Method         System.Management.Automation.ParameterMetadata ResolveParameter(string name)
ToString            Method         string ToString()
CommandType         Property       System.Management.Automation.CommandTypes CommandType {get;}
DefaultParameterSet Property       string DefaultParameterSet {get;}
Definition          Property       string Definition {get;}
HelpFile            Property       string HelpFile {get;}
ImplementingType    Property       type ImplementingType {get;}
Module              Property       psmoduleinfo Module {get;}
ModuleName          Property       string ModuleName {get;}
Name                Property       string Name {get;}
Noun                Property       string Noun {get;}
Options             Property       System.Management.Automation.ScopedItemOptions Options {get;set;}
OutputType          Property       System.Collections.ObjectModel.ReadOnlyCollection[System.Management.Automation.PSTy…
Parameters          Property       System.Collections.Generic.Dictionary[string,System.Management.Automation.Parameter…
ParameterSets       Property       System.Collections.ObjectModel.ReadOnlyCollection[System.Management.Automation.Comm…
PSSnapIn            Property       System.Management.Automation.PSSnapInInfo PSSnapIn {get;}
RemotingCapability  Property       System.Management.Automation.RemotingCapability RemotingCapability {get;}
Source              Property       string Source {get;}
Verb                Property       string Verb {get;}
Version             Property       version Version {get;}
Visibility          Property       System.Management.Automation.SessionStateEntryVisibility Visibility {get;set;}
DLL                 ScriptProperty System.Object DLL {get=$this.ImplementingType.Assembly.Location;}
HelpUri             ScriptProperty System.Object HelpUri {get=$oldProgressPreference = $ProgressPreference…

先のコマンドではDifinitionの一部が省略されて表示されてます
これらを折り返して表示するには次のようにします
コマンド

>gcm|gm|?{$_.typename -eq "system.management.automation.cmdletinfo"} | ft -wrap
  • 短縮コマンドの説明
短縮名 コマンドレット 説明
ft Format-Table 出力の列内の表示変更

結果

   TypeName: System.Management.Automation.CmdletInfo

Name                MemberType     Definition
----                ----------     ----------
Equals              Method         bool Equals(System.Object obj)
GetHashCode         Method         int GetHashCode()
GetType             Method         type GetType()
ResolveParameter    Method         System.Management.Automation.ParameterMetadata ResolveParameter(string name)
ToString            Method         string ToString()
CommandType         Property       System.Management.Automation.CommandTypes CommandType {get;}
DefaultParameterSet Property       string DefaultParameterSet {get;}
Definition          Property       string Definition {get;}
HelpFile            Property       string HelpFile {get;}
ImplementingType    Property       type ImplementingType {get;}
Module              Property       psmoduleinfo Module {get;}
ModuleName          Property       string ModuleName {get;}
Name                Property       string Name {get;}
Noun                Property       string Noun {get;}
Options             Property       System.Management.Automation.ScopedItemOptions Options {get;set;}
OutputType          Property       System.Collections.ObjectModel.ReadOnlyCollection[System.Management.Automation.PSTyp
                                   eName] OutputType {get;}
Parameters          Property       System.Collections.Generic.Dictionary[string,System.Management.Automation.ParameterM
                                   etadata] Parameters {get;}
ParameterSets       Property       System.Collections.ObjectModel.ReadOnlyCollection[System.Management.Automation.Comma
                                   ndParameterSetInfo] ParameterSets {get;}
PSSnapIn            Property       System.Management.Automation.PSSnapInInfo PSSnapIn {get;}
RemotingCapability  Property       System.Management.Automation.RemotingCapability RemotingCapability {get;}
Source              Property       string Source {get;}
Verb                Property       string Verb {get;}
Version             Property       version Version {get;}
Visibility          Property       System.Management.Automation.SessionStateEntryVisibility Visibility {get;set;}
DLL                 ScriptProperty System.Object DLL {get=$this.ImplementingType.Assembly.Location;}
HelpUri             ScriptProperty System.Object HelpUri {get=$oldProgressPreference = $ProgressPreference
                                             $ProgressPreference = 'SilentlyContinue'
                                             try
                                             {
                                             [Microsoft.PowerShell.Commands.GetHelpCodeMethods]::GetHelpUri($this)
                                             }
                                             catch {}
                                             finally
                                             {
                                             $ProgressPreference = $oldProgressPreference
                                             };}

もっと詳しく

次のコマンドではGet-Contentのメンバー(タイトル)とその中身を表示します
コマンド

>gcm | ?{$_.name -eq "get-content"} | select *

結果

HelpUri             : https://go.microsoft.com/fwlink/?LinkID=2096490
DLL                 : C:\Program Files\PowerShell\7\Microsoft.PowerShell.Commands.Management.dll
Verb                : Get
Noun                : Content
HelpFile            : Microsoft.PowerShell.Commands.Management.dll-Help.xml
PSSnapIn            :
Version             : 7.0.0.0
ImplementingType    : Microsoft.PowerShell.Commands.GetContentCommand
Definition          :
                      Get-Content [-Path] <string[]> [-ReadCount <long>] [-TotalCount <long>] [-Tail <int>] [-Filter <s
                      tring>] [-Include <string[]>] [-Exclude <string[]>] [-Force] [-Credential <pscredential>] [-Delim
                      iter <string>] [-Wait] [-Raw] [-Encoding <Encoding>] [-AsByteStream] [-Stream <string>] [<CommonP
                      arameters>]

                      Get-Content -LiteralPath <string[]> [-ReadCount <long>] [-TotalCount <long>] [-Tail <int>] [-Filt
                      er <string>] [-Include <string[]>] [-Exclude <string[]>] [-Force] [-Credential <pscredential>] [-
                      Delimiter <string>] [-Wait] [-Raw] [-Encoding <Encoding>] [-AsByteStream] [-Stream <string>] [<Co
                      mmonParameters>]

DefaultParameterSet : Path
OutputType          : {System.Byte, System.String}
Options             : ReadOnly
Name                : Get-Content
CommandType         : Cmdlet
Source              : Microsoft.PowerShell.Management
Visibility          : Public
ModuleName          : Microsoft.PowerShell.Management
Module              : Microsoft.PowerShell.Management
RemotingCapability  : PowerShell
Parameters          : {[ReadCount, System.Management.Automation.ParameterMetadata], [TotalCount, System.Management.Auto
                      mation.ParameterMetadata], [Tail, System.Management.Automation.ParameterMetadata], [Path, System.
                      Management.Automation.ParameterMetadata]…}
ParameterSets       : {[-Path] <string[]> [-ReadCount <long>] [-TotalCount <long>] [-Tail <int>] [-Filter <string>] [-I
                      nclude <string[]>] [-Exclude <string[]>] [-Force] [-Credential <pscredential>] [-Delimiter <strin
                      g>] [-Wait] [-Raw] [-Encoding <Encoding>] [-AsByteStream] [-Stream <string>] [<CommonParameters>]
                      , -LiteralPath <string[]> [-ReadCount <long>] [-TotalCount <long>] [-Tail <int>] [-Filter <string
                      >] [-Include <string[]>] [-Exclude <string[]>] [-Force] [-Credential <pscredential>] [-Delimiter
                      <string>] [-Wait] [-Raw] [-Encoding <Encoding>] [-AsByteStream] [-Stream <string>] [<CommonParame
                      ters>]}

これらの情報を見るとコマンドレット名[Name]はメンバー[Verb(動詞)]とメンバー[Noun(名詞)]の組み合わせであることが判ります
従ってメンバー[Noun]でフィルタすると使用可能な動詞[Verb]の一覧が得られます
これで最初のフィルタするコマンドが理解できたと思います
このフィルタリング手法はGet-Commandの他にGet-ChildItem、Get-Service、Get-Processなどまたファンクションですがよく使うGet-NetIPAddressなどでも応用可能です

Contentについて

  • 短縮コマンドの説明
短縮名 コマンドレット 説明
catGet-Content指定された場所にあるアイテムのコンテンツを取得します
基本的にファイルの内容を取得します
gc
type
ac Add-Content ファイルに追記します
clc Clear-Content ファイルの内容をクリアします
sc Set-Content ファイルに新たに内容を書き込みます
※PowerShell7以降ではこの短縮名は使えません

他にもいくつか注意点があります
次のサイトを参照してください
tech.guitarrapc.com
ファイル書き込み時にはOut-Fileを使うことも考慮してください
またファイル書き込みにはリダイレクト「>や>>」もあるので必要に応じて使い分けるのが良いでしょう
www.itlab51.com

重要追記

紹介した上記サイトに書かれている「デフォルトエンコーディングの違い」についてですがPowerShell7[pwsh]では仕様が変わったようです
結論から言うとpwshではOut-File,Set-Content,リダイレクト(>,>>)で全てASCIIとして出力されるようになったようです
PowerShell[powershell]でも確認しましたが、この場合はエンコーディングが違うことを確認しました
Set-ContentのみASCII
これらに注意してください

【ImageMagic】一括処理でJpeg画像から丸窓化(Ping画像)するBatchプログラム【Windows】

環境

OS:Windows
ImageMagic7以降

注意

ファイル名に半角スペースが含まれている場合エラーになります
作成したバッチファイルは画像のあるフォルダに入れて実行してください
トリミングした画像はPNG画像になります

変数preにはファイル前置詞を指定できます

CircleConv.bat

@echo off
setlocal enabledelayedexpansion
set pre=_
type nul > list.txt
for %%i in (*.jpg) do (
    magick identify "%%i" >> list.txt
)
for /f "tokens=1,3" %%a in (list.txt) do (
    for /f "tokens=1,2 delims=x" %%x in ("%%b") do (
        set /a cx=%%x/2
        set /a cy=%%y/2
        if /i %%x gtr %%y (
            set top=0
            set left=!cx!
            set harfx=0
            set /a harfy=%%y/2
            set size=%%y
            set /a cutleft=%%x-!size!
            set /a cutleft=!cutleft!/2
            set cuttop=0
        ) else (
            set top=!cy!
            set left=0
            set /a harfx=%%x/2
            set harfy=0
            set size=%%x
            set cutleft=0
            set /a cuttop=%%y-!size!
            set /a cuttop=!cuttop!/2
        )
        set /a harf=!size!/2
        magick -size !size!x!size! xc:none -draw "circle !harf!,!harf! !harfx!,!harfy!" _mask_%%a.png
        magick %%a -crop "!size!x!size!+!cutleft!+!cuttop!"  _ex_%%a.png
        magick _ex_%%a.png _mask_%%a.png -compose CopyOpacity -composite %pre%%%%a.png
        del _ex_%%a.png
        del _mask_%%a.png
    )
)
del list.txt

SQLServerのインストールと郵便番号データのインポート

ファイヤーウォールのポート開放

コントロールパネルでファイアーウォールを検索
WindowsDefenderファイアウォールの詳細設定を表示
新しい規則で次のポートを開放
TCP 1433
UDP 1434
規則の名前はMSSqlserverとでもしておく

■SQLServer2017のインストール

コンピューターの管理のサービスとアプリケーションで
SQL構成マネージャーのネットワーク構成でプロトコルの名前付きパイプを有効にする
(ネットワーク越しに使用する場合はTCP/IPも有効にする)

■郵便局のページ

http://www.post.japanpost.jp/zipcode/download.html
から必要な郵便番号データをダウンロードする
(読み仮名データの促音・拗音を小書きで表記するものの全国一括)
ken_all.zipを解凍し別名KEN_ALL(更新日付とか).CSVにする

■MSSMSでデータベースを作成

ここではKEN_ALL

■MSSMSでテーブルを作成(テーブル名もKEN_ALL)

USE [KEN_ALL]
GO
/****** Object:  Table [dbo].[KEN_ALL]    Script Date: 2018/03/18 13:31:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[KEN_ALL](
 [cord] [varchar](100) NULL,
 [zip5] [varchar](100) NULL,
 [zip] [varchar](100) NULL,
 [todofukenkana] [varchar](100) NULL,
 [sikuchosonkana] [varchar](100) NULL,
 [choikikana] [varchar](100) NULL,
 [todofuken] [varchar](100) NULL,
 [sikuchoson] [varchar](100) NULL,
 [choiki] [varchar](100) NULL,
 [a] [varchar](1) NULL,
 [b] [varchar](1) NULL,
 [c] [varchar](1) NULL,
 [d] [varchar](1) NULL,
 [e] [varchar](1) NULL,
 [f] [varchar](1) NULL
) ON [PRIMARY]
GO

■管理者権限のコマンドプロンプトBCPでKEN_ALL(更新日付とか).CSVインポートする

>bcp KEN_ALL in c:\フォルダーパス\KEN_ALL().CSV -S <Server Name> -d KEN_ALL -U <Username> -P <password> -q -c -t,

コマンドオプションの説明

  • S サーバー名を指定します。省略した場合、既定のサーバーになります。
  • T 統合認証を使ってログインします。この場合ユーザー名、パスワードは必要ありません。
  • q 空白や単一引用符を含むデータベース名を指定するには、-q オプションを使用する必要があります。
  • c 文字データ型を使用して操作を実行します。 このオプションを使用すると、フィールドごとにプロンプトが表示されません。 char をプレフィックスなしのストレージ型として、また \t (タブ) をフィールド区切り文字、 \r\n (改行文字) を行ターミネータとして使用します。 -c は -w と互換性がありません。
  • t フィールド ターミネータを指定します。 既定値は \t (タブ文字) です。 既定のフィールド ターミネータを無効にする場合、このパラメーターを使用します。 詳細については、「フィールド ターミネータと行ターミネータの指定 (SQL Server)」をご覧ください。

bcp.exe コマンドでは、フィールド ターミネータを 16 進数表記で指定すると、値が 0x00 で切り捨てられます。 たとえば、0x410041 を指定した場合、使用されるのは 0x41 になります。
field_term がハイフン (-) またはスラッシュ (/) で始まる場合は、 -t と field_term 値の間に空白を入れないでください。

■sqlcmdで確認する

>sqlcmd -S <Server Name> -d KEN_ALL -U <Username> -P <Password> -Q "select + from KEN_ALL;"

SQLServer2017に PubsとNorthWindデータベースのインストール

■解凍してinstnwnd.sqlとinstpubs.sqlの一部を書き換える

(C:\SQL Server 2000 Sample Databasesに解凍)

○instnwnd.sql

/*
exec sp_dboption 'Northwind','trunc. log on chkpt.','true'
exec sp_dboption 'Northwind','select into/bulkcopy','true'
*/
alter database Northwind set recovery simple

○instpubs.sql

/*
execute sp_dboption 'pubs' ,'trunc. log on chkpt.' ,'true'
*/
alter database pubs  set recovery simple

■sqlcmdでデータベースをインストールする

BATファイルを作って実行する

Windows認証の場合

@echo off
cd C:\SQL Server 2000 Sample Databases
sqlcmd -S (コンピューター名)\(インスタンス名) -i instpubs.sql
sqlcmd -S (コンピューター名)\(インスタンス名) -i instnwnd.sql

SQL Server認証の場合

@echo off
cd C:\SQL Server 2000 Sample Databases
sqlcmd -S (コンピューター名)\(インスタンス名) -U (ユーザ名) -P (パスワード) -i instpubs.sql
sqlcmd -S (コンピューター名)\(インスタンス名) -U (ユーザ名) -P (パスワード) -i instnwnd.sql

コンピューター名は標準ならHOME、そのあと\を挟んでインスタンス名を入れます
(ここではSQLExpressになってます)

■作ったBATファイルをコマンドプロンプトで実行する

■データベースができたか確認する

コマンドプロンプトに次のコマンドを実行する

sqlcmd -S (コンピューター名)\(インスタンス名) -U (ユーザ名) -P (パスワード) -Q "select name,create_date from sys.databases;"

一覧の中にpubsとNorthwindがあれば成功です

【R言語】 RODBCパッケージを使ったSQLServer接続

■RODBCパッケージをインストール

しかし、RGuiのパッケージメニューからインストールしたほうが良い感じ(ヘルプなどがインストールされる)

> install.packages("RODBC")

■インストールされたかを確認する

> library()

※コンソールとは別にウィンドウが開き一覧が表示される

■RODBCを使うことを宣言

> library(RODBC)

ODBCデータソースを使う場合

> db=odbcConnect("SQLServerHOME")
> ds=sqlQuery(db,"select top 100 * from dbo.R_PackageList")
> ds

※データソースを作るにはコントロールパネル→システムとセキュリティ→管理ツールを選択
 ODBCデータソースをダブルクリックしてODBCデータソースアドミニストレーターを表示
 ユーザーDNSで追加してドライバーを選択(SQLServer)して完了を押す
 データソースの作成になるので任意のデータソース名と接続するSQLServerを選択(説明は省略可)

ODBCドライバーで直接接続する場合(既定のデータベース、Windows認証で接続)

> db<- odbcDriverConnect('driver={SQL Server};server=HOME;database=R;trusted_connection=true')
> db
RODBC Connection 3
Details:
  case=nochange
  DRIVER=SQL Server
  SERVER=HOME
  UID=owner
  Trusted_Connection=Yes
  WSID=HOME
  DATABASE=R
> ds=sqlQuery(db,"select top 100 * from dbo.R_PackageList")
> ds

ODBCドライバーで直接接続する場合(インスタンス名付きのデータベース、Windows認証で接続)

>  db<- odbcDriverConnect('driver={SQL Server};server=HOME\\MSSQLSERVER2017;database=KEN_ALL;trusted_connection=true')
> db
RODBC Connection 8
Details:
  case=nochange
  DRIVER=SQL Server
  SERVER=HOME\MSSQLSERVER2017
  UID=owner
  Trusted_Connection=Yes
  WSID=HOME
  DATABASE=KEN_ALL
> ds=sqlQuery(db,"select top 100 * from dbo.KEN_ALL")

ODBCドライバーで直接接続する場合(SQLServer認証)

> db<- odbcDriverConnect('driver={SQL Server};server=HOME\\MSSQLSERVER2017;database=KEN_ALL;UID=sa;PWD=パスワード')
> db
RODBC Connection 9
Details:
  case=nochange
  DRIVER=SQL Server
  SERVER=HOME\MSSQLSERVER2017
  UID=sa
  PWD=******
  WSID=HOME
  DATABASE=KEN_ALL

インスタンス付きサーバー名を指定する場合、\\で接続する必要がある(通常は\一つ)。
 これはR Consoleの"\"を表現する場合には"\\"にしなければならない規定がある
 ファイルパスの接続文字でも同様の事が言える
 C:\temp\test.xlsを指定する場合にはC:/temp/test.xlsとするかC:\\temp\\test.xlsとしなければならない

■その他AccessExcelに接続する場合

odbcConnectAccess(access.file, uid = "", pwd = "", ...)
odbcConnectAccess2007(access.file, uid = "", pwd = "", ...)
odbcConnectExcel(xls.file, readOnly = TRUE, ...)
odbcConnectExcel2007(xls.file, readOnly = TRUE, ...)

■パッケージのアンロード

> detach("package:RODBC")

■パッケージのアンインストール

> remove.pakages("RODBC")

※再インストールするにはRGuiを再起動する必要がある

【Visual Basic】タブレットモードのタッチキーパッド(TabTip)のコントロール

■TabTip起動時

Process.Start("c:\program files\common files\microsoft shared\ink\tabtip.exe")

■TabTipを閉じる時

'宣言

Const WM_SYSCOMMAND As Integer = &H112
Const SC_CLOSE As Integer = &HF060
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Declare Function PostMessage Lib "user32.dll" Alias "PostMessageA" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As IntPtr) As IntPtr

'閉じたいイベントで

Dim hWnd As IntPtr = FindWindow("IPTip_Main_Window", vbNullString)
If hWnd <> IntPtr.Zero Then PostMessage(hWnd, WM_SYSCOMMAND, SC_CLOSE, 0)

XAMPP WebアプリケーションDrupalインストール時の注意

XAMPPをWindows付属のIISと共存させるにはApacheのhttp.confのListen 80→Listen 8080、ServerName localhost:80→ServerName localhost:8080に変更する。
ApacheのWebサーバーを呼び出すURLはhttp:localhost:8080になる。

開発環境

WebSever統合アプリケーション

〇XAMMP for Windows7.2.3
C:\XAMPP\xampp-control.exe3.2.2.0
https://www.apachefriends.org/jp/index.html
◆Webサーバー
Apache 2.4.34
C:\xampp\apache\bin\httpd.exe2.4.34
◆データベースサーバー
MariaDB(MySQL)10.1.36
C:\xampp\mysql\bin\mysql.exe10.1.36
CGI(Common gatewayInterface)
PHP 7.2.10
C:\xampp\php\php.exe7.2.10
Perl 8.38 2015-11-23
C:\xampp\perl\bin\perl5.16.3.exe
Tomcat 1.0.15.0
C:\xampp\tomcat\bin\tomcat7w.exe1.0.15.0
Apach付属のJSP(JavaServerPages)サーブレット[Java Servlet]
〇Drupal8.6.1
https://www.drupal.org/download
Drupalのインストールには時間がかかる為、既定のPHP実行制限時間では足りないので次の設定を変更する。C:\xampp\php\php.iniのmax_execution_time=30→max_execution_time=300に変更しておく。
ApacheWebサーバーのphpMyAdminにアクセスし空のDrupal用データベースを作成する。
Drupalをインストールしたフォルダにブラウザからアクセスする。インストールが始まるので指示される手順に沿って行う。インストールには30分前後かかる。