powershell

AD属性一覧

cls $cn = "CN="; $schema = [DirectoryServices.ActiveDirectory.ActiveDirectorySchema]::GetCurrentSchema(); $Searcher = New-Object System.DirectoryServices.DirectorySearcher( $cn ); $reslt = $Searcher.FindOne(); foreach( $properties in $resl…

powershell でユーザー取得

よく忘れるので。 $targetAccountName="ユーザーアカウント" $root = New-Object DirectoryServices.DirectoryEntry( 'LDAP://rootDSE' ); $dn=$root.defaultNamingContext.Value; # DC=jp,DC=xxxx,DC=net $entry = New-Object DirectoryServices.DirectoryE…

PowerShell で困ったら

とりあえず Get-Member,GetType で状況確認。

PowerShell で ActiveDirectory

なんか PowerShell で GetDirectoryEntry すると DirectoryEntry じゃないものが取れる。要は entry.propertyName みたいな書き方をしたいからそうなってるっぽいんだけど。リフレクションっぽい。 別に entry.Properties["propertyName"] でもいいんだけど…

PowerShellでもClassが作れるてきな

http://mojibake.seesaa.net/article/56484188.html

powershell(ver1.0) で try-catch

2.0 は実装されたらしい。 でもなんか 1.0 使うらしい。ネタ元 http://csharper.blog57.fc2.com/blog-entry-177.html 必要に迫られて catch の複数対応。 つかんだ例外の $Error は削除してる。 function CatchStatements ( $catchBlocks, $ex, [ref]$isCatc…

DirectoryServices.DirectoryEntry で dispose できない罠

powershellの話。(ver1.0) 確認ロジック $target = New-Object DirectoryServices.DirectoryEntry( 'LDAP://rootDSE' ) if ( !($target -is [IDisposable]) ) { return; } $target.Dipose(); ちなみに GetType もできないし。 なんかのラッパーなのかと思う…

powershellの落とし穴

function test() { "aaaaa"; Write-Host "bbbbb"; Write-Output "ccccc"; return 100; } cls; $result = test; # output # bbbbb $result.Length; # output # 3 $result[0]; # output # aaaaa $result[1]; # output # ccccc $result[2]; # output # 100 retu…

PowershellでActiveDirectoryオブジェクトの属性を変更する。

絶対値が取れるのが前提。エラー処理とかないよ。 $targetAccountName = ""; $root = New-Object DirectoryServices.DirectoryEntry( 'LDAP://rootDSE' ) $dn = $root.defaultNamingContext.Value; $entry = New-Object DirectoryServices.DirectoryEntry( "…