2020年10月28日水曜日

◆配列の連結

PS C:\> $a = 1,2,3
PS C:\> $b = 4,5,6
PS C:\> $a + $b
1
2
3
4
5
6
PS C:\> $a,$b
1
2
3
4
5
6

この2つは一見同じ結果に見えるが、$a = 1 とすると前者は

[System.Object[]] に 'op_Addition' という名前のメソッドが含まれないため、メソッドの呼び出しに失敗しました。
発生場所 行:1 文字:1
+ $a + $b
+ ~~~~~~~
     + CategoryInfo          : InvalidOperation: (op_Addition:String) []、RuntimeException
     + FullyQualifiedErrorId : MethodNotFound

となる。

後者も一見良さそうに見えるが実際には多段階配列になってしまう。

$c = $a , $b
$c.count   #2になる
$c[0][0]     #1

どうすれば汎用的ですかね。

$c = @()
$c += $a |  %{$_}
$c += $b |  %{$_}

とか?

.NETクラスを使う?

連結も加算も「+」にしたので混乱を招く?

2020年10月22日木曜日

◆Get-ADUser フィルター(filter)の指定方法

外側をダブルコーテーション、文字列をシングルコーテーションで囲むのが基本でしょうか。

外側囲み記号

属性

値の指定方法

値の囲み記号

結果

シングルコーテーション

数値

コンスタント

無し

Get-ADUser -Filter 'employeeid -eq 479'

シングルコーテーション

数値

変数

無し

$id = 479

Get-ADUser -Filter 'employeeid -eq $id'

シングルコーテーション

数値

変数(プロパティ)

無し

$p = 1 | select id , account

$p.id = 479 ; $p.account = "hoge_hoge"

Get-ADUser -Filter 'employeeid -eq $($p.id)'

X

シングルコーテーション

文字列

コンスタント

ダブルコーテーション

Get-ADUser -Filter 'samaccountname -eq "hoge_hoge"'

シングルコーテーション

文字列

変数

無し

$account = "hoge_hoge"

Get-ADUser -Filter 'samaccountname -eq $account'

シングルコーテーション

文字列

変数

ダブルコーテーション

$account = "hoge_hoge"

Get-ADUser -Filter 'samaccountname -eq "$account" '

X

シングルコーテーション

文字列

変数(プロパティ)

無し

$p = 1 | select id , account

$p.id = 479 ; $p.account = "hoge_hoge"

Get-ADUser -Filter 'samaccountname -eq $($p.account)'

X

ダブルコーテーション

数値

コンスタント

無し

Get-ADUser -Filter "employeeid -eq 479"

ダブルコーテーション

数値

変数

無し

$id = 479

Get-ADUser -Filter "employeeid -eq $id"

ダブルコーテーション

数値

変数(プロパティ)

無し

$p = 1 | select id , account

$p.id = 479 ; $p.account = "hoge_hoge"

Get-ADUser -Filter "employeeid -eq $($p.id)"

ダブルコーテーション

文字列

コンスタント

シングルコーテーション

Get-ADUser -Filter "samaccountname -eq 'hoge_hoge' "

ダブルコーテーション

文字列

変数

無し

$account = "hoge_hoge"

Get-ADUser -Filter "samaccountname -eq $account"

X

ダブルコーテーション

文字列

変数

シングルコーテーション

$account = "hoge_hoge"

Get-ADUser -Filter "samaccountname -eq '$account' "

ダブルコーテーション

文字列

変数(プロパティ)

無し

$p = 1 | select id , account

$p.id = 479 ; $p.account = "hoge_hoge"

Get-ADUser -Filter "samaccountname -eq $($p.account)"

X

ダブルコーテーション

文字列

変数(プロパティ)

シングルコーテーション

$p = 1 | select id , account

$p.id = 479 ; $p.account = "hoge_hoge"

Get-ADUser -Filter "samaccountname -eq '$($p.account)' "

波括弧

数値

コンスタント

無し

Get-ADUser -Filter {employeeid -eq 479}

波括弧

数値

変数

無し

$id = 479

Get-ADUser -Filter {employeeid -eq $id}

波括弧

数値

変数(プロパティ)

無し

$p = 1 | select id , account

$p.id = 479 ; $p.account = "hoge_hoge"

Get-ADUser -Filter {employeeid -eq $($p.id)}

X

2020年10月13日火曜日

◆ActiveDirectory ユーザーの名前(name)を更新するには

どうするんでしょうね。

Set-Aduserには Name パラメータが無いんですね。

GUIでは更新できるので何かしら方法はありそうなのですが。

そのうち調べてみましょう。