Set titleurl property of webparts in powershell script

I have a requirement to change the titleurl of every webpart in my site collection to the url of the page on which the webpart resides, so users can't just navigate to lists and libraries through the webpart title.  How do I accomplish this via powershell,
so I don't have to manually edit hundreds of webparts? 

You can do that using PowerShell:- I hope the below link solves your problem
http://aarebrot.net/blog/2010/09/changing-the-properties-of-an-existing-web-part-using-powershell/
http://sharepointgrind.wordpress.com/2013/08/30/updating-web-part-properties-using-powershell/
Mark ANSWER if this reply resolves your query, If helpful then VOTE HELPFUL
INSQLSERVER.COM
Mohammad Nizamuddin

Similar Messages

  • Powershell script assistance - adding another property to existing script

    This is not my script but was written by Richard L. Mueller. It works perfectly for us but I would like to know if the account is enabled or disabled when the output is created. Basically it would output the name, lastlogon and then either enabled or disabled.
    I've attempted to add a new property by adding another " $Searcher.PropertiesToLoad.Add" and "$Result.Properties.Item ".
    It works fine if I add something like "givenName" but I can't find the property name to show if the account is enabled or disabled.
    The entire script is shown below:
    # PSLastLogon.ps1
    # PowerShell script to determine when each user in the domain last
    # logged on.
    # Copyright (c) 2011 Richard L. Mueller
    # Hilltop Lab web site - http://www.rlmueller.net
    # Version 1.0 - March 16, 2011
    # This program queries every Domain Controller in the domain to find the
    # largest (latest) value of the lastLogon attribute for each user. The
    # last logon dates for each user are converted into local time. The
    # times are adjusted for daylight savings time, as presently configured.
    # You have a royalty-free right to use, modify, reproduce, and
    # distribute this script file in any way you find useful, provided that
    # you agree that the copyright owner above has no warranty, obligations,
    # or liability for such use.
    Trap {"Error: $_"; Break;}
    $D = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
    $Domain = [ADSI]"LDAP://$D"
    $Searcher = New-Object System.DirectoryServices.DirectorySearcher
    $Searcher.PageSize = 200
    $Searcher.SearchScope = "subtree"
    $Searcher.Filter = "(&(objectCategory=person)(objectClass=user))"
    $Searcher.PropertiesToLoad.Add("distinguishedName") > $Null
    $Searcher.PropertiesToLoad.Add("lastLogon") > $Null
    # Create hash table of users and their last logon dates.
    $arrUsers = @{}
    # Enumerate all Domain Controllers.
    ForEach ($DC In $D.DomainControllers)
    $Server = $DC.Name
    $Searcher.SearchRoot = "LDAP://$Server/" + $Domain.distinguishedName
    $Results = $Searcher.FindAll()
    ForEach ($Result In $Results)
    $DN = $Result.Properties.Item("distinguishedName")
    $LL = $Result.Properties.Item("lastLogon")
    If ($LL.Count -eq 0)
    $Last = [DateTime]0
    Else
    $Last = [DateTime]$LL.Item(0)
    If ($Last -eq 0)
    $LastLogon = $Last.AddYears(1600)
    Else
    $LastLogon = $Last.AddYears(1600).ToLocalTime()
    If ($arrUsers.ContainsKey("$DN"))
    If ($LastLogon -gt $arrUsers["$DN"])
    $arrUsers["$DN"] = $LastLogon
    Else
    $arrUsers.Add("$DN", $LastLogon)
    # Output latest last logon date for each user.
    $Users = $arrUsers.Keys
    ForEach ($DN In $Users)
    $Date = $arrUsers["$DN"]
    "$DN;$Date"

    It is part of the userAccountControl attribute. Retrieve that attribute for each user and test if the ADS_UF_ACCOUNTDISABLE bit (2) is set.
    -- Bill Stewart [Bill_Stewart]

  • Powershell script set timezone and default calendar rights to NonEditingAuthor

    Hi
    How do I make a Powershell script setting Timezone to da-dk and calendar rights on default user to NonEditingAuthor for all users?
    Best regards
    MSISOM

    For product specificquestions yoou should post in the product forum.  In this case in teh O365 forum.
    I conencted in to see how easy it is to find the info.  On query was all it took.
    Set-MailboxRegionalConfiguration  --->>
    http://technet.microsoft.com/en-us/library/dd351103(v=exchg.150).aspx
    Searhing O65 is the best place to find your answers.  Post here when you have an issue of how to use PowerShell.
    http://community.office365.com/en-us/f/613/t/29986.aspx
    ¯\_(ツ)_/¯

  • How to set volume using Powershell script?

    I would like to know on how to set volume under Window 7 Home 64 bits system using Powershell script.
    Such as 8000 levels as default
    Does anyone have any suggestions?
    Thanks in advance for any suggestions
    Thanks in advance for any suggestions

    Try this.
    Function Set-SpeakerVolume{
    Param (
    [switch]$min,
    [switch]$max,
    [int]$Percent
    $wshShell = new-object -com wscript.shell
    If ($min){
    1..50 | % {$wshShell.SendKeys([char]174)}
    ElseIf ($max){
    1..50 | % {$wshShell.SendKeys([char]175)}
    elseif($Percent){
    1..50 | % {$wshShell.SendKeys([char]174)}
    1..($Percent/2) |% {$wshShell.SendKeys([char]175)}
    Else{
    $wshShell.SendKeys([char]173)
    This works in Windows 8.1.
    Stolen / Modified from
    http://blogs.technet.com/b/heyscriptingguy/archive/2013/07/28/weekend-scripter-cheesy-script-to-set-speaker-volume.aspx, which took me 20 seconds of (apparently) lucky searching.
    Karl
    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer.
    My Blog: Unlock PowerShell
    My Book:
    Windows PowerShell 2.0 Bible
    My E-mail: -join ('6F6C646B61726C406F75746C6F6F6B2E636F6D'-split'(?<=\G.{2})'|%{if($_){[char][int]"0x$_"}})

  • Is it possible to catch a PowerShell script output when an exit code is setted?

    Hi,
    i'm using TEO 2.1.2 with the hotfixes from 1 to 12 already installed and i have a problem using the "Execute Windows PowerShell Script" in reading the output of a PowerShell script if an exit code is expressly setted . For example if i try to execute a script like:
    the output given by the activity is only 0 (like the exit code).
    This is a problem if i use a script with multiple exit codes corrisponding to different kind of situations and different outputs like the following:
    if($flag -eq "0")
       Write-output "Hello"
       exit 0
    elseif ($flag -eq "1")
       Write-output "Error 1"
       exit 1
    else
      Write-output "Error 2"
      exit 2
    or if i call an executable which exit codes i want to identify by a readable description.
    Anyone knows a way to solve this issue?
    Thanks a lot,
    bye.
    Giulio

    Thanks Shaun,
    i was already looking toward this kind of approch, but i was also curious if there was a different way of doing this.
    Anyway just a little annotation about your line of code, in Tidal 2.1.2 at least, Write-host doesn't work right, echo or Write-Output are fine but Write-host seems to be ignored. To the following script:
    the output is
    Maybe i'm missing something. Regarding an upgrade, as a devoloper i'd really like to try the improvement of the new version but this is not a decision I can make.
    Thank you,
    bye.
    Giulio

  • (Powershell script) Move Computer to Windows 8 OU based on prior OU set in OSD variable in OSD

    We have Windows 7 and Windows 8 machines that get configured through SCCM 2012 OSD. In my task sequence I have the computer joined to an OU based on the drop down selection. However I cannot write something into the javascript to put a computer into the
    sub ou labeled windows 8. I would like to write a powershell script that will put the computer into the sub OU based on what was selected earlier.
    Example: Computer is joined to Sales OU in our organization. There is a sub OU called Windows 8 under the Sales. If Sales is selected then it should join that subOU Windows 8.  Has anyone accomplished this task before? How would I write this? I have enclosed
    a photo of what my OSD looks like. Very simple. This hta exports the OSDDomainOU variable out and the apply network settings task sequence grabs it and joins it to the selected OU.

    I would use a switch statement and it would be something like this
    function Set-OSDVariable
    Param (
    [string]$OSDVariable,
    [string]$OSDVarValue
    $tsenv = New-Object -ComObject Microsoft.SMS.TSEnvironment
    $tsenv.Value($OSDVariable) = $OSDVarValue
    function Get-OSDVariable
    Param (
    [string]$OSDGetVar
    $tsenv = New-Object -ComObject Microsoft.SMS.TSEnvironment
    $tstOSDVar = $tsenv.Value("$OSDGetVar")
    return $tstOSDVar
    $osddomainou = Get-OSDvariable -OSDGetVar "osddomainouname"
    switch($osddomainou)
    "external" { Set-OSDVariable -OSDVariable "osdomainnameou" -OSDVarValue "win8 external ou" }
    The function included in the script above sets OSD Variables and I call it on the switch statement. Follow that format for the rest of the possible OU's. I've also included a function to get the variable too. 

  • SQL Server upgradation Issue : 2012 to 2014. A job step received an error at line 1 in a PowerShell script. The corresponding line is 'set-executionpolicy RemoteSigned -scope process -Force'. Correct the script and reschedule the job.

    Message
    Executed as user: CORPTST\XXXXX. A job step received an error at line 1 in a PowerShell script. The corresponding line is 'set-executionpolicy RemoteSigned -scope process -Force'. Correct the script and reschedule the job. The error information returned
    by PowerShell is: 'Security error.  '.  Process Exit Code -1.  The step failed.
    I receive this error during the sql server job 'syspolicy_purge_history' execution  when sql server got upgraded form SQL Server 2008 to 2014.

    Hi Vishnu,
    According to the error message, it also occurs in SQL Server 2012.  Here is a feedback about the error in the link below.
    https://connect.microsoft.com/SQLServer/feedback/details/754063/sql-server-2012-syspolicy-purge-history-job-step-3-fails-with-security-error
    To resolve this issue, please change the value of the following registry key from ‘RemoteSigned’ to ‘Unrestricted’. For more details, you can review this similar
    blog.
    HKLM\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.SqlServer.Management.PowerShell.sqlps120\ExecutionPolicy
    Thanks,
    Lydia Zhang

  • Can a powershell script be set to run once an email had been received from a certain address?

    Hello,
    I'm trying to see if a PowerShell script can be made to run once an email has been received from a given email address or with a certain subject.
    I came across this
    http://dmitrysotnikov.wordpress.com/2008/05/08/execute-powershell-scripts-from-your-smartphone/
    but I have not been able to get this to the run the script, only the transcript part seems to load. I have tried all suggestions but no luck.
    Has anyone been able to do such a thing? or know how?

    It is not PowerShell. It is VBA.  You need to post questions about VBA in the VBA forum.
    ¯\_(ツ)_/¯

  • Non-Script Way of Setting Visible Property

    Why hello there!
    I am looking to set the "visible" property of a movie clip in
    the Flash CS3 designer, as opposed to using AS3.
    In my movie, I set a movieclip to invisible in code
    immediately. However, I sometimes see the artefact of the image for
    a split-second on running the swf in my browser. I would therefore
    like to set the property in the designer.
    I am guessing that there is not a way of doing it. Are there
    any suggestions?
    I'm now considering setting the alpha value to 0 in designer,
    and then setting the alpha value to 1 in code when I need to be
    able to see the mc.
    Raffi.

    Hey kglad,
    I appreciate the prompt response. Sorry I wasn't clear enough
    in my initial message.
    I am simply looking to be able to set, say, a rectangle
    primitive to invisible without having to set in the code. At the
    moment, I am setting the visible property to false in the first
    frame in the code. However, as a result, I sometimes (not
    frequently) see artefacting when I run my movie. The rectangle very
    momentarily appears before disappearing.
    Raffi.

  • Setting the custom master page through powershell is NOT working

    Hi,
     I am writing the below code to set the  custom master page through powershell.
    But its not working .when i went to site settings-->master page --> in the drodown , the  maste page set is seattle.master ONLY, though my current master page is available in the dropdown.
     Can anyone pls help, whether i am missing in the below :
          Add-PSSnapin Microsoft.SharePoint.Powershell
           $SiteURL = "http://srvr1:22307/sites/SPW5"
        $weburl= $SiteURL
        $Site= Get-SPSite $SiteURL
        $web =  $Site.OpenWeb()
    $web.CustomMasterUrl = "/_catalogs/masterpage/myMasterpage.master"
    $web.MasterUrl = "/_catalogs/masterpage/myMasterpage.master"
    $web.Update()
    Das

    Hi,
    Is it a publishing page? If yes can you try the PowerShell scripts corresponding to the following code snippet?
    var publishingWeb = PublishingWeb.GetPublishingWeb(web);
    publishingWeb.CustomMasterUrl.SetInherit(inheritFromParent, false);
    publishingWeb.CustomMasterUrl.SetValue(masterPageUrl, false);
    publishingWeb.MasterUrl.SetInherit(inheritFromParent, false);
    publishingWeb.MasterUrl.SetValue(masterPageUrl, false);
    I've noticed sometime (not sure though) that Master page doesn't get updated if the inherit property is not updated first.
    Thanks,
    Sohel Rana
    http://ranaictiu-technicalblog.blogspot.com

  • PowerShell script : Directory object not found error in Get-ADGroupMember

    I am new in powershell scripting. I am writing a script to add users in different AD Groups. while doing so I do the following:
    Check if the user already exist in the group:
    $mbr_exist = Get-ADGroupMember $grpname | Where-Object {$_.SamAccountName -eq $sam}
    If user does not exist then add the user to the group.
    When I manually run the script its runs flawless, without any errors. But when I schedule the script to run it gives an error as follows:
    3/30/2015 8:32:15 AM Directory object not foundAt + $mbr_exist = Get-ADGroupMember $grpname | Where-Object {$_.SamAc ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~ Error at Line:$mbr_exist = Get-ADGroupMember
    $grpname | Where-Object {$_.SamAccountName -eq $sam}
    The strange thing is the user for which it throws the error is present in the group.I am not sure why this error is occurring when scheduled. Can any one please help? All the suggestions will be appreciated
    Note: (The script is scheduled using Windows Task Scheduler)
    try
    # # Initialize the variables we will use
    $status = 'false'
    $drivename = "H:"
    $sysdate = Get-Date -UFormat "%m_%d_%Y"
    $foldername = $drivename + "\Script_Result\PowershellData"+ $sysdate
    $backup_folder = "$foldername\AD_Groups_Backup"
    $updatedGroup = "$foldername\Updated_AD_Groups_LogFiles"
    $LogFilePath = "$foldername\Log_Update_ADGroups"+$sysdate+".log"
    # # Initialize the arrays we will use
    $GroupArray = @()
    # # maintain log of program startup
    $logdate = get-date
    $logdate.ToString() + "`tStarted script to Update AD user Groups..." | Out-File -FilePath $LogFilePath
    # # Create a sub folder to store the backup files
    $fileexist = Test-Path $backup_folder -PathType Container
    if($fileexist -ne 'False')
    New-Item -ItemType Directory $backup_folder
    # # Create a sub folder to store Updated AD group Log files
    $fileexist = Test-Path $updatedGroup -PathType Container
    if($fileexist -ne 'False')
    New-Item -ItemType Directory $updatedGroup
    # # Take back up of the AD groups data
    Get-ADGroupMember -Identity "Group1" | Export-csv "$backup_folder\Group1_BackUP$sysdate.csv"
    Get-ADGroupMember -Identity "Group2" | Export-csv "$backup_folder\Group1_BackUP$sysdate.csv"
    Get-ADGroupMember -Identity "Group3" | Export-csv "$backup_folder\Group1_BackUP$sysdate.csv"
    Get-ADGroupMember -Identity "Group4" | Export-csv "$backup_folder\Group1_BackUP$sysdate.csv"
    (an so on..... 11 such groups )
    # # Fetch AD Users data
    $ADusers = Get-ADUser -filter {(EmployeeNumber -gt 1) -and (EmployeeNumber -ne "N/A") -and (Enabled -eq $true)} -Properties * | Sort-Object -Property EmployeeNumber
    $ADusers.Count
    foreach($u in $ADusers)
    $sam = $u.SamAccountName
    $empnum = $u.EmployeeNumber
    $mgr = $u.mgr
    $fsal = $u.'fsalary-Hourly'
    $comp = $u.Company
    $ofc = $u.Office
    Write-Host "$sam : $empnum : $mgr :$fsal : $comp : $ofc" -ForegroundColor Yellow
    $GroupArray = @()
    # # Check if the user fits in any of the 11 scenarios
    if($comp -eq "US")
    # scenario 7
    write-host "7. Add to US Employees"
    $GroupArray += "US Employees"
    if($mgr -eq "Y")
    Write-Host "1. ADD to US MAnagers"
    $group = "US Managers"
    $GroupArray += $group
    if(($fsal -eq "Hourly") -and ($ofc -ne "Canton"))
    Write-Host "3. Add to US Hourly (excluding Canton)"
    $group = "US Hourly (excluding Canton)"
    $GroupArray += $group
    if(($fsal -eq "Hourly") -and ($ofc -eq "Canton"))
    write-host "4. Add to US Canton Hourly"
    $group = "US Canton Hourly"
    $GroupArray += $group
    if(($fsal -eq "Salaried") -and ($ofc -eq "Corporate" -or $ofc -eq "Landis Lakes 1" -or $ofc -eq "Landis Lakes 2"))
    Write-Host "5. Add to US Salaried Corporate"
    $group = "US Salaried Corporate"
    $GroupArray += $group
    if(($fsal -eq "Salaried") -and ($ofc -ne "Corporate" -and $ofc -ne "Landis Lakes 1" -and $ofc -ne "Landis Lakes 2"))
    Write-Host "6. Add to US Salaried Plant"
    $group = "US Salaried Plant"
    $GroupArray +=$group
    elseif($comp -eq "canada")
    # scenario 9
    write-host "9. Canada Employees"
    $GroupArray += "Canada Employees"
    if($mgr -eq "Y")
    Write-Host "2. Add to Canada Managers"
    $group = "Canada Managers"
    $GroupArray += $group
    if($fsal -eq "Hourly")
    Write-Host "10. Add to Canada Hourly"
    $group = "Canada Hourly"
    $GroupArray += $group
    if($fsal -eq "Salaried")
    Write-Host "11. Add to Canada Salaried Plant"
    $group = "Canada Salaried Plant"
    $GroupArray += $group
    elseif($ofc -eq "Corporate" -or $ofc -eq "Landis Lakes 1" -or $ofc -eq "Landis Lakes 2")
    Write-Host "8. Add to Corporate Employees"
    $GroupArray += "Corporate Employees"
    write-host "Final Group List" -ForegroundColor Green
    $grplen = $GroupArray.Length
    #$GroupArray
    $grplen
    for($i= 0; $i -lt $grplen; $i++)
    $grpname = $GroupArray[$i]
    write-host "$sam will be added to Group : $grpname" -ForegroundColor Magenta
    # # Check if the user is already present in the Group
    $mbr_exist = Get-ADGroupMember $grpname | Where-Object {$_.SamAccountName -eq $sam}
    if($mbr_exist -eq $null)
    # #Add user to US Managers group
    Add-ADGroupMember -Identity $grpname -Members $sam
    Write-Host "1. User $sam is added to $grpname group" -ForegroundColor Green
    # # documenting the user list that are added to this group
    $grpmbr = New-Object PSObject
    $grpmbr | Add-Member -MemberType NoteProperty -Name "EmployeeNumber" -Value $empnum
    $grpmbr | Add-Member -MemberType NoteProperty -Name "SamAccountName" -Value $sam
    $grpmbr | Add-Member -MemberType NoteProperty -Name "Name" -Value $u.Name
    $grpmbr | Add-Member -MemberType NoteProperty -Name "DistinguishedName" -Value $u.DistinguishedName
    $grpmbr | Add-Member -MemberType NoteProperty -Name "mgr" -Value $mgr
    $grpmbr | Add-Member -MemberType NoteProperty -Name "Company" -Value $comp
    $grpmbr | Add-Member -MemberType NoteProperty -Name "Salary/Hourly" -Value $fsal
    $grpmbr | Add-Member -MemberType NoteProperty -Name "Office" -Value $ofc
    $grpmbr | Add-Member -MemberType NoteProperty -Name "ADGroup" -Value $grpname
    $grpmbr | Export-Csv "$updatedGroup\ADUsers_To_Group($grpname)_$sysdate.csv" -Append -NoTypeInformation
    else
    Write-Host "Member $sam already exist in $grpname group" -ForegroundColor Red
    $logdate = get-date
    $logdate.ToString() + "`tCompleted script to Update Update AD Groups..." | Out-File -FilePath $LogFilePath -Append
    $status = 'true'
    return $status
    catch
    $err_lineno = $error[0].InvocationInfo.ScriptLineNumber
    $err_line = $error[0].InvocationInfo.Line
    $ExceptionMessage = $_.Exception.Message
    #$ExceptionMessage
    $error_info = $error[0].ToString() + $error[0].InvocationInfo.PositionMessage
    Write-Host "$error_info " -ForegroundColor Red
    $FailedItem = $_.Exception.ItemName
    if($ExceptionMessage)
    $logdate.ToString() + "`t $error_info " | out-file "$foldername\ErrorLog_Update_AD_Groups$sysdate.log" -append
    "Line Number: $err_lineno . `nError at Line: $err_line" | out-file "$foldername\ErrorLog_Update_AD_Groups$sysdate.log" -append
    #Invoke-Item "C:\ErrorLog.log"
    $status = 'false'
    return $status

    Hi mdkelly, Sorry for such a late reply (due to credential issues).
    I am using Windows task scheduler to schedule the task. I am given the administrator access to the server (Windows Server 2012). So I think I set to run the script under system account.
    My apologies for asking this, am I missing something while scheduling the script through task scheduler?  how to check if the scheduled task is running under who's credentials? How to pass my (admin) credentials, so that the script execution won't face
    a problem? Any suggestion on the above questions will be helpful. (I tried to search on net for the questions but didn't get any conclusive answers)  
    Thanks in advance.

  • Powershell Script - Convert Managed Metadata column Value to string

    HI,
    I have written a small PowerShell Script to pull records from a SP List and put them in a csv file. Here is the script:
    $MyWeb = Get-SPWeb "http://dev-apps:8800/applications/PA"
    $MyList = $MyWeb.Lists["Alist"]
    $exportlist = @()
    $Mylist.Items | foreach {
    $obj = New-Object PSObject -Property @{
    “PName” = $_["Port Name"]
    "AName" = $_["Agent Name"]
    "Address 1" = $_["Address 1"]
    "Address 2" = $_["Address 1"]
    "Address 3" = $_["Address 3"]
    "Address 4" = $_["Address 4"]
    $exportlist += $obj
    $exportlist | Export-Csv -path 'C:\Filename.csv'
    The script is running all right, the output file is also created, data is also correct for all columns but 1. This PName is a
    Managed metadata type column and the output values I am getting for this column are like this:
    "ERICA|a6d1e8fd-1f6b-4e09-9830-d21e35950881"
    "CLIVE|24dff17f-a1b5-4abe-ae86-57299e1e098b"
    viz. the ["Actual Value"|"its GUID"] (seems so). I do not want this GUID to be included in the result csv. Is there a way to remove it.
    P.S. Choice column values are being fetched just file.

    Try this (you'll need to add in your other properties)
    $items = New-Object psobject
    $items | Add-Member -MemberType NoteProperty -Name "AName" -value "" ;
    $items | Add-Member -MemberType NoteProperty -Name "PName" -value "" ;
    $items | Add-Member -MemberType NoteProperty -Name "Address1" -value "" ;
    $items | Add-Member -MemberType NoteProperty -Name "Address2" -value "" ;
    $items | Add-Member -MemberType NoteProperty -Name "Address3" -value "";
    $exportlist = @();
    $Mylist.Items | foreach {
    $pname = $_["PName"] -as [Microsoft.SharePoint.Taxonomy.TaxonomyFieldValue];
    $obj = $items | Select-Object *;
    $obj.AName = $_["AName"];
    $obj.PName = $pname.Label;
    $obj.Address1 = $_["Address 1"];
    $obj.Address2 = $_["Address 2"];
    $obj.Address3 = $_["Address 3"];
    $exportlist += $obj
    $exportlist | Export-Csv -path 'C:\AData.csv'
    Regards, Matthew
    MCPD | MCITP
    My Blog
    View
    Matthew Yarlett's profile
    See my webpart on the TechNet Gallery that allows administrative users to upload, crop and format user profile photos. Check it out here:
    Upload and Crop User Profile Photos

  • Powershell script to update mailbox search

    I am trying to update a mailbox search using a powershell script:
    Stop-MailboxSearch -Identity "LitHolds" -confirm:$false
    $members = (import-csv -Path "Path"| ForEach-Object{$_.SamAccountName})
    foreach ($user in $members)
    Set-MailboxSearch -Identity "LitHolds" -SourceMailboxes $user.samaccountname
    Start-MailboxSearch -Identity "LitHolds" -confirm:$false
    I essentially have our sysadmins populating a csv file and then they run this script manually every night with the latest updates.  They are telling me that the mailbox search is empty.
    When I run the script I am getting a watson error immediately after with the following:
    WARNING: An unexpected error has occurred and a Watson dump is being generated: Value cannot be null.
    Parameter name: legacyDN
    Value cannot be null.
    Parameter name: legacyDN
        + CategoryInfo          : NotSpecified: (:) [Stop-MailboxSearch], ArgumentNullException
        + FullyQualifiedErrorId : System.ArgumentNullException,Microsoft.Exchange.Management.Tasks.StopMailboxSearch
        + PSComputerName        : Exchange Server Name
    What I don't understand is why it's looking for a legacyDN??
    Anyone able to do something similar?
    Chuck

    Hi Chuck,
    I would like to verify if you have a legacy Exchange.
    The LegacyDN property indicates the legacyDN of the mailbox and matches the legacyExchangeDN attribute of the user object in  Microsoft Active Directory.
    If there is any update, please feel free to let me know.
    Best regards,
    Amy
    Amy Wang
    TechNet Community Support

  • Powershell script Information output in column instead of rows

    Dear All,
    I am required powershell script Information output  in column instead of rows.
    $usr= get-aduser -filter * | select sAMAccountName,homeDrive,TerminalServicesProfilePath,homeDirectory,physicalDeliveryOfficeName,userAccountControl,displayName,l,mail, profilepath
    $myarray = @()
    Foreach($usr1 in $usr)
    $userDN = (Get-ADUser $usr1.samaccountname).distinguishedName
    $userInfo = [ADSI]"LDAP://$userDN" | select sAMAccountName,homeDrive,TerminalServicesProfilePath,homeDirectory,physicalDeliveryOfficeName,userAccountControl,displayName,l,mail, profilepath
    $ts=$userInfo.TerminalServicesProfilePath
    $sn=$userInfo.samaccountname
    $hm=$userinfo.homeDrive
    $hd=$userinfo.homeDirectory
    $pd=$userinfo.physicalDeliveryOfficeName
    $ua=$userinfo.userAccountControl
    $dp=$userinfo.displayName
    $ll=$userinfo.l
    $ml=$userinfo.mail
    $pp=$userinfo.profilepath
    $myarray += New-Object psobject -Property @{
        Sam = $userInfo.samaccountname
        TerminalServicesProfilePath = $userInfo.TerminalServicesProfilePath
      homeDrive = $userinfo.homeDrive
        homeDirectory=$userinfo.homeDirectory
        physicalDeliveryOfficeName=$userinfo.physicalDeliveryOfficeName
        userAccountControl=$userinfo.userAccountControl
        displayName=$userinfo.displayName
         l=$userinfo.l
         mail=$userinfo.mail
         profilepath=$userinfo.profilepath
    $myarray |fl
    $myarray | Out-File "c:\final.txt"

    Hey this is such a sweet small script compared to everything else out there and I guess you can edit it to return any value you wish. One LARGE problem however: the TerminalServicesProfilePath comes back empty on all accounts regardless of whether the field
    is populated or not. This is basically because this setting is not stored in an Active Directory attribute but Terminal Services information is stored in the userParameters schema attribute as a BLOB.
    I got this script:
    $Users = ([ADSISearcher]"(&(objectCategory=person)(objectClass=user))").findall() | select path
    foreach ($user in $users) {
    $userSearch = [adsi]"$($user.path)"
    # get logon name
    $userSearch.psbase.InvokeGet(“SamAccountName”)
    # Profile Attributes
    $userSearch.psbase.InvokeGet("ProfilePath")
    # Remote Desktop Services Attributes
    $userSearch.psbase.InvokeGet("TerminalServicesProfilePath")
    which returns the value but the output is terribly unformatted. If we could integrate the two to ensure that it is correctly formatted, AND returns the TSProfile that would be awesome!
    Can anyone help me do that?
    Life is dangerous, no one has ever survived. So enjoy!
    Please do not tag an unrelated quesiton onto the end of an old and answered question.  Please read the forum guidelines before posting.
    We do not do custom scripts on demand.
    ¯\_(ツ)_/¯

  • Powershell script to get Site Collection. Site Owner, Title

    Hi,
    I am new to SharePoint, currently I have given one task to create the powershell script which contains the below fields from our two farms. Could you please help me out with the same.
    The script to list out below items:
    Site Collections:
    Site Collection Name:
    Site Collection Owners:
    Last Activity and the size of site collections.
    Many Thanks & Best Regards,
    Naren

    To get all Site Collections:
    If all you want is a list of all site collections in the farm, all you have to do is open a PowerShell window, load the SharePoint Snapin, if you haven't (Add-PSSnapin
    Microsoft.SharePoint.PowerShell), and type Get-SPSite.
    If you want to return the list of site collections for a specific web application, the easiest way is to just pipe it as Get-SPWebApplication
    http://intranet | Get-SPSite
    To get Site Collection Owners:
    Add-PSSnapin "Microsoft.SharePoint.Powershell" -ErrorAction SilentlyContinue
    Get-SPWebApplication "http://mySharePointSite.com"|
    Get-SPSite| foreach-object{ Write-host$_.Url - $_.Owner.Email}
    To get Size of all Site Collections:
    Get-SPSite | select url, @{label"Size in MB";Expression={$_.usage.storage/1MB}} | Sort-Object
    -Descending -Property "Size in MB" | ConvertTo-Html -title "Site Collections sort by size" | Set-Content sc.html
    Regrading the retrieving the last activity I am not sure to what exactly you are looking for but I assume you are concern about getting users last logon time and date using PowerShell.
    For this refer here: Get Users Last Logon Time and Date using PowerShell
    Please remember to upvote if it helps you or
    click 'Mark as Answer' if the reply answers your query.

Maybe you are looking for