とあるエンジニアの技術記録

主にWindowsやLinuxの設定方法、トラブル解決方法について投稿してます~♪

PowerShellについて③

2016年11月30日 12時58分39秒 | WIN

こんにちわ。
今回もPowerShellコマンドについて記載していきます。

今日は以下2点です。
 ①IPv6を無効する
 ②iSCSIを構成する


①IPv6を無効するコマンド
 WindowsServer2012R2 ServerCoreにHyperVサービスをインストールしたホスト2台でフェイルオーバークラスター構成の検証を行った際、
IPv6に関する通信警告が表示されたため、以下がIPv6を無効にしました。その際使用したコマンドになります。

まず最初にGet-NetAdapterBindingというコマンドを使用して
そのホストにどのようなネットワークコンポーネントが設定されているか確認します。

 PS C:\> Get-NetAdapterBinding

 Name    DisplayName                                                      ComponentID        Enabled
 --------   -------                                                               -----------              -------
 Team01 Hyper-V 拡張可能仮想スイッチ                             vms_pp                False
 Team01 Link-Layer Topology Discovery Responder            ms_rspndr            True
 Team01 Link-Layer Topology Discovery Mapper I/O Driver  ms_lltdio             True
 Team01 Microsoft Network Adapter Multiplexor Protocol     ms_implat            False
 Team01 Microsoft ネットワーク用クライアント                      ms_msclient          True
 Team01 Microsoft MAC Bridge                                        ms_bridge             False
 Team01 Microsoft Load Balancing/Failover Provider           ms_lbfo               True
 Team01 QoS パケット スケジューラ                                   ms_pacer             True
 Team01 Microsoft ネットワーク用ファイルとプリンター共有    ms_server            True
 Team01 インターネット プロトコル バージョン 6 (TCP/IPv6)   ms_tcpip6             False
 Team01 インターネット プロトコル バージョン 4 (TCP/IPv4)    ms_tcpip              True


『ms_tcpip6』というコンポーネントをFalseにすればIPv6は無効になるため、
以下のコマンドを実行します。

 PS C:\> Disable-NetAdapterBinding -Name "Team01" -ComponentID ms_tcpip6


②ServerCoreOSでiSCSIを構成する
 フェイルオーバークラスタ環境を構築するためISCSIサーバを構築し、
WindowsServer2012R2 ServerCoreでiscsiの設定を行いましたが、設定はすべてPowershellコマンドになります。
その際使用したコマンドと設定の流れは以下の通りです。

 1.ServerCore上で停止しているiSCSIイニシエーターサービス(MSiSCSI)のスタートアップを自動起動に変更
  PS C:\> Set-Service msiscsi -startuptype automatic

 2.iSCSIイニシエーターサービスの開始
  PS C:\> Start-Service msiscsi

 3.iSCSIターゲットポータルの構成
  PS C:\> New-IscsitargetPortal -TargetPortalAddress xxx.xxx.xxx.xxx
   *ターゲットポータルアドレスはiSCSIストレージのIPアドレスを指定してください。

 4.iSCSIのストレージに接続
  PS C:\> Connect-IscsiTarget -NodeAddress "IQN" -TargetPortalAddress xxx.xxx.xxx.xxx -isPersistent $True
   *ノードアドレスはストレージのIQNを事前し指定してください。
 問題なく接続できると以下のように表示されます。
---------------------------------------------------------------------------
 AuthenticationType      : NONE
 InitiatorInstanceName   : ROOT\ISCSIPRT\0000_0
 InitiatorNodeAddress    : xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 InitiatorPortalAddress  : 0.0.0.0
 InitiatorSideIdentifier : 400001370000
 IsConnected             : True
 IsDataDigest            : False
 IsDiscovered            : True
 IsHeaderDigest          : False
 IsPersistent            : True
 NumberOfConnections     : 1
 SessionIdentifier       : ffffe00141339020-4000013700000002
 TargetNodeAddress       : xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 TargetSideIdentifier    : 0100
 PSComputerName          :
---------------------------------------------------------------------------

 5.WindowsServer2012R2GUIサーバのサーバーマネージャーにiSCSI設定を行ったServerCoreサーバを登録し、
 『コンピュータの管理』画面からiscsiストレージがマウントされているか確認します。
 マウントされていることを確認後
 ServerCoreサーバを再起動し自動マウントされるか確認してください。

また更新します。
以上です。


▼参考URL
「Windows Server 2012 ServerCore でiSCSIを構成する手順 」
http://blogs.yahoo.co.jp/fc3s_se/35196793.html

「Hyper-V Server 2012 R2 セットアップ - IPv6を無効にするには?」
http://seagull.teak.jp/adiary3/0173

「Windows Server 2012R2 Server Core で IPv6を無効にする」
http://takayuki.frontside.jp/?p=262


PowerShellについて②

2016年11月18日 21時30分54秒 | WIN

こんにちわ。

今回もPowerShellコマンドについて記載していきます。

今回は以下2点です。
 ①検索結果の件数をカウント
 ②ADサーバに登録しているユーザの情報表示(最後にログオンした時刻等を表示)

①検索結果の件数をカウント
あまり使う機会は無いかもしれませんが、
『()』と『.Count』を付けることで件数を取得できます
たとえばHyper-Vに関するモジュールが何個組み込まれているかを確認することとができます。

▼Hyper-Vモジュールを場合
 PS C:\> (Get-Command -Module Hyper-V).Count
 178

▼iscsiモジュールを場合
 PS C:\> (Get-Command -Module iscsi).Count
 13

『()』と『.Count』を付けなければ以下のように表示されます。
 PS C:\> Get-Command -Module iscsi
 CommandType     Name                                               ModuleName
 -----------     ----                                               ----------
 Function        Connect-IscsiTarget                                iSCSI
 Function        Disconnect-IscsiTarget                             iSCSI
 Function        Get-IscsiConnection                                iSCSI
 Function        Get-IscsiSession                                   iSCSI
 Function        Get-IscsiTarget                                    iSCSI
 Function        Get-IscsiTargetPortal                              iSCSI
 Function        New-IscsiTargetPortal                              iSCSI
 Function        Register-IscsiSession                              iSCSI
 Function        Remove-IscsiTargetPortal                           iSCSI
 Function        Set-IscsiChapSecret                                iSCSI
 Function        Unregister-IscsiSession                            iSCSI
 Function        Update-IscsiTarget                                 iSCSI
 Function        Update-IscsiTargetPortal                           iSCSI
 PS C:\>


②ADサーバに登録しているユーザの情報表示(最後にログオンした時刻等を表示)
以下のコマンドを実行すると最後にログオンした時刻が表示されます。

 PS C:\> Get-ADUser -Properties * -Filter * | fl name, lastLogonDate | more
 name          : Administrator
 lastLogonDate : 2016/11/14 7:04:05


以上。

▼参考資料
「PowerShellで検索文字列をカウントしてみよう」
http://excel.wp.xdomain.jp/?p=149

「PowerShell でのユーザーの取得・検索」
https://adtan.wordpress.com/2011/12/16/powershell-%E3%81%A7%E3%81%AE%E3%83%A6%E3%83%BC

%E3%82%B6%E3%83%BC%E3%81%AE%E5%8F%96%E5%BE%97/

「Format-List コマンドレットの使用」
https://technet.microsoft.com/ja-jp/library/ee176830.aspx


PowerShellについて①

2016年11月11日 20時51分30秒 | WIN

こんにちわ。
まだ11月なのに連日12月上旬の気温らしく寒いとぶつぶつ言いながら出勤しております、、
(毎日寒ければ慣れてくるので平気ですが寒暖差があるこの時期がとても苦手です、、)

本題になりますが、いまさらですが、、
ServerCoreを設定することが増えそれに伴いPowerShellコマンドも入力する機会が増えてきました、、、
WindowsServer2012 R2 ServerCore上で使用している設定やコマンド等を記載していきます。
 *ServerCoreに関してはかなり初心者です、、ほぼ初歩的な内容になります。

今回は以下3点です。
 ①Powershellの起動
 ②FWの設定変更
 ③ネットワークの種別(NetworkCategory)を変更する方法

①Powershellの起動
まずそもそもPowershell起動方法すらわからなかったため、
コマンドプロンプト画面で「powershell」と入力すると以下のようなプロンプトになり、Powershellが起動します。

 C:\>powershell
 Windows PowerShell
 Copyright (C) 2014 Microsoft Corporation. All rights reserved.

 PS C:\>

powershellを停止する場合は「exit」と入力します。
 PS C:> exit

 C:\>


②FWの設定変更
次にServerCoreのFWをオフにする設定ですが、
sconfigコマンドでは変更できなかったためPowershellを使用した無効化設定コマンドを行います。

 PS C:>Get-NetFirewallProfile | Set-NetFirewallProfile -Enabled false

有効化設定コマンドは以下の通りです。

 PS C:>Get-NetFirewallProfile | Set-NetFirewallProfile -Enabled true


③ネットワークの種別(NetworkCategory)を変更する方法
最後にWindows Server 2012 R2でネットワークの種別(NetworkCategory)を変更する方法について記載します。

 ▼プライベートに変更する場合
 PS C:>Get-NetConnectionProfile | where Name -eq "<ネットワーク名>" | Set-NetConnectionProfile -NetworkCategory Private

 ▼パブリックに変更する場合
 PS C:>Get-NetConnectionProfile | where Name -eq "<ネットワーク名>" | Set-NetConnectionProfile -NetworkCategory Public


また更新します。
以上です。

▼参考資料
「Server CoreモードでのFirewallの無効化」
http://blog.o365mvp.com/2012/11/13/server-core%E3%83%A2%E3%83%BC%E3%83%89%E3%81%A7%E3%81%AEfirewall%E3%81%AE%E7%84%A1%E5%8A%B9%E5%8C%96/

「Windows Server 2012 R2でネットワークの種別(NetworkCategory)を変更する方法 」
http://kiyokura.hateblo.jp/entry/2014/03/09/154551