我可以在我的SharePoint服务器上完美运行此脚本,用户的个人资料图片被更新:调用脚本远程不起作用
[Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
[Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server")
$siteurl = "http://SHAREPOINTSITE/"
try {
$site = New-Object Microsoft.SharePoint.SPSite($siteurl)
} catch {
New-Item -ItemType File -Path C:\Users\admin\Desktop -Name ERROR1.txt -Value $_.Exception.Message -Force
}
try {
$context = [Microsoft.Office.Server.ServerContext]::GetContext($site)
} catch {
New-Item -ItemType File -Path C:\Users\admin\Desktop -Name ERROR2.txt -Value $_.Exception.Message -Force
}
#This gets the User Profile Manager which is what we want to get hold of the users
$upm = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)
$user = "DOMAIN\user.name"
#Put it in a loop for iterating for all users
if ($upm.UserExists($user)) {
try {
$profile = $upm.GetUserProfile($user)
$profile["PictureURL"].Value = "\\Sharepoint\C$\Users\admin\Desktop\1.jpg";
$profile.Commit();
} catch {
New-Item -ItemType File -Path C:\Users\admin\Desktop -Name ERROR3.txt -Value $_.Exception.Message -Force
}
}
New-Item -ItemType File -Path C:\Users\admin\Desktop -Name HELLO.txt -Force
$site.Dispose()
但是,当我从远程PowerShell会话中运行它,我得到一些奇怪的错误:
ERROR1.txt
异常调用 “.ctor” 与 “1” 的说法(S):“在http://SHAREPOINTSITE/ Web应用程序可能不被发现。确认您输入的网址是否正确。如果URL应该提供现有内容,系统管理员可能需要一个新的请求URL映射添加到目标应用。“
ERROR2.txt
多暧昧发现超载”的getContext”和参数计数:‘1’
我已经检查了所有的可能性here,但仍然看到这个问题
。这是我如何调用远程机器上面的脚本:
$spfarm = "DOMAIN\admin.username"
$spfarmpw = ConvertTo-SecureString "password123" -AsPlainText -Force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $spfarm,$spfarmpw
$session = New-PSSession SharePoint -Authentication Default -Credential $cred
Invoke-Command -Session $session -FilePath "\\SharePoint\C$\Users\admin\Desktop\testremote.ps1"
我曾尝试在几个不同的方式调用这个(例如将脚本托管在我的机器上或托管在SharePoint服务器上,以及使用相对路径调用脚本),但我总是看到这些错误。
任何人都可以请帮我理解,为什么从远程PC调用它时不起作用?该脚本显然被称为(HELLO.txt
始终得到创建),但SharePoint配置文件图片永远不会更新 - 即使该脚本绝对应该工作。
任何帮助或指导是非常赞赏
NSLOOKUP
nslookup SHAREPOINTSITE
输出
Server: dc1.domain.co.uk
Address: xx.xx.x.xx
Name: sharepoint.domain.co.uk
Address: yy.yy.y.yy
Aliases: SHAREPOINTSITE.domain.co.uk
哪里yy.yy.y.yy
是正确的IP(这是在S我在执行时看到的ame地址ping SHAREPOINTSITE
)
当您在SharePoint服务器上执行nslookup时,名称SHAREPOINTSITE是否解析为正确的IP? –
@MikeGaruccio是的,我认为是。我用'nslookup'结果更新了我的答案 – Bassie
hmm ok,然后打开http:// SHAREPOINTSITE /从浏览器正确显示该网站是否正确? –