Sunday 9 April 2017

PowerShell remoting - create folder on remote servers

Preparation

Read-Host -AsSecureString | ConvertFrom-SecureString | Out-File C:\Scripts\<username>\<username>_pwd.txt

Variables

$SPserver = "<servername>"

$username = "\"
$password = Get-Content C:\Scripts\<username>\<username>_pwd.txt | ConvertTo-SecureString

Credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username, $password

Connection

#Create remote session to SP server
$session=New-PSSession -ComputerName $SPserver -Credential $credentials

Create DIR

Invoke-Command -Session $session -ArgumentList $output -ScriptBlock  { mkdir E:\<FolderName> }

#Removing remote sessions
Get-PSSession |Remove-PSSession

Open a SharePoint list using PowerShell

Keep using this so put it up here for reference:


#Open SharePoint List
$SPServer=
"http://abcd01:9999/"
$SPAppList=
"/Lists/UPList/"
$spWeb =
Get-SPWeb $SPServer
$spData = $spWeb.
GetList($SPAppList)

Export SharePoint Group members to .csv

Export SP Group members to .csv 

# Script for extracting members of SP groups in a site to a .csv file

This is how it looks in ISE:



Here is the Powershell:


Add-PSSnapin "Microsoft.SharePoint.PowerShell"

function global:Get-SPSite($url)
 {
    return new-Object Microsoft.SharePoint.SPSite($url)
 }

function global:Get-SPWeb($url)
{
  $site= New-Object Microsoft.SharePoint.SPSite($url)
        if($site -ne $null)
            {
               $web=$site.OpenWeb();     
            }
    return $web
}

$URL="https://extranet.domain/sites/Meetings"
     $site = Get-SPSite $URL
    
     #Write the Header to "Tab Separated Text File"
        "Site Name`t  URL `t Group Name `t User Account `t User Name `t E-Mail" | out-file "c:\Scripts\UsersandGroupsRpt.txt"
        
     #Iterate through all Webs
      foreach ($web in $site.AllWebs)
      {
        #Write the Header to "Tab Separated Text File"
        "$($web.title) `t $($web.URL) `t  `t  `t `t " | out-file "c:\Scripts\UsersandGroupsRpt.txt" -append
         #Get all Groups and Iterate through  
         foreach ($group in $Web.groups)
         {
                "`t  `t $($Group.Name) `t   `t `t " | out-file "c:\Scripts\UsersandGroupsRpt.txt" -append
                #Iterate through Each User in the group
                       foreach ($user in $group.users)
                        {
                           #Exclude Built-in User Accounts
                    if(($User.LoginName.ToLower() -ne "nt authority\authenticated users") -and ($User.LoginName.ToLower() -ne "sharepoint\system") -and ($User.LoginName.ToLower() -ne "nt authority\local service"))
                    {
                                "`t  `t  `t  $($user.LoginName)  `t  $($user.name) `t  $($user.Email)" | out-file "c:\Scripts\UsersandGroupsRpt.txt" -append
                             }
                        }
         }
       }

    write-host "Report Generated at c:\Scripts\UsersandGroupsRpt.txt"






SharePoint Information Architecture Diagram

Here is the template I use for Information Architecture designs. It's built using Mindjet and I flesh the nodes out with the low level d...