代码改变世界

powershell 记录

2010-10-29 13:58  轩脉刃  阅读(526)  评论(2编辑  收藏  举报

the following module was built either with optimizations enabled or without debug information
 solution:
 I have also faced the same problem on migrating the application .net 1.x to 2.0 and i solved by disabling the "Warn if no user code on launch" under the debugging option in the tools menu.
 Tools --> Options --> Debugging --> General --> Enable Just my code (Managed only) --> un check "Warn if no user code on launch"
 
Release build模式无法调试,会直接run 过
 
Powershell使用dll
 $password= "password"
 $securePassword = ConvertTo-SecureString $password -AsPlainText -Force
 $domain="domain"
 $userName="user"
 $credential = new-object Management.Automation.PSCredential(($domain+"\"+$userName),$securePassword)
$computerName = "sptws-sut02"
 $mainUrl = "http://" + $computerName
 $siteName = "test"
 $path="C:\Users\pettest\Desktop"
 $webName="HAHAHA"
 $attachmentName="testAttachmentName2"
 $attachmentName = $attachmentName + ".txt"
 
$ret = invoke-command -computer $computerName -Credential $credential -scriptblock{
 param(
 [string]$siteName,
 [string]$webName,
 [string]$path,
 [string]$attachmentName,
 [string]$mainUrl
 )
 
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") | out-null
 

$spSites = new-object Microsoft.SharePoint.SPSite($mainUrl)
 

$spWeb = $spSites.openweb($siteName +"/"+ $webName)
 
$attachmentUrl = $path + "\" + $attachmentName
 
$fStream = [System.IO.File]::OpenRead($attachmentUrl)
 
$byteArray = new-object byte[] $fStream.Length
 
$fStream.Read($byteArray, 0, [int]$fStream.Length);
$fStream.close()
 
$spWeb.Folders["Shared Documents"].Files.Add($attachmentName, $byteArray)
}-argumentlist $siteName, $webName, $path,$attachmentName,$mainUrl
 
Powershell使用sharepoint自带的powershell
 $ret = invoke-command -computer $computerName -Credential $credential -scriptblock{
 param(
 )
 
$ver = $host | select version
 if ($ver.Version.Major -gt 1)
{$Host.Runspace.ThreadOptions = "ReuseThread"}
 Add-PsSnapin Microsoft.SharePoint.PowerShell
 Set-location $home
 $application = Get-SPServiceApplication -name "Business Data Connectivity"
 $guid=$application.ID
 
write-host $guid
 return $guid
 Publish-SPServiceApplication $guid
 }
 
Sharepoint的Powershell
 罗列一些命令:
 Get-SPDatabase
 
Database:Microsoft.Office.Server.Administration.ProfileDatabase
 DataConnectionFile:Microsoft.Office.InfoPath.Server.Administration.DataConnectionFile
 
Get-SPIisWebServiceApplicationPool
 Get-SPServiceApplication
 Stop-SPServiceInstance –Identity $id –comfirm:$false
 远程调用Powershell前,client和server要执行:
 Enable-PSRemoting
 Set-executionPolicy unrestricted/remotesigned
 
如果client端是x64,则务必在powerehll-x86和-x64上都要执行