powershell 记录

来源:互联网 发布:linux 查看显存 编辑:程序博客网 时间:2024/05/23 11:08

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

}

 

SharepointPowershell

罗列一些命令:

Get-SPDatabase

 

DatabaseMicrosoft.Office.Server.Administration.ProfileDatabase

DataConnectionFile:Microsoft.Office.InfoPath.Server.Administration.DataConnectionFile

 

Get-SPIisWebServiceApplicationPool

Get-SPServiceApplication

Stop-SPServiceInstance –Identity $id –comfirm:$false

远程调用Powershell前,clientserver要执行:

Enable-PSRemoting

Set-executionPolicy unrestricted/remotesigned

 

如果client端是x64,则务必在powerehll-x86-x64上都要执行

 

原创粉丝点击