powershell
コマンド分類 基本構造 Keyword: NetLbfoTeam Verb: New, Remove, Get, Set, Add, Rename Object: (none), Nic, Member Verb-Object matrix New: None Add: Nic, Member Remove: None, Member, Nic Get: None, Member, Nic Set: None, Member, Nic Rename: N…
wpf drag and drop by powershell powershellでのドラックアンドドロップ実装方法。 手順 1. xamlでAllowDrop=“True” 2. PowerShellでハンドラ実装 - Add_DropEnter - Add_DropLeave - その他のハンドラ AllowDrop <Window Name="w1" AllowDrop="True" > <StackPanel> </StackPanel> </Window> ハンドラ $w : Window Object function…
TCP by Powershell 手順 new tcpclient stream to reader check .Connected read(buffer,0,size) Write $tcpConnection = New-Object System.Net.Sockets.TcpClient($FTPServer, $FTPPort) $tcpStream = $tcpConnection.GetStream() $reader = New-Object Sy…
LinuxからWindows制御 winexeが使える。 コンピュータ名 hunnyの場合。 winexe -U hunny/Administrator%poi //192.168.1.1 "echo Oha-" 開放が必要なポート 135/tcp(RPCエンドポイント・マッパー) 445/tcp(ダイレクト・ホスティングSMB) 1025~65535/tcp…
非同期実行 by powershell RunSpace Start-Job Start-Process AppDomain 独立アプリ起動 System.Diagnostics.Process 非同期中、標準入出力を制御できるもの。 Start-Job : receive-job Start-Process: ファイル指定 Process: Stream 終了値を取得できるもの…
ssh by powershell ssh.net + PowerShell opensshも出ているが、PowerShellで使うにはモジュールの方が便利かもしれない。 参考 http://www.powershelladmin.com/wiki/SSH_from_PowerShell_using_the_SSH.NET_library
AppDomain再び PowerShellによるAppDomain制御。 ちょっと古い記事。10年前のもの。 by oising 2007/12/07 As knowledge of PowerShell increases for those new to .NET, there comes a point when people start to notice some shortcomings of the Assemb…
PowerShell Action delegate Action/Funcはdelegate型 Action : 戻り値なし、引数なし。 Action: 戻り値なし、引数1 Func<T,TResult: 戻り値1,引数1 PowerShellでは [action] [action[int]] [func[int][int]] ? or func[int,int]] ? Funcの例 Func<T,TResult> using System; public class GenericFunc { public static void Main() { // Instantiate deleg…</t,tresult:>
ShowDialog()中に非同期イベントを処理できない。 Powershell でWPFのShowDialog()を処理中に非同期イベントが発生しても処理されない件、原因不明ながら回避策にて対応。 なお、イベントの発生と処理は別物。発生時刻をイベントのプロパティTimeGeneratedで…
SynchronizingObject on powetshell Start-ProcessのExitedイベントの終了処理で、wpfのLabel.Contentを変更したい。 それだけ。 $proc = Start-Process "poi.bat" -passThru $ev = Register-ObjectEvent $proc -EventName Exited -Action { AddText("hoge")…
RunSpace 参考 https://msdn.microsoft.com/ja-jp/library/system.management.automation.runspaces.runspace(v=vs.85).aspx https://blogs.technet.microsoft.com/heyscriptingguy/2015/11/26/beginning-use-of-powershell-runspaces-part-1/ https://www.g…
Clipboad on wpf by powershell PowerShellでWPFのクリップボードを使う。 [Windows.Clipboard] のGetText(), SetText()を使う。 $get = [Windows.Clipboard]::GetText() [Windows.Clipboard]::SetText("oha") [Windows.Clipboard]::Clear() 但し、下記が必…
Poweshellコンソール by wpf まさに欲しかったもの。PowerShellコンソールをWPFに組み込む。 肝はPowershll.Create()でPowershell を生成する事。 using (var powershell = PowerShell.Create()) { powershell.AddCommand("Get-ChildItem"); powershell.AddC…
Start-ProcessのExitedEvent Thread Strart-ProcessのExited EventはデフォルトではSystem thread pool から実行される。UI系とは異なるため、UI系を制御すると問題が発生しやすい。 そのため、Formなどで使用するためにSynchronizingObject にUIオブジェク…
リモートデスクトップをHttpsで/ssl飛ばす。 myrtilleで可能な模様。WebSocketを使用している模様。 参考 https://github.com/cedrozor/myrtille/blob/master/README.md
WPF messageBox MessageBoxResult result = MessageBox.Show("Do you want to close this window?", "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { Application.Current.Shutdown(); } 参考 M…
PowerShellで実行ユーザー取得 $id = [System.Security.Principal.WindowsIdentity]::GetCurrent() $uname = $id.Name $groupsids = $id.Groups $groupsids | foreach{ $_.Translate([System.Security.Principal.NTAccount]) } 参考 WindowsIdentity http://…
ftp起動 $ftpSite.Start()はダメで、正しくは$ftpsite.ftpserver.Start()なのね。 ftpサーバーをスタートすれば良かったのね $ftpSite = IIS:\Sites\FtpData $ftpSite.ftpServer.Start() 参考 http://stackoverflow.com/questions/23015011/start-ftp-websit…
Pester for PowerShell 実行方法 雛形生成 New-Fixture .\bin Code テスト実行 Invoke-Pester .\bin\Code.Tests.ps1 テスト記法 Describe "Code" { Context "poi1" { It "Test Case 1" { $data | should Be $null } It "TestCase2" { "" | Should exist } } …
PSScriptAnalyzer for PowerShell 使い方 Invoke-ScriptAnalyzer SCRIPT 使うまで Download from GitHub Install-Module -Name PSScriptAnalyzer or git clone https://github.com/PowerShell/PSScriptAnalyzer or download from https://github.com/PowerSh…
-whatif powershell のコモンパラメータの一つ、-whatif は、いわゆるドライランのオプション。Remove-itemやCopy-Itemなどで実行せずに、実行確認をする。 さて、実装するには? -whatif実装 肝は、 if( $PSCmdlet.ShouldProcess( $target ) ){ -whatif時に…
文字コード on powershell コード sjis XAML sjis out-file unicode get/set-content sjis $outputencoding us-ascii chcp 65001
WebClient by PowerShell Webclient classを使ってダウンロード function download ( [String]$dir = "c:\wk\poi", [uri]$uri = "https://www.google.com/index.html") { $file = Split-Path $uri.AbsolutePath -Leaf $bs = New-Object System.Net.WebClient…
WPF ComboBox 方法としては二つ。 XAML内にデータを書く。 コード側のクラスをバインドする。 XAML版 <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Combo" Height="10" Width="100"> <StackPanel> <ComboBox SelectedIndex="0"> <ComboBoxItem>その一</comboboxitem></combobox></stackpanel></window>
PowerShellでssh 参考 .netを使ったssh module PowerShellからsshしたい http://www.infilic.co.jp/tech/?p=542 https://www.starplatinum.jp/connect_linux_via_ssh/ OpenSSHサポートのニュース http://osdn.jp/magazine/15/06/05/082000 http://www.simpli…
配列性能 on PowerShell PowerShell配列に += で要素を追加する性能が良くないらしい。固定長配列として実装されており、追加時に配列を作り直しているのが原因とのこと。 性能面ではArrayList or List使用を推奨する。Listを使用する場合、 $x = New-Object…
CTRL-C by PowerShell PowerShellでCTRL-Cを処理する方法 Polling finally finally CTRL-Cや、exit() 実行時でもfinallyが実行される。 polling CTRL-Cをキー入力処理するフラグをセットし、以後はCTRL-Cをキー入力としてポーリング。 フラグセット キーのポ…
Start-Process使用法 全体フロー $proc Start-process -passThru $ejob = Register-ObjectEvent -action $action -MessageData $job action: unregister-event remove-job $ejob PowerShellからの外部コンソールアプリを非同期起動する際にStart-Processを使…
Windowsネットワークの場所変更 Windowsネットワークの場所には、 パブリック public プライベート private ドメイン domain の3種類があり、Windowsファイアーウォールの設定が異なる。 プライベートへの変更方法 接続確認 Get-NetConnectionProfile 変更 S…
使用メモリ追加 クオータが不足していますメッセージが出るようになったため、使用メモリを追加する。 winrm winrmを使用するので設定。管理者権限が必要なので、管理者になってから。 Start-Process powershell -verb runas winrm quickconfig 現設定を確認…