Change content of default.aspx for subsites using Powershell

Hi.
I need to update the content of the default.aspx of 60+ subsites in a site Collection. I am able to loop all subsites and get the corresponding default.aspx files using a PowerShell snippet like:
$site = Get-SPSite -WebApplication https://mysite.domain.no/ -Limit All
$wc = $site.allwebs | where {$_.url.StartsWith(https://mysite.domain.no/sites/blahblah/blahblahblah) }
foreach ($web in $wc){
$file = $web.GetFile("default.aspx")
The problem is I don't know whether to use the Set-Content command-let or an XMLDocument approach.
I have the file With the correct content on the local machine. I tried With $file.Parentfolder in order to use
$f = $web.GetFolder($file.ParentFolder)
$fc = $f.files
Get-ChildItem "C:\temp\default.aspx" | foreach {
$spFileCollection.add($($_.Name),$_.OpenRead(), $true)
to replace the file but this gives an error on empty folder. Can I use this approach or is there a way to change the actual content of the file?

Hi Jorgen,
According to your description, my understanding is that you want to update the page content using PowerShell.
I suggest you read the content data like below:
$data = $file.OpenBinary()
$encode = New-Object System.Text.ASCIIEncoding
$test = $encode.GetString($data)
Then you can change the string you want, and then you can save it using SaveBinary() method.
Here are some detailed articles for your reference:
Reading the contents of a SharePoint library file using PowerShell
Using powershell to read/modify/rewrite sharepoint xml document
Best Regards
Zhengyu Guo
TechNet Community Support

Similar Messages

  • Set default quota for farm using powershell

    Hello, 
    Looking for a powershell solution to creating a default quota template. So when new sites are created they default to that quota, or can be changed if needed. 
    Thanks, 
    Will 

    This article is for 2010, but it should work the same in 2013.  This PowerShell just creates the quota template.  You will need to pick the quota template when creating a site collection.  There is no way to set a default quota template for
    regular site collections.
    http://www.sharepointdiary.com/2013/08/create-sharepoint-quota-templates-using-powershell.html
    Paul Stork SharePoint Server MVP
    Principal Architect: Blue Chip Consulting Group
    Blog: http://dontpapanic.com/blog
    Twitter: Follow @pstork
    Please remember to mark your question as "answered" if this solves your problem.

  • Export/ import of a subsite using Powershell and STSADM

    Can any one clarify the difference between export/import of subsite between PS and STSADM.
    I was able to export a subsite using Powershell but when using Powershell, it gives me error as subsite is not there.
    When I used the stsadm it worked even the subsite is not there.
    Appreciate help and thanks much.

    STSADM is depreciated in 2010, you should be using PowerShell wherever possible.
    If the site isn't there then exporting should be tricky. Could be a false error due to permissions though

  • Where can I change Firefox 4 default setting for proxy servers

    I am working on setting up firefox 4 in a multi user environment in linux. In FF 3.x releases, I could go to greprefs/all.js area and make the changes in the all.js file to chagne settings globally. But, I could not find any such file for firefox 4.x installation (for linux).
    Would you please advise where can I go about editing global setting in Firefox 4?
    thanks.

    Maybe it works if you create file and place a files with the prefs in the defaults/pref folder.
    You can use a mozilla.cfg file to lock prefs or specify default values.<br />
    You can place a file local-settings.js in the defaults\pref folder to specify using mozilla.cfg.
    You can use these functions in mozilla.cfg:
    defaultPref(); // set new default value
    pref(); // set pref, but allow changes
    lockPref(); // lock pref, disallow changes
    To prevent users from installing software use:
    lockPref("xpinstall.enabled" ,false);
    See:
    * http://kb.mozillazine.org/Locking_preferences

  • Change Smart View default colours for all clients

    I need to change Smart View default colours. But it must be done in a centralized way, so I can not set it up at the client level. I'm not sure if Smart View takes defaults from planning.css styles, or if they're defined somehow at the provider, or maybe specified in client installer.
    Thank you in advance for any guidance on this.
    SD

    SD,
    You may want to work with Oracle SmartView Support, to see if / how it is possible for SmartView, using a Service Request.
    Thanks!

  • Incorrect Default Gateway for Clients using a Concentrator

    Hey all,
    Hopfully an easy one - I'm trying to configure a VPN Concentrator for use with the old VPN Client for an IPSec CVPN.
    The clients connect fine, but they are getting the incorrect default gateway during the address assignment.
    My address pool is 192.168.0.128/25.  The client correctly picks up the first address in the range, 192.168.0.129, but the default gateway for the VPN adapter is assigned as the next address in the range, 192.168.0.130.
    I need the gateway address to be 192.168.0.254 (the SVI of the L3 switch connected to the Concentrator), but I can't for the life of me fine a configuration option anywhere in the pool assignment.  I've set the tunnel default gateway to this 192.168.0.254, but this makes no difference.
    Any ideas where I can find this config option?
    Thanks!

    Andrew
    In the chart that you posted about the routing setup it refers to a DMZ network and DMZ gateway. Can you clarify what these are since I do not see them in the drawing that is in that post?
    I agree with Herbert that it is cleaner to have the address pool on the concentrator use addresses that do not overlap with the concentrator subnet connecting to the layer 3 switch. And as long as the layer 3 switch has a route to that address pool, and the next hop in the route is the address of the concentrator interface then the separate pool addressing should work just fine.
    I have re-read this thread and want to make sure that after some changes that you have made that the problem symptoms are still the same. You told us earlier that: "Now the client can ping the interfaces on its local LAN (concentrator  interface 192.168.0.253, and the L3 switch, 192.168.0.253), but it  cannot reach the rest of our internal LAN behind the layer 3 switch." Is this still an accurate statement of the problem?
    As Herbert said earlier this could either be caused by the concentrator not have a correct route for the inside or it could be  because the inside does not have a correct route to the client. In re-reading your description of the routing set up it looks like the concentrator has a default route configured but not the tunnel default route. May I suggest that you try configuring a tunnel default route (in addition to the normal default route) and see whether that makes any difference?
    If that does not help the problem then I would suggest that you verify that the devices on the inside do have their default gateway set correctly and that the layer 3 switch does have a route for the VPN address pool with the concentrator interface address as the next hop.
    HTH
    Rick
    [edit] I just focused on the question that you asked about the concentrator possibly needing a route for the address pool. The concentrator does not need any route statements for the address pool - it knows its own address pool, pretty much like having a connected interface subnet. The layer 3 switch is what needs a route for the address pool.

  • How  to set default value for Zfeild using statusprofile

    hi experts,
    I need to set a default value for a zfeild using status profile.Although we can default the values,using getter and setter methods,but in my requirement,the feild will be defaulted when the page is locked,also in display mode,which will require me to write code to unlock then set the value and then write a commit,as there wont be any user action performed.
    I have created a zstatus profile and have set the required status to inital,but no luck
    please suggest if this canbe achived through status profile.
    Regards
    Anu.

    Hi,
    You can check in the getter if the Page is locked and then display the value to want to display. Note that this will be just Displaying the default value for the Zfield and it will not set the default value into  the Zfield in DB, because when the document is locked ( means locked for editing - mostly when system status is completed ) , setters are not called and so you can display the value but cant set it. This is fine if the value you want to display in Z field is just for user's informations and its not required to save this default value.
    The best approach would be to set the value in the Zfield before the page is locking. For example, If you wat to set the zfield value when status is set to "Completed" , then you can configure an action that is 1) triggered during saving of the document with 2) start condition "When status is completed"  ( both 1 and 2 you can mention in action defination ), then Implement this action badi in which you can set the Zfield to default value.
    This will ensure that default value is always set whenever the page is getting locked for editing ( i assumed that page lock means status completed ).
    Thanks & Regards
    Suchita

  • SP Online - Managed Metadata column Default Value for folders (using CSOM)

    Hello,
    I am working on setting default values (metadata columns)  for different folders on my document library. As so far, I've found solution about how to set default values on whole library and many solutions which works for folders, but not for sharepoint
    online (using metadataDefaults object).
    The only working solution for folders in SPO I've found is editing file library/Forms/client_LocationBasedDefaults and add some data here.
    My question is: is there any easier method to set default values for each folder in document library without manually editing this file? 

    I second that, I have a client looking to do the same thing but I don't see a way to automate this.

  • Windows 8.1 - How to enable "Require additional authentication at startup" for bitlocker using powershell script?

    I need help to do this using powershell scripts on Windows 8.1?
    OS : Windows 8.1 Enterprise
    TPM Chip : None
    Enabling bitlocker on OS drive with a password at boot time is a 2 step process.
    1) Edit the Group Policy (gpedit.msc) - Administrative Templates -> Windows Components -> BitLocker Drive Encryption -> Operating System Drives ->
    Require additional authentication at startup -> Allow bitlocker without a compatible TPM
    ref : http://www.7tutorials.com/how-enable-bitlocker-without-tpm-chip-windows-7-windows-8
    2) Enable Bitlocker on c driver using manage bitlocker snapin
    I need help to do this using powershell scripts?
    I researched on the forums but ran into an issue.
    I found that Group policy commandlets can be used to do step 1.  
    I am getting the error : "ins have been registered for Windows PowerShell version 4" when I try to do the following in windows 8.1
    Add-PSSnapin GroupPolicy
    Import-Module GroupPolicy -Verbose

    Hi TinkerBotFoo,
    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
    We
    are trying to better understand customer views on social support experience, so your participation in this
    interview project would be greatly appreciated if you have time.
    Thanks for helping make community forums a great place.

  • How do I change or remove default apps for a given file extension (in Terminal?) without munging date modified on all my old files?

    When a program is installed, it seems to be able to do it (sometimes inappropriately if it hijacks file associations without asking) so why can't I?  This is for 10.4.
    Specifically:
    1. Since installing an HP wireless printer, HP not only tries to install a bunch of sales-ware on your machine that you have to carefully opt out of (annoying, but not a problem if forewarned), it changes the default file association for a number of basic file types, listing all sort of existing files as HP printer files. Using Get Info to change the default file type association globally causes it to mark ALL the files of that type as newly updated, munging the file metdata (which HP did NOT do). Most of the stuff on our computer is sorted by last modified, so if there is a way to fix this in Terminal (to simply fix or remove the HP default tag) without changing the date the file was modified, it would help. Note that uninstalling the program that created the default would do this, but I obviously can't do that (and reinstalling HP would have the same effect). So there has to be another way, right?
    2. Since updating iTunes to v.9 a while back, every mp3 is marked as an iTunes file even though iTunes has NO multiple library capability without a wonky reboot using the option key, meaning that if I click on an mp3 downloaded since last update of iTunes, it opens automatically in iTunes and gets added to the SOLE itunes library without asking. (There is no way to toggle between multiple libraries or archive media in separate folders; iPhoto has a similar problem. (Has this been fixed in the latest version of iTunes?) In comparison, Quicktime starts up immediately and does not attempt to create a playlist just because you opened a file and listened to it.
    (The iTunes playlists are simply subfolders of the single main library -- and you can't create a new library without doing a wonky procedure by clicking option during startup and telling iTunes to forget where its library is located (includin everything in it) and look up an entirely separate one by hand. So any mp3 file downloaded recently is uploaded to iTunes if you click on it. This wouldn't be problem if it didn't automatically add it to the sole iTunes library just because you clicked on it.)
    Besides, all my old mp3s are Quicktime files and they are all archived by date modified. To its credit, ITunes, unlike HP, does NOT hijack older files already on disk and remark them as iTunes files. It only marks newly downloaded files as such.  But if I try and change file association for FUTURE mp3 files using Get Info > "use this program for all files of this type", it munges the file metadata (date modified) for all existing files!
    Note that in HP case, it apparently does it at the file exchange preference level (or whatever it's called) since the OS then recognizes every file of those types as an HP file. In the iTunes case, it only does it if you download a new media file or open an existing file in iTunes, but again without changing the date it was last edited.
    Since these programs are able to change the default file association without changing the date the file was last edited, it should be reversible in Terminal, correct?  Why does it change "date modified" when you try and correct metadata using Get Info (or sometimes just by clicking an enclosing folder?) Date modified should be a record of when a file itself was edited, not when it was renamed, or other metadata. Otherwise stuff can't be sorted correctly.

    The unix commands you need are:
    GetFileInfo
    SetFileInfo
    and maybe find
    for cryptic details use the man command
    Macintosh-HD -> Applications -> Utilities -> Terminal
    man SetFileInfo
    You may use the SetFileInfo command to set the file type & the program which will open the file.
    # This little gem will do a get info on all files in a directory.
    mac $ ls  | xargs -I {} GetFileInfo "{}"
    file: "/Users/mac/playdoc/oddadocodd"
    type: ""
    creator: ""
    attributes: avbstclinmedz
    created: 05/01/2011 14:53:22
    modified: 05/01/2011 14:53:22
    file: "/Users/mac/playdoc/one.docx"
    type: ""
    creator: ""
    attributes: avbstclinmedz
    created: 05/01/2011 13:57:48
    modified: 05/01/2011 13:57:48
    file: "/Users/mac/playdoc/oneLineFile"
    type: "TEXT"
    creator: "!Rch"
    attributes: avbstclinmedz
    created: 05/07/2011 14:27:17
    modified: 05/07/2011 14:27:17
    file: "/Users/mac/playdoc/oneLineFile.txt"
    type: "TEXT"
    creator: "!Rch"
    attributes: avbstclinmedz
    created: 05/07/2011 14:27:49
    modified: 05/07/2011 14:27:49
    file: "/Users/mac/playdoc/three.docx"
    type: ""
    creator: ""
    attributes: avbstclinmedz
    created: 05/01/2011 13:58:03
    modified: 05/01/2011 13:58:03
    file: "/Users/mac/playdoc/two.docx"
    type: ""
    creator: ""
    attributes: avbstclinmedz
    created: 05/01/2011 13:57:56
    modified: 05/01/2011 13:57:56
    file: "/Users/mac/playdoc/weirder.doc.docx"
    type: ""
    creator: ""
    attributes: avbstclinmedz
    created: 05/01/2011 14:50:03
    modified: 05/01/2011 14:50:03
    # well, ! is a funnie character so we escape it.
    mac $ SetFile -t TEXT -c \!Rch two.docx
    mac $ GetFileInfo two.docx
    file: "/Users/mac/playdoc/two.docx"
    type: "TEXT"
    creator: "!Rch"
    attributes: avbstclinmedz
    created: 05/01/2011 13:57:56
    modified: 05/01/2011 13:57:56
    mac $
    mac $ date
    Sat May  7 14:40:56 EDT 2011
    mac $

  • Change to the default behaviour for Birds Eye view please

    At the moment the way Birds Eye View (pressing a key to zoom the image to full screen) is not very clever: An example - if your cursor is at the left of the screen it will first of all zoom out, with the "actual area" box located on the left, roughly where your cursor happened to be . And then on releasing the key, it will zoom to a completely new place in the image, based on where your cursor happened to be when you activated the shortcut. In practice this is almost random behavior, because while you are retouching in close, your cursor can be almost anywhere.
    Now I know that its possible very when you are zoomed out to relocate the box, but its a pain to have to do this each time, when its not required.
    What it should do, in my humble opinion - is by default it should keep what I'm calling the "area box" located in the currently zoomed area of the screen, so zooming in and out with the key will by default always take you back to where you were.
    For those of use doing high detail work, who like to quickly see a full screen, this change in behavior would make it possible to use Birds eye view more easily instead of zooming in and out in other ways.
    Of course a preference could be provided in case anyone at all actually likes the annoying CS4 default

    depend of what you want exactly you can use
    PositionInterpolator if you just need a translation
    here is a example that should work
    BoundingSphere bounds = new BoundingSphere();
    TransformGroup vpTrans= myWorld.getViewingPlatform().getViewPlatformTransform();
    // create Alpha
    Alpha alpha = new Alpha (-1,Alpha.INCREASING_ENABLE + Alpha.DECREASING_ENABLE,
    0, 0, 2000, 0, 1000, 2000, 0, 1000);
    // create position interpolator
    PositionInterpolator posInt = new PositionInterpolator (alpha, vpTrans);
    posInt.setSchedulingBounds(bounds);
    posInt.setStartPosition(-1.0f);
    another way his to use spline the best example of this is in the demo that come with java3d at
    your_JVM/demo/java3d/SplineAnim/SplineAnim.java
    the only thing you have to change his to specify the good transformGroup wich is vpTrans
    hope it help
    cyril

  • Setting Default values for field using custom.pll

    Hi All,
    I have an rquirement to set the default values on Meterial Tranasction screen for some condition
    I tried it in both ways via Form Personalization and using custom.pll
    i m using the following code in custom.pll
    form_name      varchar2(30):= name_in('system.current_form');
    block_name varchar2(30):= name_in('system.cursor_block');
    trx_type           varchar2(30);
    subinv                varchar2(30);
    begin
    if form_name='WIPTXMAT' and block_name ='MTL_TRX_LINE' then
    if event_name ='WHEN-VALIDATE-RECORD' then
         trx_type:=name_in('WIPTXMAT.TRANSACTION_TYPE');
    if trx_type ='WIP Return' THEN
         copy(10,'MTL_TRX_LINE.TRANSACTION_QUANTITY');
              copy(10,'MTL_TRX_LINE.NUMBER_OF_LOTS_ENTERED');
              sinv:=trim(name_in('MTL_TRX_LINE.SUBINVENTORY_CODE'));
              if sinv is null then
                   copy(subinv,'MTL_TRX_LINE.SUBINVENTORY_CODE');
                   copy(fr_locator,'MTL_TRX_LINE.LOCATOR');
                   FND_MESSAGE.SET_STRING(sinv);
                   FND_MESSAGE.SHOW;
              end if;
         end if;
    end if;
    end if;
    end event;
    Problem is that default values are getting set but not for all rows . if there are 4 records then values are set for only first 2 rows and if there are 2 rows then defaults are set for 1st row only.
    Same behaviour happens when i do it via form personalization
    i couldn't understand the behaviour of WHILE-VALIDATE-RECORD event..
    Please provide some suggestion on it. its really urgent.
    Thanks in Advance
    Renu

    Works Now...

  • Changing file clicking default behaviour for all users

    Is there a way to change the default file clicking behaviour for all users? Each user can do it himself by going via the username menu ("Personal Preferences", "When clicking on a file...") but I would prefer to set it for all users to a value that is different from the default.

    Hi Ganesh,
    Can u pl post how you solved this.
    Regards,
    Reema.

  • Change speed, duplex, auto negotioation of NIC using Powershell or command line

    Hi
    I created Hyper-V cluster using nodes with Microsoft Hyper-V server 2012R2. So these nodes don't have GUI. How to change for example NIC speed? I have 1GB NIC but in system autonegotiation use 100MBps? How to force 1gps speed.
    This is one of example. Using Power Shell Get/Set-NedAdater commands don't have power to do it.
    Thank you for help!
    Kind Regards Tomasz

    Is this the nic on a VM or on a VM Host?
    A physical NIC can usually only be changed by the vendors utilities.  A VM can change NICs in the config file.
    This might be helpfulk in deciding:
    https://social.technet.microsoft.com/Forums/windowsserver/en-US/8746cfc4-df49-4b12-9e66-81d80605e717/configure-hyperv-vm-nic-speed?forum=winserverhyperv
    ¯\_(ツ)_/¯

  • To find out the list of user profiles marked for deletion using powershell or C# for SharePoint 2010

    I have Disabled the MysiteCleanup timer Job and disabled few user profile accounts in AD.  Then in SharePoint user profile service, ran the User profile full synchronise job.
    I am able to find the marked for deletion records from the table (UserProfile_Full) in SQL server and also in the Manage User profile menu of the central admin under "Profile missing from import"
    view.  But  am not getting these records, If I execute the  below powershell command.
    $upa = Get-spserviceapplication -name 'User Profile Service Application'
    Set-SPProfileServiceApplication $upa -GetNonImportedObjects $true
    This command shows only the system account and not the accounts, which are marked for deletion .
    Please suggest how to get this result.
    Thanks & Regards,
    Yoga

    What result do you get hen use use type below in powershell
    $upa

Maybe you are looking for

  • HT203808 I can't change the Apple ID on my new phone after switching from my old phone.

    I bought a new iPhone 5S and restored my iTunes info from an old backup.  I now have an old Apple ID in my new phone when I try to use iCloud.  The old Apple ID is defunct so I can't delete the account as I don't have the password.  I backed up my ol

  • How do I import a file that is on the desktop to iMovie?

    How do I import a file that is on the desktop to iMovie? I had some 8 mm film put onto DVD by yesdvd and now want to import the 3 hours of video into iMovie to edit and create a short story. I have created a dmg file on my desktop from the DVD but am

  • Error in merge statement when trying to impliment SCD type 2 using merge...

    Hi , I'm trying to impliment SCD type 2 using Merge using below blog as reference but sime how it is erroring out with error http://www.made2mentor.com/2013/08/how-to-load-slowly-changing-dimensions-using-t-sql-merge/ Msg 207, Level 16, State 1, Line

  • Output device not automatically determined in VF02

    Hello gurus, My default output device is not coming automatically when I add an output type in VF02. This is an issue because output type has requirement 62 set in output procedure, therefore it will not be added until invoice is release to accountin

  • Flash photo gallery, popup image

    Hi! I'm new to flash. I have created a small flash thumbnail gallery. What I would like to add now is that when you click on one of the images, a bigger version of the selected image appears as a popup. At least it looks that way. How is this done? D