by kusakari
28. 9月 2009 19:22
SharePoint Serverのドキュメントライブラリに、ローカルに保存されているファイルをアップロードします。
環境:PowerShell V2 , Microsoft Office SharePoint Server 2007 (MOSS2007)
■WebClientクラスの作成
System.Net.WebClientを作成します。
$client = New-Object Net.WebClient
■資格情報の設定
System.Net.CredentialCacheで、DefaultCredentials資格情報を適用します。
$client.Credentials = [Net.CredentialCache]::DefaultCredentials
■アップロード
UploadFileメソッドでファイルをアップロードします。
$client.UploadFile($url + $saveFileName, "PUT", $uploadFilePath)
■サンプルスクリプト
ローカルの C:\Temp\test.txt ファイルを、SharePoint Server上のドキュメントライブラリの中にある「レポート/WSUS/」に、今日の日付のファイル名でアップロードします。
$url = "https://xxxxxx:xxxx/SiteDirectory/Security/Shared%20Documents/レポート/WSUS/"
$upFilePath = "C:\Temp\test.txt"
$date = Get-Date
$date = [string]$date.ToString("yyyy年MM月dd日") + ".txt"
$client = New-Object Net.WebClient
$client.Credentials = [Net.CredentialCache]::DefaultCredentials
$client.UploadFile($url + $date , "PUT", $upFilePath)
$client.Dispose()
■結果

08b378aa-7578-41af-bf4d-6e37ba327643|0|.0
by kusakari
25. 9月 2009 22:45
SharePoint Serverのサイトに作られた、ドキュメントライブラリに保存されているファイルの一覧を取得します。
環境:PowerShell V1 , Microsoft Office SharePoint Server 2007 (MOSS2007)
今回の実験環境では、ドキュメントライブラリの名前は「共有ドキュメント」になります。
■サイトのコンテンツリストを確認します。
$web.lists | Select-Object Title
■コンテンツリストのコレクションを取得します。
$col = $web.lists["共有ドキュメント"].Items
■サンプルスクリプト
$url = "https://xxxxxx:xxxx/SiteDirectory/Security/"
[Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") | Out-Null
$site = New-Object Microsoft.SharePoint.SPSite($url)
$web = $site.OpenWeb()
$web.lists["共有ドキュメント"].Items | Select-Object Name, File -First 10
$site.Dispose()
■結果

a70abada-36d7-4cdc-8071-99f535578cc4|0|.0
by kusakari
24. 9月 2009 22:47
PowerShellでSharePoint Server(MOSS)に接続して、簡単なサイト情報を取得します。
環境:PowerShell V1 , Microsoft Office SharePoint Server 2007 (MOSS2007)
■参照の追加を行います。
[Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") | Out-Null
■SPSiteクラスを作成して、SharePoint(MOSS)のURLを指定します。
$moss = New-Object Microsoft.SharePoint.SPSite($url)
■サンプル
$url = "https://localhost/"
[Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") | Out-Null
$moss = New-Object Microsoft.SharePoint.SPSite($url)
$moss #サイト情報の表示
$moss.AllWebs | Select-Object Title, Users #全てのサイトのタイトルとURL表示
$moss.Dispose()
■結果

e9f70af9-6087-47f5-ba75-6ed4446a33a7|0|.0
by kusakari
18. 9月 2009 23:36
PowerShellからWSUSに接続して、WSUSクライアントの未適用更新プログラム情報を取り出します。
環境:PowerShell v2 , WSUS 3.0
■Microsoft.UpdateServices.Administrationを追加して、ローカルのWSUSサーバへ接続します。
[Reflection.Assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration") | Out-Null
$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer()
■ComputerTargetScopeクラスを作成します。
$compScope = New-Object Microsoft.UpdateServices.Administration.ComputerTargetScope
$compScope.IncludedInstallationStates = [Microsoft.UpdateServices.Administration.UpdateInstallationStates]::All
■UpdateScopeクラスを作成します。
状態として下記の2つの状態である更新プログラムを取得します。
| NotInstalled |
: |
未インストール |
| Downloaded |
: |
ダウンロード済みで、未インストール |
$upScopeNI = New-Object Microsoft.UpdateServices.Administration.UpdateScope
$upScopeNI.IncludedInstallationStates = [Microsoft.UpdateServices.Administration.UpdateInstallationStates]::NotInstalled
$upScopeDL = New-Object Microsoft.UpdateServices.Administration.UpdateScope
$upScopeDL.IncludedInstallationStates = [Microsoft.UpdateServices.Administration.UpdateInstallationStates]::Downloaded
■サンプルスクリプト
[Reflection.Assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration") | Out-Null
$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer()
$compScope = New-Object Microsoft.UpdateServices.Administration.ComputerTargetScope
$compScope.IncludedInstallationStates = [Microsoft.UpdateServices.Administration.UpdateInstallationStates]::All
$upScopeNI = New-Object Microsoft.UpdateServices.Administration.UpdateScope
$upScopeNI.IncludedInstallationStates = [Microsoft.UpdateServices.Administration.UpdateInstallationStates]::NotInstalled
$upScopeDL = New-Object Microsoft.UpdateServices.Administration.UpdateScope
$upScopeDL.IncludedInstallationStates = [Microsoft.UpdateServices.Administration.UpdateInstallationStates]::Downloaded
$ret = ""
$comps = $wsus.GetComputerTargets($compScope) | ForEach-Object {
$updateInfoNI = $_.GetUpdateInstallationInfoPerUpdate($upScopeNI);
$updateInfoDL = $_.GetUpdateInstallationInfoPerUpdate($upScopeDL);
$ret += "=============================================`r`n"
$ret += "コンピューター名: " + $_.FullDomainName + "`r`n"
$ret += "IPアドレス: " + $_.IPAddress + "`r`n"
$ret += "最終状態送信日時: " + ([datetime]$_.LastReportedStatusTime).ToString("yyyy/MM/dd HH:mm:ss") + "`r`n"
$ret += "OS: " + $_.OSDescription + "`r`n"
$ret += "=============================================`r`n"
$updateInfoNI | ForEach-Object {
$updateNI = $wsus.GetUpdate($_.UpdateId)
$ret += "Title: " + $updateNI.Title + "(" + $updateNI.UpdateClassificationTitle + ")(NotInstalled)`r`n"
}
$updateInfoDL | ForEach-Object {
$updateDL = $wsus.GetUpdate($_.UpdateId)
$ret += "Title: " + $updateDL.Title + "(" + $updateDL.UpdateClassificationTitle + ")(Downloaded)`r`n"
}
$ret += "`r`n"
}
Write-Host $ret
■結果

18204d36-d02c-4fad-bf67-37bc9f3a1427|0|.0
Category: PowerShell
Tags: WSUS
by kusakari
17. 9月 2009 19:45
PowerShellからWSUSに接続して、WSUS更新プログラム情報を取り出します。
環境:PowerShell v2 , WSUS 3.0
■ Microsoft.UpdateServices.Administrationを追加して、ローカルのWSUSサーバへ接続します。
[Reflection.Assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration")
$wsus = [microsoft.updateservices.administration.adminproxy]::GetUpdateServer()
■ UpdateScopeクラスを作成します。
$scope = New-Object Microsoft.UpdateServices.Administration.UpdateScope
$scope.IncludedInstallationStates = [Microsoft.UpdateServices.Administration.UpdateInstallationStates]::All
■ サンプルスクリプト
[Reflection.Assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration") | Out-Null
$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer()
$scope = New-Object Microsoft.UpdateServices.Administration.UpdateScope
$scope.IncludedInstallationStates = [Microsoft.UpdateServices.Administration.UpdateInstallationStates]::All
$wsus.GetUpdates($scope) | Select-Object -Property UpdateClassificationTitle,ProductTitles,Title -First 10
■ 結果

f1b4de37-971b-49d6-99df-1e50dd4e16a6|0|.0
Category: PowerShell
Tags: WSUS