I need a PowerShell (v2) script to read or copy files from a SharePoint library resident on a remote SharePoint server. The twist is, I need to filter on the last modified date of the file(s). Also, the server running the script does not have SharePoint installed.
Here's what I've tried:
Get-ChildItem using the UNC path of the SP file with LastWriteTime filter. I encountered latency issues with this. It runs fine if I've recently opened the document library in the web. But when scheduled to run on its own, the read consistently fails (cannot find file).
Copying the files with the script below. Problem is that the modified date is lost when it's copied to the target machine. The date added/modified is now the copy date.
$target = "http://myspweb.com/myfile.xlsx"
$dest = "D:\library\newfile.xlsx"
$wc = New-Object System.Net.WebClient
$wc.UseDefaultCredentials = $true
$wc.DownloadFile($target, $dest)
Using the Get-SPWeb command. Allegedly, this exposes properties of the files, including last modified date, but seems to require that the server running the script have SharePoint installed (Add-PSSnapin Microsoft.Sharepoint.Powershell gives a "not installed on this machine" error.) A full SharePoint installation isn't really an option -- nor is remoting. Some installation of SP tools might be an option, but I can't figure out what would be required.
Any other ways to approach this?
What you can't do (server-side object model)
The Get-SPWeb cmdlet can only be used from one of the web front end servers that are actually running SharePoint as part of your SharePoint farm, so if you don't have access to log in to the server, that option is right out.
What you can do (web services)
Alternatively, SharePoint exposes web services that you can use to access SharePoint data (including column data) from a remote server.
The available web services vary depending on which version of SharePoint you are using.
The Lists Web Service
The SharePoint 2010/2013 Lists.asmx web service can be accessed if you're willing to compose your own SOAP calls. You can refer to this answer for an example that uses Powershell. Refer to the official documentation here.
You can either format your query so that it only returns results with a certain modified date (using CAML query syntax), or you can return all the results and process them in Powershell to select the ones you care about.
The REST API
SharePoint 2013 also has a REST-based web service you can use. (Technically, SharePoint 2010 does as well, but it's a bit half-baked.) Here's an example using Powershell and the REST API: https://gallery.technet.microsoft.com/office/How-to-Get-all-the-Lists-a0af6259
Related
On Windows Server 2012 Datacenter with Microsoft Dynamics CRM 2016 installed, I want to run a deployment command but for every commands I get this error: "(500) Internal Server Error".
I first run this:
Add-PSSnapin Microsoft.Crm.PowerShell
and it will work fine and when I check it with get-pssnapin and Get-Help *Crm*, every thing is fine and every thing that I need is registered. but when I want to run a cmdlets command like these, I face the error: Get-CrmSetting or Get-CrmCertificate or ...
For example for Get-CrmSetting TraceSettings it give me this error:
How can I solve this problem and error?
Thanks
According to this article, you might want to try:
Get-CrmSetting –SettingType TraceSettings
Here are a couple more items to investigate, from this article:
To use the XRM tooling cmdlets, you need PowerShell version 3.0 or
later. To check the version, open a PowerShell window and run the
following command: $Host
Set the execution policy to run the signed PowerShell scripts. To do
so, open a PowerShell window as an administrator and run the
following command: Set-ExecutionPolicy -ExecutionPolicy AllSigned
Verify the (CRMDeploymentServiceAppPool Application Pool identity) has SQL SEVER SysAdmin permission. This is needed to perform any CRM configuration changes and organizational operations.
Note: it does not matter if the account executing the PowerShell is a system admin or SQL server sysadmin because these operations are executed via the deployment web service.
Deployment Web Service (CRMDeploymentServiceAppPool Application Pool identity)
....Sysadmin permission on the instance of SQL Server to be used for the configuration and organization databases.
....
(500) Internal Server Error, refers to a HTTP response status code. This means that the Powershell command is calling a URL and the URL is reporting a error.
You need to know the URL to really find out what the problem is. One way you can get the URL, is downloading Fiddler Classic. Once installed, you have to enable HTTPS decryption.
In my case the URL was...
https://<my-crm-domain>/XrmDeployment/2011/deployment.svc?wsdl
When I ran this URL on the server where CRM is installed, I got an exception stating...
Could not load file or assembly 'Microsoft.Crm.Application.Components.Application'
All this meant, I needed to copy a file, Microsoft.Crm.Application.Components.Application.dll, from C:\Program Files\Dynamics 365\CRMWeb\bin into folder C:\Program Files\Dynamics 365\CRMWeb\XRMDeployment\bin.
Once this was done, the URL worked and therefor my PowerShell command as well.
I have set up IIS on a Win 10 machine.
All I want to do is have a site with one page that runs a VBScript or Powershell script on the machine.
How can I do this simply?
It exists PowerShell Web Server. It's a Secure, flexible and lightweight web server that should meet your requirements.
In a few minutes you will be able to have a site with one page, I use it to publish my daily stats.
I tried about a dozen PowerShell scripts that I found and not one even created a single share.
We are migrating from Win 2008 and SQL Server 2008 R2 to Windows 2012 and SQL Server 2014.
I have to create a ton of shares and assign a lot of varying permissions.
I'm looking for (ideally) a Powershell script (but can live with VB or anything else) that can go through a list of shares and permissions and create/assign them.
For example
E:\Folder1\A Share1 Domain\Tom Read
E:\Folder1\A Share1 Domain\Dick Full
E:\Folder1\A Share1 Domain\Harry Change
So it would go through every line, see if the share exists, if not create it, then assign the permissions.
On Server 2012R2 you can use the New-SmbShare cmdlet : https://technet.microsoft.com/en-us/library/jj635722(v=wps.630).aspx
On older versions you have to fall back to WMI to do it :https://msdn.microsoft.com/en-us/library/aa389393(v=vs.85).aspx (the article even has a PS example).
With Set-Acl you can set the ACLs for the shares.
As you can see all the tools to acomplish this are available in a default installation of Windows Server.
I have an azure subscription and I'm trying to write a powershell script to automatically get a list of all the resources (VMs, Storage Accounts, Databases, etc) that I currently have in my subscription. Is there a way to do this using the azure management REST API or the Azure Cmdlets?
If you are using the new Resource Manager model (introduced in 2014) you can use the following PowerShell script.
Login-AzureRmAccount
Get-AzureRmResource | Export-Csv "c:\Azure Resources.csv"
To use the Resource Manager PowerShell commands you will need the AzureRM PowerShell module (https://learn.microsoft.com/en-us/powershell/azure/install-azurerm-ps).
Install-Module AzureRM
For more information on the difference between Resource Manager and Classic models see, https://learn.microsoft.com/en-us/azure/azure-resource-manager/resource-manager-deployment-model.
For users with multiple subscriptions:
If you want to output the contents of multiple subscriptions then you will need to call Select-AzureRmSubscription to switch to another subscription before calling Get-AzureRmResource.
I don't think there's just one function (or PS Cmdlet) to fetch all this information. However each of these can be fetched through both Windows Azure Service Management REST API as well as Window Azure PowerShell Cmdlets.
Windows Azure Service Management REST API: http://msdn.microsoft.com/en-us/library/windowsazure/ee460799.aspx. For example, if you want to list storage accounts in your subscription, you would use this: http://msdn.microsoft.com/en-us/library/windowsazure/ee460787.aspx
Windows Azure PowerShell Cmdlets: http://msdn.microsoft.com/en-us/library/jj554330.aspx. Again, if you want to list storage accounts in your subscription, you would use this: http://msdn.microsoft.com/en-us/library/dn205168.aspx.
well,
You may update the version of your AzurePowershell and execute this command.
Get-AzureResource
In the output, You may check for "ResourceType".
It has the information about the type of resource creatd on azure.
Since you said PowerShell "preferably", I'm going to assume other options are still maybe useful? You can go to http://portal.azure.com, and click on the Menu icon (three horizontal lines), then All Resources. Then at the top of the page you can click Export to CSV and open that in Excel.
You have to take 30 seconds to do a little cleanup in Excel, but for what I'm trying to do right now, this was definitely the best & fastest solution. I hope it's useful to you (or someone else) too.
Adding to #Gaurav's answer (and related to your comment about SQL database enumeration): You can enumerate all of your databases, on a per-server basis, in a few easy steps.
First, enumerate all of the SQL Database servers in your subscription:
Then, for each server, create a connection context and enumerate the databases. Note that, with the Get-Credentials cmdlet, I was prompted to enter a username + password via a popup, which I don't show here. For demonstration purposes, I created a brand new server, with only a master database, to show what the output looks like:
This sample demonstrates how to automatically get a list of all the resources (VMs, Storage Accounts, Databases, App Services) and status via Powershell by certificate authentication.
https://gallery.technet.microsoft.com/Access-Azure-resource-data-ca9cc9f7
I know it's already been answered however, I have found the Get-AzResource command easy to use and fetches all the resources from a particular subscription. Try using it with "ft" for clean text
Get-AzResource | ft
Screenshot
I'm a developer at a university in Chicago supporting Ellucian/Datatal Colleague on Unidata 7.2. We recently converted from Unidata on Unix to Windows Server and had a number of extract cron jobs that had to be converted to the new OS. During that conversion, I was introduced to the MS Windows Powershell Scripting Environment and have been using it to automate a lot of tasks that had been procedurally fragmented where the tasks were split up and executed asynchronously on different machines.
We are implementing the Ellucian Portal built on MS Sharepoint, and for that task we need to run a nightly job refreshing MS Active Directory attributes from our HR data. In order to do that I put together a Powershell script to take a flat file and update AD. However, the beauty of Powershell scripting is that you can work natively with .Net framework objects. I had developed a number of applications and utilities using VB UniObjects over the years and this seems to be a perfect opportunity to leverage the Powershell interface and build the extract step directly into the AD update script so the entire process can be executed as a single integrated application.
I've downloaded and installed the U2 toolkit for .Net from Rocket software but I've run into a snag in that the Powershell reference and instantiation syntax is different than any of the Visual Studio languages. Though I've been able to make some progress and have been able to establish a U2 ADO connection with the U2.Data.Client namespace, I am still having trouble instantiating the Native UniObjects U2.Data.Client.UO objects properly.
I'm sure that it just a simple issue with referencing the libraries correctly, but I've never actually worked with the .Net framework before, and I can't seem to find any authoritative examples of using the U2 .Net library in Powershell. This forum appears to be a great resource and the progress I've made is due to posts I've found here. If anyone has any thoughts or expertise in both U2 and Powershell I'd love to hear if you have an opinion on how to make the magic happen.
Thank you for asking this question.
You can call very easily U2 Toolkit for .NET (U2NETDK) from Windows PowerShell.
See the enclosed screen shot.
I did the following:
Install U2 Toolkit for .NET
Refer the installed .NET U2NETDK assembly
Create Connection Object
Create Command Object
Open Connection
Execute ADO.NET Command ( SELECT FIRST_NAME, SURNAME FROM MEMBERS)
Fetch Data. Write data on the PowerShell
Close the Connection.
If you want to use UO.NET capability and you want to use read file, UniCommand, SelectList, then refer U2.Data.Client.UO.UniFile, U2.Data.Client.UO.UniCommand etc.
I hope this example will help other U2 .NET Users too.
See this example:
http://blogs.technet.com/b/threekings/archive/2008/07/18/ado-net-in-powershell-update-sql-data-example-sample.aspx
Thank you for trying U2NETDK' ADO.NET and windows PowerShell.
For Native Access ( Uniobjects API), you do not need UODOTNET.DLL.
We have embedded Uniobjects API in U2NETDK.
So you will refer U2.Data.Client and U2.Data.Client.UO namespaces. See below the script and screen shot.
Add-Type -Path "C:\Program Files (x86)\Rocket Software\U2 Toolkit for .NET\U2 Database Provider\bin\.NETFramework\v2.0\U2.Data.Client.dll"
$Connection = New-Object U2.Data.Client.U2Connection
$Connection.ConnectionString = "Database=XDEMO;User ID=administrator;Password=pass;Server=9.72.199.235;Persist Security Info=True;ServerType=universe;AccessMode=Native"
$Connection.Open()
$Session = $Connection.UniSession
$UniSelectList =$Session.CreateUniSelectList(2);
$UniFile = $Session.CreateUniFile("PRODUCTS");
$UniSelectList.Select($UniFile);
while (!$UniSelectList.LastRecordRead)
{
$sRecID = $UniSelectList.Next();
write-host $sRecID
}
$Connection.Close()