foreach ループに変数 $a があります。
ファイル名に文字列を設定したい。
$server = "mysqlservername"
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SmoEnum') | out-null
$My='Microsoft.SqlServer.Management.Smo'
$srv = new-object ("$My.Server") $Server
$scripter = new-object ("$My.Scripter") $srv
$scripter.Options.ToFileOnly = $true
$a = new-object System.Data.Datatable
$a=$srv.databases[$Database].EnumObjects([long]0x1FFFFFFF -band $all)
$a | FOREACH-OBJECT
{
$scripter.Options.Filename = "$($_.schema).$($_.name)"
#then script out an object using that filename)
$UrnCollection = new-object ('Microsoft.SqlServer.Management.Smo.urnCollection')
$URNCollection.add($_.urn)
$scripter.script($URNCollection)
}
ファイル名を「schema.name」にしたいのですが、$_.schema が存在する場合のみです (すべてのオブジェクトにスキーマがあるわけではありません)。そうでない場合は、「名前」だけにしたい
空の場合、 $a.schema が空白か null か空かはわかりません。それが重要かどうかはわかりません。
現在の設定では、スキーマが空 (?) の場合、ファイル名は「.myobjectnamehere」です。
1行でそれを行う方法はありますか?大量の IF 条件で実行できますが、できればインラインで実行したいと思います。ありがとう。
$a | の内容は次のとおりです。gm
TypeName: System.Data.DataRow
Name MemberType Definition
---- ---------- ----------
AcceptChanges Method void AcceptChanges()
BeginEdit Method void BeginEdit()
CancelEdit Method void CancelEdit()
ClearErrors Method void ClearErrors()
Delete Method void Delete()
EndEdit Method void EndEdit()
Equals Method bool Equals(System.Object obj)
GetChildRows Method System.Data.DataRow[] GetChildRows(string relationName), System.Data.DataR...
GetColumnError Method string GetColumnError(int columnIndex), string GetColumnError(string colum...
GetColumnsInError Method System.Data.DataColumn[] GetColumnsInError()
GetHashCode Method int GetHashCode()
GetParentRow Method System.Data.DataRow GetParentRow(string relationName), System.Data.DataRow...
GetParentRows Method System.Data.DataRow[] GetParentRows(string relationName), System.Data.Data...
GetType Method type GetType()
HasVersion Method bool HasVersion(System.Data.DataRowVersion version)
IsNull Method bool IsNull(int columnIndex), bool IsNull(string columnName), bool IsNull(...
RejectChanges Method void RejectChanges()
SetAdded Method void SetAdded()
SetColumnError Method void SetColumnError(int columnIndex, string error), void SetColumnError(st...
SetModified Method void SetModified()
SetParentRow Method void SetParentRow(System.Data.DataRow parentRow), void SetParentRow(System...
ToString Method string ToString()
Item ParameterizedProperty System.Object Item(int columnIndex) {get;set;}, System.Object Item(string ...
DatabaseObjectTypes Property string DatabaseObjectTypes {get;set;}
Name Property string Name {get;set;}
Schema Property string Schema {get;set;}
Urn Property string Urn {get;set;}