qshinoの日記

Powershell関係と徒然なこと

powershell

IISアクセス権限 by Powershell

Powershellによるアクセス権限設定 Add-WebConfiguration "/system.ftpServer/security/authorization" -value @{accessType="Allow";users="?";permissions=3} -PSPath IIS:\ -location FTPFolder permissions=3 が重要で、"Read,Write"ではダメらしい。 pe…

Firewall 再び

Powershell でファイアーウォール設定 取得 TBD 設定 FTP port 21 設定。 - Data portの許可に関しては別途。 if (-not(Get-NetFirewallRule | where Name -match "ftp")) { New-NetFirewallRule ` -Name "FTP-test" ` -DisplayName "FTP-test" ` -Descripti…

ftp by webclient by powershell

ftp up/download local.txtをftpサーバーに送信&受信 $user = 'me' $pw = 'pass' $url = 'ftp://host.jp/' $wc = New-Object System.Net.WebClient $wc.Credentials = New-Object System.Net.NetworkCredential($user,$pw) $wc.BaseAddress = $url $wc.Uploa…

Powershell カスタムオブジェクト

PowerShellカスタムオブジェクト パイプや戻り値で使われているカスタムオブジェクトをコードで意識的に作成する方法。 作成方法 Hashから変換 $obj1 = [PSCustomObject]@{ "Name" = "Tom"; "Age" = 29; } $obj1.Name 応用:hashから既存オブジェクト作成 Add…

-noexit powershell

実行後に終了しないオプション。 参照 http://www.atmarkit.co.jp/fwin2k/win2ktips/1024psshrtct/psshrtct.html

ftp client by powershell

ftp client Powershellのftp client PSFTP Set-FTPConnectionで設定登録 Get-FTPConnectionで接続 Get-FTPItem で読み込み Add-FTPItem で書き込み Get-FTPChildItemでls New-FTPItemでmkdir セッションを閉じる方法は? Code Import-Module PSFTP Set-FTPCo…

Powershell イベント処理

PowerShellイベント処理/WPF PowerShellでのWPFイベントハンドラの登録は、コントロールの持つadd_xxxを使う。 $button.add_Click({Write-Host "poi"}) 引数 $this イベントソース $_. EventArgs 但し、最初のイベントソースは、EventArgs のSourceプロパテ…

PSSharper xaml editor

PSSharper Powershell の構文チェック。 1. PS read-only予約語への代入 2. 未定義変数の参照 3. 未参照変数 xaml editor previewができる模様。 参考 http://www.powertheshell.com/pssharper/

sha1 ハッシュ

$enc = [system.Text.Encoding]::UTF8 $string1 = "This is a string to hash" $data1 = $enc.GetBytes($string1) # Create a New SHA1 Crypto Provider $sha = New-Object System.Security.Cryptography.SHA1CryptoServiceProvider # Now hash and display …

des暗号 by powershell

des暗号化 by powershell Powershell のSecureStringはそのマシンのそのユーザーでしか復号できないので可搬性がない。 そこで、可搬性のある暗号化 # 変数定義 $inPath = "F:\Desktop\myTest.txt" $encPath = "F:\Desktop\Enc.txt" $decPath = "F:\Desktop\…

ウインドウ機能インストール by Powershell

Install-WindowsFeature import-module servermanager Get-WindowsFeature で確認し、 Install-WindowsFeature -Name xx -IncludeManagementTools -Restart -LogPath でインストール Add-WondowsFeatureは、Install-xx のAlias 参考 Technet https://technet…

フォルダパーミッション

フォルダパーミッション設定 by powershell 基本操作は、acl取得、変更、acl設定。 実施例) 継承無効化 $folder = 'c:\tmp\myfolder' $acl = Get-Acl $folder $acl.SetAccessRuleProtection($true,$true) $acl | Set-Acl $folder 継承付きでフルコントロール…

IIS-FTP userisolation by Powershell

PowerShellによるIIS FTPサイト構築 前提 ユーザー分離はvdir非共有 $iso=3 Read/Write可 Win2012R2以降 情報取得 ls IIS:\ ls IIS:Sites\ ls IIS:\Sites\xx $site = Get-Item IIS:\Sites\xx $site $ftp = Get-WebConfiguration -pspath IIS:\Sites\xx $ftp …

Powershell デバッグ

Powershell Debug デバック機能一覧 write-host write-debug write-verbose write-progress Set-PSDebug Break point $host.EnterNestedPrompt() Write-Warning/Error write-host コンソール出力。 write-verbose $VerbosePreferenceにより挙動を変更可能。…

Powershell XML

XML 参考 https://msdn.microsoft.com/ja-jp/library/system.xml.xmlnodelist(v=vs.110).aspx https://msdn.microsoft.com/ja-jp/library/system.xml.xmlelement(v=vs.110).aspx#メソッド http://odashinsuke.hatenablog.com/entry/20090708/1247060185

Powershell WMI

WMI 参考 http://rtaki.sakura.ne.jp/infra/?p=1632

DNS

DNSについて 未だCache ServerとForwarding Serverの違いが分かっていない。 何方もAuthority がない? 参考 https://www.digitalocean.com/community/tutorials/an-introduction-to-dns-terminology-components-and-concepts DNS構築 https://www.designet.…

IIS FTPサイト構築 by Powershell

IIS-FTPサイト自動構築 Windows 2012R2 のPowerShell用IIS WebAdministration Moduleを使って自動構築を試みる。 これらをMSではPowerShell IISスナップインと呼んでいる。ここでは以後スナップインと呼ぶ。 スナップインは3つのカテゴリに分かれる。 プロバ…

Powershell FireWall設定

FireWall 参考 https://creativeweb.jp/tips/firewall-ftp/ http://ameblo.jp/memomemoag0u3/entry-11741667885.html https://technet.microsoft.com/ja-jp/library/dd939055.aspx

Powershell ダイナミックパラメータ

ダイナミックパラメータ Get-Command の動的な挙動 -ArgumentList による変化 参考 http://winscript.jp/powershell/?s=-argumentList

Powershell os version 取得

OS Version取得方法 [System.Environment]::OSVersion 或いは、 Get-WindowsEdition -Online -Verbose 正しく受け取れないケース http://msdn.microsoft.com/en-us/library/windows/desktop/dn302074.aspx

環境変数

環境変数 PowerShell で環境変数操作 読み取り $env:namae 設定/session $env:session = “123” 設定/User Environmentクラスを使う [Environment]:: SetEnvironmentVariable("variable", "value", [EnvironmentVariableTarget]::User) 参考/set http://bakem…

Powershell registry

PowerShellでレジストリ PowerShellでレジストリ操作する方法 読み取り 作成 変更 削除 読み取り Get-ItemProperty -Path HKLM:\Software\Microsoft\Windows\CurrentVersion -Name DevicePath 作成 New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows…

Powershell Unit test

ユニットテストツール Pesterの紹介 PeaterはPowerShell向けのUnit Test Tool 使い方 PS> New-Fixture -Name HelloWorld これで、HelloWorld.ps1と、HelloWorld.Tests.ps1が作成される。 実行は PS> invoke-pester Executing all tests in 'C:\usr\tmp' Desc…

ページ切替

Powershell + wpfのページ切替 NavigationWindow http://sourcechord.hatenablog.com/entry/20130831/1377942291 参考 uwp http://coelacanth.jp.net/uwp_006/ NavigationService http://graphics.hatenablog.com/entry/2015/02/08/154920

Powershell Module Manifest

Powershell Module Manifest 作成方法は3種類 1. versionのみ 2. New-ModuleManifest 3. テンプレートを写す Versionのみ '@{ModuleVersion="1.0"}' > myModuleName.psd1 New-ModuleManifest New-ModuleManifest myModuleName.psd1 -ModuleVersion "2.0" -Au…

Windows初期設定関連スクリプト

目次 タイムゾーン Windowsファイアーウォール Firewall プロキシ設定 windoqs update IE ESC無効化 IP固定化 DNS設定/DNSサーバーIPアドレス追加 ネットワークのifIndex, alias, IPアドレス取得 ファイアーウォール設定について PS> Get-NetFirewallProfile…

Set-ExecutionPolicy

みんなが最初に引っかかる所 Set-ExecutionPolicy Restricted - 実行できるスクリプトはありません。Windows PowerShell は対話型モードでのみ使用できます。 AllSigned - 信頼できる発行元が署名したスクリプトのみを実行できます。 RemoteSigned - ダウン…

Powershell zabbix

Powershell で書くzabbix zabbix_agentd.confに書くらしい。 Userparameter=vm.state,powershell.exe -NoProfile -ExecutionPolicy Bypass -file “C:\test.ps1” スクリプトの中身は — test.ps1 $Health = "poi" foreach($State in $Health){ if($state.Healt…

windows dnsサーバー

DNSサーバーをpowershellから設定したいので、まずは関連情報を収集。 DnsShellを利用 DnsShell Module install ServerManager Module Install Zone登録 ホスト=Aレコード登録 逆引きPTRレコード登録 DnsShell Module Install Import-Module DnsShell Get-Co…