Update a filed value with powershell script with ordery by and where condition
Hi
I have below powershell script to update list columns but how i update a field value with ordery by a column and where condition
below is the part of my script
$list = $web.Lists[$listName]
$items = $list.items
$internal_counter = 1
#Go through all items
foreach($item in $items)
if($item["CourtNO"] -eq $null)
#if($item["CourtNo"] -eq '1')
$item["CaseNo"] = $internal_counter
#how to add a column ordery by Title
# and where Title field value from 1 to 10
$internal_counter++
adil
Hi,
You mean that you only need to update all items with Title field value in range 1..10 and order by them before run the loop statement update?
If so, use CAML query to get the items only match the condition.
#Build Query
$spQuery = New-Object Microsoft.SharePoint.SPQuery
$query = '<Where><And><Gte><FieldRef Name="Title" /><Value Type="Text">0</Value></Gte><Lte><FieldRef Name="Title" /><Value Type="Text">10</Value></Lte></And></Where><OrderBy><FieldRef
Name="Title"/></OrderBy>'
$spQuery.Query = $query
$spQuery.RowLimit = $list.ItemCount
$items = $list.GetItems($spQuery)
Hope this help!
/Hai
Visit my blog: My Blog | Visit my forum:
SharePoint Community for Vietnamese |
Bamboo Solution Corporation
Similar Messages
-
What is the best way to run a powershell script with parameters in the Task Scheduler?
Hello,
Want to run the following from a scheduled task in the Task Scheduler on a server. What is the best approach?
.\pscript.ps1 -csvfile "\\Srv1\Share\File.txt"
Thanks for your help! SdeDotHi,
To run a powershell script with parameters in the Task Scheduler:
Program: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Add argument (optional): -Command "& c:\scripts\test.ps1 -par1 2 -par2 3"
Hope the below two articles be helpful for you:
Schedule PowerShell Scripts that Require Input Values
https://blogs.technet.com/b/heyscriptingguy/archive/2011/01/12/schedule-powershell-scripts-that-require-input-values.aspx
How to Schedule a PowerShell Script
http://dmitrysotnikov.wordpress.com/2011/02/03/how-to-schedule-a-powershell-script/
Regards,
Yan Li
Regards, Yan Li -
Which is better approach to manage sharepoint online - PowerShell Script with CSOM or Console Application with CSOM?
change in sharepoint scripts not require compilation but anything else?Yes, PowerShell is great, since you can quick change your code without compilation.
SP admin can write ps scripts without specific tools like Visual Studio.
With powershell you can use cmdlets,
which could remove a lot of code, for example restarting a service.
[custom.development] -
Powershell script for security groups and users for multiple share folders
Hi scripting team,
I need your help with powershell script for the below queries
1. List out the security groups for more than one server share path and output it to a file ( csv )
For eg.
If the are are two share paths
\\servername\foldermain\folder1
\\servername\foldermain\folder2
So I needs the list of security groups for each share path
And the output needs to be under each any every path.
2. Grab the users belongs to main security groups and it nested groups for more than one security group and listed the users under each and every group. No need to display nested groups. Just users belongs to main group and users under nested.
Your teams help is much appreciated
Thank you.
Thilochana kumararatneHi Braham,
Thanks for your quick reply.
Are we able to do this on two stage method
1. grab the security groups from the share paths
if can grab the share path from a separate txt file than copying it to the <your path> location
so i can modify the txt file
once run the script
if can the output like below to a CSV file
\\servername\foldermain\folder1group 1group 2group 3\\servername\foldermain\folder2group 1group 2group 3then i know which groups belongs to which share paththen i can remove the duplicate groups and keep the common groups to grab the users belongs to itso with the second script same as the first copy the security groups to a txt file and the out put as below.what I needs is the users full name and the samaccount name ( user id )group 1user1user2user3
group 2user1user2user3looking forward your help on thisThank you.Thilo -
What version of iLife works with Snow Leopard 10.6.8, and where can I buy it?
Welcome to Apple Support Communities
You can install the latest version, iLife '11. It's available at the Mac App Store, but the versions available there aren't compatible with Mac OS X Snow Leopard, so you have to get iLife '11 on a DVD at eBay or Amazon > http://www.amazon.com/Apple-MC623Z-A-iLife-VERSION/dp/B003XKRZES
After installing it, open > Software Update, and install the most recent version for Snow Leopard -
I have just pre-purchased the Iphone 5 and am concerned about the Nano_SIM. I am with Telstra in Australia. How and where do I get a Nano M and how do I get my pre-paid account onto the new SIM?
The nano SIM should come with the phone if you set it up with a carrier.
If you purchased an unlocked phone, you'll have to contact your carrier to get a nano sim card. -
Split filename and create folders with Powershell script ( --newbie user)
I have a folder with 1000's of files. Each file varies in length; typically between 9-14 characters. Example:
C:\workpics\1238955678.1
C:\workpics\744556224.1
C:\workpics\744556224.2
C:\workpics\8445655996.1
I would like to run a script to split the filename and separate into folders. The filename would then consist of 5 characters, the foldername would be the first characters remaining.
C:\workpics\12389\55678.1
C:\workpics\7445\56224.1
C:\workpics\7445\56224.2
C:\workpics\84456\55996.1
Any assistance to create this Powershell script would be awesome. Thank you!!I have a folder with 1000's of files. Each file varies in length; typically between 9-14 characters. Example:
C:\workpics\1238955678.1
C:\workpics\744556224.1
C:\workpics\744556224.2
C:\workpics\8445655996.1
I would like to run a script to split the filename and separate into folders. The filename would then consist of 5 characters, the foldername would be the first characters remaining.
C:\workpics\12389\55678.1
C:\workpics\7445\56224.1
C:\workpics\7445\56224.2
C:\workpics\84456\55996.1
Any assistance to create this Powershell script would be awesome. Thank you!!
Please reread your request. It makes no sense. Read each statement carefully and notice that the statements are in conflict.
Start your scrip in PowerShell. Look up things like how to list files and how to manage strings. All of the information you need is here:
http://technet.microsoft.com/en-us/scriptcenter/dd793612.aspx
¯\_(ツ)_/¯ -
Problems with PowerShell script
Hi guys.
Using this powershell scripts:
http://gallery.technet.microsoft.com/office/Lync-Environment-Report-cbc6fb1a
I have already a opened thread on MS TECHNET FORUM:
http://social.technet.microsoft.com/Forums/office/en-US/a23ffdf8-fb10-4386-b21b-9f06cda84bdd/lync-environment-report-draw-pictures-in-visio?forum=lyncdeploy
unable to solve the error for powershell script: New-LyncEnvDiagram.
Is there any of you Power$hell Mai$ter$ able to understand why the script ain't working?
with best regards,
bostjancHi Bostjanc,
Since we have no test enviroment, and this is difficult for us to debug the script.
Maybe you can try to leave a comment to ask the author chris for helps:
http://emptymessage.com/?p=149
If you have any feedback on our support, please click here.
Best Regards,
Anna Wang
TechNet Community Support -
Please help me with Powershell Script - Message Box to display after Installation
Hi Guys,
Am using package model to deploy the software. After installation on client machines i want to display a dialog box to notify the successful installation.
Currently trying VBScript to show the dialog message.
But few machines i get this dialog and few machines am not getting, in program command line am calling a batch script.
Now am planning to use a Power shell scripting to show a message box and trying to call it through a batch script.
Please assist me with the powershell script which will display a message box like above
(and let me know in script how to enable the set-execution policy Remote signed enabled)
Thanks,You can set the execution settings from within the client settings.
For a simple message box without having to load assmemblies
$wshell = New-Object -ComObject Wscript.Shell
$wshell.Popup("Operation Completed",0,"Done",0x1) -
Trying to delete a file with Powershell script ran by a service but issues with uac
I'm having issues with a script that will delete a file on the C-Drive of a server. the script looks like this:
param(
[Parameter(Mandatory=$true)][string]$hostname
$StrFileName = "C:\Program Files\NSClient++\nsclient.log"
$LogLocal="c:\Nagios\naf_delete_nscp_log_file.log"
$Date = Get-Date -Format "yyyy-MM-dd hh:mm:ss"
"$date : NSClient logfile deletion requested on $hostname" | Out-File -filepath $LogLocal -Append
If (Test-Path "$strFileName"){
Remove-Item $strFileName -Force
$Date = Get-Date -Format "yyyy-MM-dd hh:mm:ss"
"$date : NSClient logfile deleted on $hostname" | Out-File -filepath $LogLocal -Append
The script is initiated from a Nagios quick action which will use nrpe to pass the host as parameter and make the nscp service, which runs as local system, run it. It works perfectly on servers that have no uac enabled, but I can't get it to work on servers
with uac. I've tried numerous options, but none seem to work. Any tips or advice to get this working with Powershell v2 code on servers with uac enabled is highly appreciated.
Thanks.
WillemHi Willem,
one thing to note: I don't see why your script itself has a hostname parameter.
One way around UAC has always been the Windows Task Scheduler. If you register a task as System run and triggered by an event, you can simply call the event locally (which doesn't require admin permissions) and it will perform the task.
I don't know how your Nagios construct works and the script by itself doesn't make much sense. If you want advice on how to do this without resorting to tasks, I'd need to know more about the system you are using.
Cheers,
Fred
There's no place like 127.0.0.1 -
Running powershell script with customer parameters as a scheduled task
tfl wrote:I guess I don't get why you are wanting thisMy regular tasks run,. and take data from data files. Want your batch to get processed today? Then add it to the queue file by 5:00 PM.. The task runs at 5:01 and works with whatever data is available. And if the file is empty, nothing happens each night. If you want to pass parameters like this, then why bother with a scheduled task? You'd need to remove the old one and add the new one each time. Which is extra work and complexity, especially if the task at hand is in any way 'dangerous' if run twice with the same data (ie you forget to change the task or remove it).I'm using a scheduled task to trigger the script, I'm using the "on event" trigger and then calling the script as an action. The method I was using before (calling via a bat file with the event Id hard coded into that"...
Hi all,Having one of those hair pulling issues where something should work but for some reason its blindly refusing not to!I've created this script that is a bit of an extension to the email on eventID for task scheduled. It basically pulls out the various information from the actual event and fires off an email to our alerting team to investigate etc.That all works great, but what I'm now trying to do is get it to accept a custom parameter so the actual event ID its looking for doesn't have to be hard coded and can be passed to it via the commandline etc. I've got it all setup and work great but for the life of me can't get it to work correctly when set as a scheduled task. This is what the command basically looks like:powershell -executionpolicy bypass -command "& 'pathtofile\script.ps1' -evtid 8004"The latter part is the customer...
This topic first appeared in the Spiceworks Community -
Run a powershell script with domain credentials during task sequence
I have a powershell script that adds the computer it is run on to a security group. If I log onto the computer with a domain account it works perfectly. However, if it is run while logged on as the local admin account it fails with an error message
that says the domain either doesn't exist or cannot be reached.
This is a problem because when a computer is being imaged the process runs with the local admin account. Is there a way to run this script with domain credentials in the task sequence?
Thanks,
AndyHow are you running the Powershell script? If you use a Run Command Line step, you can specify an account to run as. Something like "powershell %scriptroot%\psscript.ps1" where the psscript.ps1 is located in your Scripts folder in your deployment
share.
-Nick O. -
How to copy a folder from TFS source control to Shared location with Powershell script
Hi,
I'm looking for a Powershell script where i could copy a folder from TFS Source control to a shared location.
Details:
$TeamProject/FolderA - here i want to move FolderA to a shared location called \\Share
Tried with xcopy: xcopy "$TeamProject/FolderA" "\\Share" ( but no luck, later i found it's only possible to copy files from local to share or share to share location, not from server path to shared location.
Can someone help me with the power-shell script to achieve above scenario.
Thanks, BHSRHope the below script works for your scenario. Got the code from http://stackoverflow.com/questions/23739499/copy-files-from-tfs-versioncontrol-to-directory-with-powershell
$AutoDeployDir = "$\TeamProject/FolderA"
$deployDirectory = "\\SERVER\SHAREFOLDER\"
# Add TFS 2013 dlls so we can download some files
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.VersionControl.Client")
$tfsCollectionUrl = "http://CDTFSSERVER:8080/tfs/ProjectCollection"
$tfsCollection = New-Object -TypeName Microsoft.TeamFoundation.Client.TfsTeamProjectCollection -ArgumentList $tfsCollectionUrl
$tfsVersionControl = $tfsCollection.GetService([Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer])
# Register PowerShell commands
Add-PSSnapin Microsoft.TeamFoundation.PowerShell
# Get all directories and files in the AutoDeploy directory
$items = Get-TfsChildItem $AutoDeployDir -Recurse -Server $tfsCollection
# Download each item to a specific destination
foreach ($item in $items) {
# Serverpath of the item
Write-Host "TFS item to download:" $($item.ServerItem) -ForegroundColor Blue
$destinationPath = $item.ServerItem.Replace($AutoDeployDir, $deployDirectory)
Write-Host "Download to" $([IO.Path]::GetFullPath($destinationPath)) -ForegroundColor Blue
if ($item.ItemType -eq "Folder") {
New-Item $([IO.Path]::GetFullPath($destinationPath)) -ItemType Directory -Force
else {
# Download the file (not folder) to destination directory
$tfsVersionControl.DownloadFile($item.ServerItem, $([IO.Path]::GetFullPath($destinationPath)))
Regards, Bharath
LinkedIn: -
Looking for help with PowerShell script to delete folders in a Document Library
I'd like to create a PowerShell script to delete old folders in a Document library that are over 30 days old. Has anyone created something like this?
Orange County District AttorneyHello Sid:
I am trying to do the same and Iam running the script to delete the subfolders inside a folder but I have some errors.
Could you please take a look?
_______Script________
$web = Get-SPWeb -Identity https://myportal.mydomain.com
$list = $web.GetList("ar_mailingactivity")
$query = New-Object Microsoft.SharePoint.SPQuery
$camlQuery = '<Where><And><Eq><FieldRef Name="ContentType" /><Value Type="Computed">Folder</Value></Eq><Leq><FieldRef Name="Created" /><Value Type="DateTime"><Today OffsetDays="-30" /></Value></Leq></And></Where>'
$query.Query = $camlQuery
$items = $list.GetItems($query)
for ($intIndex = $items.Count - 1; $intIndex -gt -1; $intIndex--)
$items.Delete($intIndex);
________Errors_______
Unable to index into an object of type System.Management.Automation.PSMethod.
At C:\Script.ps1:2 char:22
+ $list =$webGetList <<<< "ar_mailingactivity"]
+ CategoryInfo
:InvalidOperation: (ar_mailingactivity:String) [], RuntimeException
+ FullyQualifiedErrorID
:CannotIndex
You cannot call a method on a null-valued expression.
At c:\Script.ps1:6 char:24
+ $items = $list.GetItems <<<< ($query)
+ CategoryInfo
:InvalidOperation: (GetItems:String) [], RuntimeException
+ FullyQualifiedErrorID
:InvokeMethodOnNull -
How can I open IE, in inPrivate Browsing mode using PowerShell script?
$ie = New-Object -com internetexplorer.application;
$ie.visible = $true;
$ie.navigate2("http://bing.com");
while ($ie.Busy -eq $true) { Start-Sleep -Milliseconds 1000; }
RamanaHi
Venkata,
I’m writing to just check in to see if the suggestions were helpful. If you need further help,
please feel free to reply this post directly so we will be notified to follow it up.
If you have any feedback on our support, please click here.
Best Regards,
Anna
TechNet Community Support
Maybe you are looking for
-
I have Pages 09 and I have created a business card using the template but can't figure out how to duplicate it to the other 9 spaces on the page. I am and sure I am going to look daft coz its only the click of a button but I can't work it out Thanks
-
Data Concurrency and Consistency ( SCN , DATA block)
Hi guys, i am getting very very very confused about how oracle implement consistency / multiversioning with regards to SCN in a data block and transaction list in the data block.. I will list out what i know so you guys can gauge me on where i am.. W
-
I have a paid subscription to Adobe Pro. I just bought a new computer and need to know how to transfer the software from my old computer to my new one.
-
Posting problem--personal domain
Hi Folks, I'm having a frustrating problem with publishing parts of my website via iWeb. The gist is that one of my sites will no longer load when typed in directly, although it will when accessed via a link on another of my sites. Here's some backgr
-
Trouble installing Designer Repository under XE
I have installed Oracle 10g XE on another PC (as a test system), and I have the XE Client on my own laptop. I also have SQL Designer installed, and both can talk to the copy of XE just fine. However, when I try to install the Designer Suite, I've run