Using the SharePoint Administrator PowerShell command Import-SPWeb, I loop through many backup files, each generates the output:

Log file generated:

With the amount of files imported these messages make error and tracking output unmanageable. How can I suppress the message & still generate the log?

The following does not work

 Import-SPWeb -Identity... | Out-File $null 


I have attempted to use Start-Job with a script block but it does not seem to actually run the command.

Invoke command with scriptblock outputs the writing I want to avoid

I have been attempting to work with runspace but even InvokeAsync seems to output the writing I wish to avoid


3 Answers 3


When I need to do this in powershell (hide output), I usually test these three ways, but I cannot try it right now :

  1. [void]Import-SPWeb ... at the beginning of the line could work
  2. Import-SPWeb ... > $null at the end of the line
  3. Import-SPWeb ... | Out-Null

Please give feedback about results.

  • '[void] import-spweb' is error. '[void](import-spweb)' still outputs. '| out-null' still outputs. '> $null' still outputs
    – user13186
    Nov 10, 2014 at 21:29
  • can you try with *>$null at the end ? (If you're using PSv3). And also $null = Import-SPWeb ...
    – Nico
    Nov 12, 2014 at 8:01

Use the -NoLogFile parameter.

Import-SPWeb -Identity http://site -Path //server/share/file.cmp -NoLogFile
  • I'm attempting to have my cake and eat it too. I need logs generated as a requirement but I want to know how to supress the text for a smooth user experience ( & to justify time spent ). Still, thanks for contributing!
    – user13186
    Nov 13, 2014 at 1:17
  • You can't. The code has a Console.WriteLine if you don't use -NoLogFile it will always show the message. Nov 13, 2014 at 19:28

I knew for a while that answer would reside in calling Import-SPWeb from a different console context since the SharePoint command seems to call console.writeline ("str"); I have learned a lot about creating powershell runspaces & Invoke commands. Ultimately I found that a solution in spawning new powershell process which cleans itself up.

Step 1: create a script for the action

  [CmdletBinding ()]
 Param ([string]$url, [string]$backupfile)
 Add-PSSnapin Microsoft.SharePoint.powershell -EA 0
  Import-SPWeb $url -Path $backupfile
  # other commands and error handling you may want

Step 2: run script in 2nd powershell process

 Start-Process powershell.exe -ArgumentList ".\myscript.ps1 -url http://site -backupfile c:\backup.cmp" -WindowStyle Hidden 

This will now execute Import-SPWeb, generate the import.log, and not output ugly text to screen. Also you may wish to look into additional start-process parameters like -RedirectStandardOutput

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.