天天看点

powershell 记录

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"password="password"securepassword = convertto-securestring password−asplaintext−forcepassword−asplaintext−forcedomain="domain"

 username="user"username="user"credential = new-object management.automation.pscredential((domain+"\"+domain+"\"+username),securepassword)securepassword)computername = "sptws-sut02"

 mainurl="http://"+mainurl="http://"+computername

 sitename="test"sitename="test"path="c:\users\pettest\desktop"

 webname="hahaha"webname="hahaha"attachmentname="testattachmentname2"

 attachmentname=attachmentname=attachmentname + ".txt"

ret=invoke−command−computerret=invoke−command−computercomputername -credential credential -scriptblock{  param(  [string]credential -scriptblock{  param(  [string]sitename,

 [string]webname,[string]webname,[string]path,

 [string]attachmentname,[string]attachmentname,[string]mainurl

 )

[void][system.reflection.assembly]::loadwithpartialname("microsoft.sharepoint") | out-null

spsites=new−objectmicrosoft.sharepoint.spsite(spsites=new−objectmicrosoft.sharepoint.spsite(mainurl)

spweb=spweb=spsites.openweb(sitename+"/"+sitename+"/"+webname)

attachmenturl=attachmenturl=path + "\" + attachmentnameattachmentnamefstream = [system.io.file]::openread(attachmenturl)attachmenturl)bytearray = new-object byte[] fstream.lengthfstream.lengthfstream.read(bytearray,0,[int]bytearray,0,[int]fstream.length); 

fstream.close()fstream.close()spweb.folders["shared documents"].files.add(attachmentname,attachmentname,bytearray) 

}-argumentlist sitename,sitename,webname, path,path,attachmentname,mainurlpowershell使用sharepoint自带的powershellmainurlpowershell使用sharepoint自带的powershellret = invoke-command -computer computername−credentialcomputername−credentialcredential -scriptblock{

 param(

ver=ver=host | select version

 if (ver.version.major−gt1)$host.runspace.threadoptions="reusethread"add−pssnapinmicrosoft.sharepoint.powershellset−locationver.version.major−gt1)$host.runspace.threadoptions="reusethread"add−pssnapinmicrosoft.sharepoint.powershellset−locationhome

 application=get−spserviceapplication−name"businessdataconnectivity"application=get−spserviceapplication−name"businessdataconnectivity"guid=application.idwrite−hostapplication.idwrite−hostguid

 return guidpublish−spserviceapplicationguidpublish−spserviceapplicationguid

 }

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:id–comfirm:false

 远程调用powershell前,client和server要执行:

 enable-psremoting

 set-executionpolicy unrestricted/remotesigned

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