Getting Dimensions of images in a folder using Power Shell

I have a folder with several thousand images. I am hoping to list the images with the dimensions for each image.
I found this link that gets me some info, but I wasn't completely successful with it:
http://www.sapien.com/forums/scriptinganswers/forum_posts.asp?TID=3059&PID=17205
TimA

Function Get-Image
begin{
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") |Out-Null
process{
$fi=[System.IO.FileInfo]$_
if( $fi.Exists){
$img = [System.Drawing.Image]::FromFile($_)
$img.Clone()
$img.Dispose()
}else{
Write-Host "File not found: $_" -fore yellow
end{}
dir "C:\*.jpg" -Recurse | % {
$image = $_ | Get-Image
New-Object PSObject -Property @{
File = $_.name
Fullname = $_.Fullname
Height = $image.Height
Width = $image.Width
Oliver Lipkau
[PowerShell enthusiast]
http://oliver.lipkau.net/blog

Similar Messages

  • Get the web part properties of documeny lib view web part using power shell

    Hi,
    Am looking to get the propeties of a list view web part - a document library's  list view web  part- using PowerShell
    Manually I am able to do the same: the steps followed by me is given below:
    1) I went to the
    http://srvr1:123/sites/enggtest/mydoclib1/forms/allitems.aspx
    2) Edit the page
    3) Edit the  mydoclib1 view web part
    4) go to the peroperties
    5) Check the Server Render checkbox
    is there   anyway i can do this using power shell.

    The code below assumes that the webpart is at index 0:
    $SiteUrl = "http://aissp2013/sites/TestSite/"
    $pageURL = "http://aissp2013/sites/TestSite/Lists/MyList/AllItems.aspx"
    $web = Get-SPWeb $SiteUrl
    $wpm = $web.GetLimitedWebPartManager($pageURL, [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
    $wp = $wpm.WebParts[0]
    $wp.ServerRender = $true
    $wpm.SaveChanges($wp)
    Blog | SharePoint Learnings CodePlex Tools |
    Export Version History To Excel |
    Autocomplete Lookup Field

  • How to get site permissions using power shell ?

    Hello,
    I require to get list of granted permissions ( Group/users ) which we see from Site Actions > Site Permissions.
    would you please let me know how can I fetch the same using power shell ?
    Thanks and Regards,
    Dipti Chhatrapati

    Hello,
    I have found the same using following script :
    if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) { 
    Add-PSSnapin "Microsoft.SharePoint.PowerShell" 
    #Define variables 
    $site = Get-SPSite "Site collection URL"
    #Get all subsites for site collection 
    $web = $site.AllWebs
    #Loop through each subsite and write permissions
    foreach ($web in $web) 
    if (($web.permissions -ne $null) -and ($web.hasuniqueroleassignments -eq "True")) 
    Write-Output "****************************************" 
    Write-Output "Displaying site permissions for: $web" 
    $web.permissions | fl member, basepermissions 
    elseif ($web.hasuniqueroleassignments -ne "True") 
    Write-Output "****************************************" 
    Write-Output "Displaying site permissions for: $web" 
    "$web inherits permissions from $site" 
    Write-Host "Finished." 
    $site.dispose() 
    $web.dispose()
    Hope it helps others !
    Thanks and Regards,
    Dipti
    Dipti Chhatrapati

  • Add or delete the summary links web part's[deployed as a VS solution] link using power shell

    hi,
     i am having a visual studio custom solution having page layouts implemented. In that solution i am having 1  summary links web part and in that i have hard coded few links and this is  deployed on ion dev and staging env.
    Now, the issue is : yesterday, customer came to me and asking me to change the links from http://abc to
    http://xyz/ in this summary links. can anyone pls throw some light,such that i can change this link using a power shell script. i know  if i go the VS solution and change the link and redeploy [ update-spsolution
    command] will work.
    but if the links are changing regularly , chnaging the vs solution and redeploying is not a good practice.
    if i elaborate li'l bit,  i am adding the screen shot : i need to get the summary link column's value and  need to update[ delete xisting one and  add new ones ]
    is there any way , i can change the links using power shell script?
    i tried the belwo power shells cript to get the page in the page layouts :
    $web = get-spweb
    "http://siteurl"
    $pubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
    $pagesListName = $pubWeb.PagesListName
    $defaultAspxFile = $pubWeb.GetPublishingPage("$pagesListName/mycustomhome.aspx")
    $summaryLinkFieldValue = New-Object
    Microsoft.SharePoint.Publishing.Fields.SummaryLinkFieldValue
    // here am getting the NULL VALUE
    can i get the  summary links field correctly and  delete / modify the same?
    help is appreciated!
    ##$groupLink = New-Object
    Microsoft.SharePoint.Publishing.SummaryLink("My group")
    #$groupLink.IsGroupHeader = $true $summaryLinkFieldValue.SummaryLinks.Add($groupLink)

    Hi Shabeaut,
    Could you tell us why do you want to add a link web part to the master page for all pages?
    I tested that Summary Links web part (and other types of web parts) added in the master page under Quick Launch couldn't be edited when I edit the pages inherited from v4.master page, it looks by design.
    Have you tried using the Quick Launch to add the link instead if you want to show links in all pages.
    Thanks
    Daniel Yang
    TechNet Community Support

  • Deploy wsp through Power Shell- start stop SP admin service and run execadmsvcjobs command using power shell

    Hi,
     Can anyone pls point me any link/ src code  for  deplyoing wsp using power shell. I know I can deploy it through Add-spsolution and install-spsolution, the issue is that, it will give   "status - stuck in deploying scheduled..."
    and i need to restart the sharepoint services - services.msc --> SP administration and timer services - and then i need to run the exceadmsvcjobs command to deploy / update the wsp  successfully in solution store.
    i mean, whats the power shell equivalent of these tasks. or anyone has already scripted these.
    if i elaborate little bit, would like to know how to automatically Retract, Remove, Add and Deploy SharePoint 2010 WSP Solution Files with PowerShell

    ok, i have found  the same :
     here its : hope this will help someone.
    function wait4timer($solutionName)
    $solutionName ="TestingWSP.wsp"
    $solution = Get-SPSolution | where-object {$_.Name -eq $solutionName}
    if ($solution -ne $null)
    Write-Host "Waiting to finish soultion timer job" -ForegroundColor Green
    while ($solution.JobExists -eq $true )
    Write-Host "Please wait...Either a Retraction/Deployment is happening" -ForegroundColor DarkYellow
    sleep 5
    Write-Host "Finished the solution timer job" -ForegroundColor Green
    try
    # Get the WebApplicationURL
    $MyWebApplicationUrl = "http://srvr:21778/";
    # Get the Solution Name
    $MywspName = "TestingWSP.wsp"
    # Get the Path of the Solution
    $MywspFullPath = "D:\myWorkspace\TestingWSP.wsp"
    # Try to get the Installed Solutions on the Farm.
    $MyInstalledSolution = Get-SPSolution | Where-Object Name -eq $MywspName
    # Verify whether the Solution is installed on the Target Web Application
    if($MyInstalledSolution -ne $null)
    if($MyInstalledSolution.DeployedWebApplications.Count -gt 0)
    wait4timer($MywspName)
    # Solution is installed in atleast one WebApplication. Hence, uninstall from all the web applications.
    # We need to unInstall from all the WebApplicaiton. If not, it will throw error while Removing the solution
    Uninstall-SPSolution $MywspName -AllWebApplications:$true -confirm:$false
    # Wait till the Timer jobs to Complete
    wait4timer($MywspName)
    Write-Host "Remove the Solution from the Farm" -ForegroundColor Green
    # Remove the Solution from the Farm
    Remove-SPSolution $MywspName -Confirm:$false
    sleep 5
    else
    wait4timer($MywspName)
    # Solution not deployed on any of the Web Application. Go ahead and Remove the Solution from the Farm
    Remove-SPSolution $MywspName -Confirm:$false
    sleep 3
    wait4timer($MywspName)
    # Add Solution to the Farm
    Add-SPSolution -LiteralPath "$MywspFullPath"
    # Install Solution to the WebApplication
    #Install-SPSolution -Identity <SolutionName> -WebApplication <URLName> [-GACDeployment] [-CASPolicies]
    install-spsolution -Identity $MywspName -WebApplication $MyWebApplicationUrl -GACDeployment #-FullTrustBinDeployment:$true -GACDeployment:$false -Force:$true
    # Let the Timer Jobs get finishes
    wait4timer($MywspName)
    Write-Host "Successfully Deployed to the WebApplication" -ForegroundColor Green
    catch
    Write-Host "Exception Occuerd on DeployWSP : " $Error[0].Exception.Message -ForegroundColor Red
    ref :
    http://www.sharepointpals.com/post/How-to-Deploy-a-SharePoint-2013-Solution-(WSP)-in-the-Farm-using-PowerShell

  • Activate design manager (sandbox) solution using power shell - SP2013

    Hi All,
    I have a  design manager (sandbox) solution and deployed in site collection. I am trying to upload the new version using power shell.
    Uninstall-SPUserSolution , Remove-SPUserSolution, Add-SPUserSolution and finally doing Install-SPUserSolution on that time i am getting the following error " Install-SPUserSolution : This file may not be moved, deleted,
    renamed, or otherwise edited." kindly help me for this issue.
    Regards,
    Santhosh

    Can you please provide more details on your solution package? Did you use SharePoint Design Manager to create design package? If that is the case then if you read the following article it reads and 
    "In SharePoint 2013 you cannot uninstall an imported design package, and you should never attempt to deactivate a design package through the solution gallery." 
    I think if you read the article it might be helpful.
    http://msdn.microsoft.com/en-us/library/jj862342.aspx
    Amit

  • Programmatically create SPGroups using power shell

    hi,
     I wanna create sp groups  programmatically using power shell,
    can anyone pls point me in the right direction.
    i have gone through this code:
    $GroupName = "mygrp1"
    $owner =""
    $member =""
    $Description =""
     $SPWeb.SiteGroups.Add($GroupName, "", "","")
     $SPGroup = $SPWeb.SiteGroups[$GroupName]
     $SPWeb.RoleAssignments.Add($SPGroup)
     $SPWeb.Dispose() 
    just wanted to know whether should i add few code  related with sproleassignments/ sproeldefintions etc we used to do in SP OM through c#
    help is appreciated!

    There are two parts.
    1. Adding a group to the site collection.
    2. assigning permissions to the group.
    The PS script given below first ensures if the group exists or not and then executes the logic. If the group already exists, then it will not add group the site. I would recommed to test it in Dev environment and then use in Prod.
    $site=Get-SPSite $siteCollectionUrl
    $rootSite=$site.RootWeb
    $member=$rootSite.Users["User_Name"]
    $user=$rootSite.Users["Other_User_Name"]
    try
    $grp=$rootSite.SiteGroups["Group Name"]
    catch
    if($grp -eq $null)
    $rootSite.SiteGroups.Add("Group Name",$member, $user, "Group Description")
    $grp=$rootSite.SiteGroups["Group Name"]
    $roleDef=$rootSite.RoleDefinitions.GetByType([Microsoft.SharePoint.SPRoleType]::Contributor)
    $roleAssigns=New-Object -TypeName Microsoft.SharePoint.SpRoleAssignment -ArgumentList $grp
    $roleAssigns.RoleDefinitionBindings.Add($roleDef)
    $rootSite.RoleAssignments.Add($roleAssigns)
    $rootSite.Update()
    Pradip T. ------------- MCTS(SharePoint 2010/Web)|MCPD(Web Development) https://www.mcpvirtualbusinesscard.com/VBCServer/paddytakate/profile

  • New-CMGlobalCondition unable to create New script Condition using Power Shell

    I am using config Manger 2012 and trying to use power shell cmdlet to create a new Global Condition using PowerShell but its not working for me using this
    Do not understand how to use that command any idea.
    New-CMGlobalCondition -DataType Boolean -DeviceType Windows -FilePath file.ps1 -Name test -ScriptLanguage PowerShell
    Error comes as 
    New-CMGlobalCondition : No object corresponds to the specified parameters.
    At line:1 char:1
    + New-CMGlobalCondition -DataType Boolean -DeviceType Windows -FilePath file.ps1 - ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (Microsoft.Confi...onditionCommand:NewGlobalConditionCommand) [New-CMGlobalCondition], I 
       temNotFoundException
        + FullyQualifiedErrorId : ItemNotFound,Microsoft.ConfigurationManagement.Cmdlets.AppModel.Commands.NewGlobalConditionCommand

    Hi,
    What's your version of SCCM? I ran this command line on SCCM 2012 R2 CU2.
    It seems SCCM 2012 R2 CU2 fixed New-CMGlobalCondition cmdlet issue.
    "The New-CMGlobalCondition cmdlet incorrectly requires use of the
    -WhereClause parameter."
    Description of Windows PowerShell changes in Cumulative Update 2 for System Center 2012 R2 Configuration Manager
    Best Regards,
    Joyce

  • Create & Start UPS Service Using Power-Shell in SharePoint 2013

    I want to know that is there a way to create a User Profile Synchronization Service using Power-Shell in a SharePoint 2013 Enterprise site? If so then how am I supposed to do that and start the User Profile Synchronization Service using the Power-Shell.
    I'm seeking this help because the UPS service is stuck in Starting and both FIM Services are also not started but they are in Automatic start mode.
    Could someone try to solve this matter.
    Thanks,
    regards,
    Chiranthaka

    start it from powershell will not help you resolve the issue.
    Try below articles:
    http://myspexp.com/2011/04/28/user-profile-synchronization-servicehangs-on-starting-i-fixed-it/
    troubleshoot this issue:http://www.harbar.net/articles/sp2010ups2.aspx
    http://www.sharepointdiary.com/2012/09/user-profile-synchronization-service-stuck-at-starting.html#ixzz2aXArH7zX

  • Using Power shell script how to hidden SharePoint existing features.

    Hi Firends,
    Using Power shell script how to hidden SharePoint existing features.
    Please help me.
    Thanks,
    Tiru
    Tiru

    The Hidden property is set within the solution, so you would need access to the source code in order to set it.
    Trevor Seward
    Follow or contact me at...
    &nbsp&nbsp
    This post is my own opinion and does not necessarily reflect the opinion or view of Microsoft, its employees, or other MVPs.

  • How to get latest added file from a folder using apple script

    Hi..
    I am trying to get a latest added file from a folder..and for this i have below script
    tell application "Finder"
        set latestFile to item 1 of (sort (get files of (path to downloads folder)) by creation date) as alias
        set fileName to latestFile's name
    end tell
    By using this i am not able to get latest file because for some files the creation date is some older date so is there any way to get latest file based on "Date Added" column of a folder.

    If you don't mind using GUI Scripting (you must enable access for assistive devices in the Accessibility System Preference pane), the following script should give you a reference to the last item added to any folder. Admittedly not the most elegant solution, but it works, at least under OS X 10.8.2.
    set theFolder to choose folder
    tell application "Finder"
        activate
        set theFolderWindow to container window of theFolder
        set alreadyOpen to exists theFolderWindow
        tell theFolderWindow
            open
            set theInitialView to current view
            set current view to icon view
        end tell
    end tell
    tell application "System Events" to tell process "Finder"
        -- Arrange by None:
        set theInitialArrangement to name of menu item 1 of menu 1 of menu item "Arrange By" of menu 1 of menu bar item "View" of menu bar 1 whose value of attribute "AXMenuItemMarkChar" is "✓"
        keystroke "0" using {control down, command down}
        -- Sort by Date Added:
        set theInitialSortingOrder to name of menu item 1 of menu 1 of menu item "Sort By" of menu 1 of menu bar item "View" of menu bar 1 whose value of attribute "AXMenuItemMarkChar" is "✓"
        keystroke "4" using {control down, option down, command down}
        -- Get the name of the last item:
        set theItemName to name of image 1 of UI element 1 of last scroll area of splitter group 1 of (window 1 whose subrole is "AXStandardWindow")
        -- Restore the initial settings:
        click menu item theInitialSortingOrder of menu 1 of menu item "Sort By" of menu 1 of menu bar item "View" of menu bar 1
        click menu item theInitialArrangement of menu 1 of menu item "Arrange By" of menu 1 of menu bar item "View" of menu bar 1
    end tell
    tell application "Finder"
        set current view of theFolderWindow to theInitialView -- restore the initial view
        if not alreadyOpen then close theFolderWindow
        set theLastItem to item theItemName of theFolder
    end tell
    theLastItem
    Message was edited by: Pierre L.

  • How to view images from Pictures Folder using iPhoto?

    Right now when I click an image in the Pictures folder, the image is automatically opened using Preview. I want to view images directly from my Pictures folder, and have them open to iPhoto. Is that possible?
    I just want to be able to view/sort my photos by Folders rather than by Events, Titles or Photo dates. I can't seem to get them to sort by folders in iPhoto.

    Iphoto is a Photo Database designed to allow you to organise and manipulate you photos without recourse to your files.
    It's not an image viewer, it can only work with photos that have been imported to the database.
    I just want to be able to view/sort my photos by Folders rather than by Events,
    An Event is a folder of images with a fancy icon. You can organize your pics in iPhoto anyway you want, using Albums, folders, keywords and so on. It's far more flexible that using folders in the Finder.
    You can opt to organise the files yourself, rather than have iPhoto do it for you, but I don't recommend it.
    Simply go to iPhoto Menu -> Preferences -> Advanced and uncheck 'Copy Files to the iPhoto Library on Import'.
    Now iPhoto will not copy the files, but rather simply reference them on your HD. To do this it will create an alias in the Originals Folder that points to your file. It will still create a thumbnail and, if you modify the pics, a Modified version within the iPhoto Library Folder.
    However, you need to be aware of a number of potential pitfalls using this system.
    1. Import and deleting pics are more complex procedures
    2. You cannot move or rename the files on your system or iPhoto will lose track of them on systems prior to 10.5 and iPhoto 08. Even with the later versions issues can still arise if you move the referenced files to new volumes or between volumes.
    3. Most importantly, migrating to a new disk or computer can be much more complex.
    Always allowing for personal preference, I've yet to see a good reason to run iPhoto in referenced mode unless you're using two photo organisers.
    If disk space is an issue, you can run an entire iPhoto Library from an external disk:
    1. Quit iPhoto
    2. Copy the iPhoto Library as an entity from your Pictures Folder to the External Disk.
    3. Hold down the option (or alt) key while launching iPhoto. From the resulting menu select 'Choose Library' and navigate to the new location. From that point on this will be the default location of your library.
    4. Test the library and when you're sure all is well, trash the one on your internal HD to free up space.
    If you're concerned about accessing the files, There are many, many ways to access your files in iPhoto:
    *For Users of 10.5 and later*
    You can use any Open / Attach / Browse dialogue. On the left there's a Media heading, your pics can be accessed there. Command-Click for selecting multiple pics.
    Uploaded with plasq's Skitch!
    You can access the Library from the New Message Window in Mail:
    Uploaded with plasq's Skitch!
    *For users of 10.4 and later* ...
    Many internet sites such as Flickr and SmugMug have plug-ins for accessing the iPhoto Library. If the site you want to use doesn’t then some, one or any of these will also work:
    To upload to a site that does not have an iPhoto Export Plug-in the recommended way is to Select the Pic in the iPhoto Window and go File -> Export and export the pic to the desktop, then upload from there. After the upload you can trash the pic on the desktop. It's only a copy and your original is safe in iPhoto.
    This is also true for emailing with Web-based services. However, if you're using Gmail you can use iPhoto2GMail
    If you use Apple's Mail, Entourage, AOL or Eudora you can email from within iPhoto.
    If you use a Cocoa-based Browser such as Safari, you can drag the pics from the iPhoto Window to the Attach window in the browser.
    *If you want to access the files with iPhoto not running*:
    For users of 10.6 and later:
    You can download a free Services component from MacOSXAutomation which will give you access to the iPhoto Library from your Services Menu. Using the Services Preference Pane you can even create a keyboard shortcut for it.
    For Users of 10.4 and later:
    Create a Media Browser using Automator (takes about 10 seconds) or use this free utility Karelia iMedia Browser
    Other options include:
    1. *Drag and Drop*: Drag a photo from the iPhoto Window to the desktop, there iPhoto will make a full-sized copy of the pic.
    2. *File -> Export*: Select the files in the iPhoto Window and go File -> Export. The dialogue will give you various options, including altering the format, naming the files and changing the size. Again, producing a copy.
    3. *Show File*: Right- (or Control-) Click on a pic and in the resulting dialogue choose 'Show File'. A Finder window will pop open with the file already selected.
    You can set Photoshop (or any image editor) as an external editor in iPhoto. (Preferences -> General -> Edit Photo: Choose from the Drop Down Menu.) This way, when you double click a pic to edit in iPhoto it will open automatically in Photoshop or your Image Editor, and when you save it it's sent back to iPhoto automatically. This is the only way that edits made in another application will be displayed in iPhoto.
    Regards
    TD

  • I get an 'Invalid Image Type' error when using the Locate Features. (Evaluatio​n version)

    I'm using the Evaluation Version of Vision Builder. I Simulate Acquisition using my own image (jpg), which loads fine. However, when I try to use any of the Inspection Steps features, other than Enhance Images, I get an "Invalid Image Type" error.

    Hello,
    Vision Builder functions usually work with a certain image type. For example, all the functions listed under Binary (in the menubar) will only work with binary images. Likewise, color functions will work for color images and grayscale will work for grayscale images.
    You can convert a color image into a grayscale by extracting a color plane and a grayscale image can be converted to binary using the threshold function.
    Hope this helps!
    Regards,
    Yusuf C.
    Applications Engineering
    National Instruments

  • Remote managment Exchange 2013 SP1 from C# code using Power-Shell.

    Hello,
    Sorry if I am describing something wrong, but it is first time I am using Microsoft development forum.
    I am trying to built library that will manage Exchange remotely using  C# code (VS 2012) and Power-Shell ver.4.0. My workstation and the actual Exchange server physically placed in different domains. In order to test functionalities I am using
    user that is member of all administrating and management groups in the appropriative domain. Remote Power-Shell is enabled on Exchange.
    In order to connect to the Service I am using that part of code :
    internal static bool RedirectionUrlValidationCallback(string redirectionUrl)
    bool result = false;
    var redirectionUri = new Uri(redirectionUrl);
    if (redirectionUri.Scheme.Equals("https"))
    result = true;
    return result;
    internal static ExchangeService ConnectToService(ExchangeVersion version,
    string userName,
    string emailAddress,
    string password,
    string domainName,
    ref Uri autodiscoverUrl)
    ExchangeService service;
    try
    service = new ExchangeService(version);
    service.Credentials = new WebCredentials(userName, password, domainName);
    if (autodiscoverUrl.IsNull())
    var ads = new AutodiscoverService();
    // Enable tracing.
    ads.TraceEnabled = true;
    // Set the credentials.
    ads.Credentials = service.Credentials;
    // Prevent the AutodiscoverService from looking in the local Active Directory
    // for the Exchange Web Services Services SCP.
    ads.EnableScpLookup = false;
    // Specify a redirection URL validation
    //callback that returns true for valid URLs.
    ads.RedirectionUrlValidationCallback = RedirectionUrlValidationCallback;
    // Get the Exchange Web Services URL for the user’s mailbox.
    var response = ads.GetUserSettings(emailAddress, UserSettingName.InternalEwsUrl);
    // Extract the Exchange Web Services URL from the response.
    autodiscoverUrl = new Uri(response.Settings[UserSettingName.InternalEwsUrl].ToString());
    // Update Service Url
    service.Url = autodiscoverUrl;
    else
    service.Url = autodiscoverUrl;
    catch (FormatException fe) // The user principal name(email) is in a bad format. UPN format is needed.
    LoggingFactory.LogException(fe);
    return null;
    catch (AutodiscoverLocalException ale)
    LoggingFactory.LogException(ale);
    return null;
    catch (Exception e)
    LoggingFactory.LogException(e);
    return null;
    return service;
    Then I am trying to reach existing mailbox of that user, using this part of code :
    try
    var runSpace = getRunspace();
    var pwShell = PowerShell.Create();
    pwShell.Runspace = runSpace;
    var command = new PSCommand();
    command.AddCommand("Get-Mailbox");
    command.AddParameter("Identity", userPrincipalName);
    command.AddParameter("RecipientTypeDetails", recipientType);
    pwShell.Commands = command;
    var result = pwShell.Invoke();
    if (result.IsNotNull() && result.Any())
    // TODO : fill appropriative DTO and return it.
    else
    // TODO : send back appropriative error.
    closeRunSpace(runSpace);
    catch (Exception e)
    // TODO : log the exception and send back appropriative error.
    private Runspace getRunspace()
    var runSpaceConfig = RunspaceConfiguration.Create();
    var runSpace = RunspaceFactory.CreateRunspace(runSpaceConfig);
    PSSnapInException snapEx;
    var psInfo = runSpaceConfig.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.E2010", out snapEx);
    runSpace.Open();
    return runSpace;
    private void closeRunSpace(Runspace runSpace)
    runSpace.Close();
    runSpace.Dispose();
    With this part I had problem. I received exception that appropriative Snap-in is not installed on my computer. I had no installation disk of Exchange in order to install Management Tool (as I understand this is the way to add needed part) so I changed run
    space activation to that part of code :
    private Runspace getRunspace()
    var newCredentials = (PSCredential)null;
    var connectionInfo = new WSManConnectionInfo(new Uri("http://exchange.domainname.local/powershell?serializationLevel=Full"),
    "http://schemas.microsoft.com/powershell/Microsoft.Exchange",
    newCredentials);
    connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Kerberos;
    var runSpace = RunspaceFactory.CreateRunspace(connectionInfo);
    runSpace.Open();
    return runSpace;
    Now I am receiving exception :
    "Connecting to remote server exchange.domainname.local failed with the following error message :
    [ClientAccessServer=exchange,BackEndServer=exchange.domainname.local,RequestId=....,TimeStamp=...]
    Access is denied. For more information, see the about_Remote_Troubleshooting Help topic."
    Please help me to understand what I am doing wrong.
    Thank you.
    Alexander.

    In Exchange 2010 you should be using Remote Powershell not local powershell and the snap-in.  Here is a sample that may help you:
    http://blogs.msdn.com/b/dvespa/archive/2009/10/22/how-to-call-exchange-2010-cmdlet-s-using-remote-powershell-in-code.aspx

  • Using power shell function and SQL Table

    I have a table holding file path of over 1 million documents. so like column one is documentID and column two is full file path.
    Now, I want to get the file size of each of the documents. I have a function in power shell that gets the size of a file given file path.
    My problem, is I do not know how to use that function and the table to get the size of each of the files(documents).
    Help Much Appreciated!!
    ebro

    I am not clear with your questions sir. Do you mean the category this question belongs too? If so, may be some body could help redirect the question to the appropriate place.
    So what category does this belong too CM12 or Powershell?
    http://www.enhansoft.com/

Maybe you are looking for