So my code generates output when using Enter-PSSession but the same code does not return data using invoke-command (using CredSSP) as a script.
Here is the relevant excerpt from my script:
So I am able to use the Get-SPWeb.Recylce() method when I am using Enter-PSSession but as soon as I turn this code into a script with invoke-command I do not get access to that method. What gives? I am still logged in as the same user. I suppose
it would be a permissions issue but my login never changed
if ((Get-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null) {
Add-PSSnapin Microsoft.SharePoint.PowerShell
}
$webapps = (Get-SPWebApplication | % {$_.url})
$listTemplate = [Microsoft.SharePoint.SPListTemplateType]::DocumentLibrary
foreach ($webapp in $webapps) {
$appdetails = Get-SPWebapplication $webapp
$appdetails.GrantAccessToprocessIdentity("$env:userdomain"+"\$env:username")
$spWeb = Get-SPWeb -Identity $webapp
$DocLibName = "MSOTest$($appdetails.displayname)".split(".")[0]
$DocLibName += "_DocumentLibrary"
try {
$library = $null
$library = $spWeb.lists["$DocLibName"]
}
catch {out-null}
if ($library) {
#If document library does exist, delete it
$spFolder = $spWeb.GetFolder("$DocLibName")
$spFolder.recylce() | out-null
}