Powershell scripts not writing it to output file

Hi,
Below is my script which loops through all sites and web in a site collection and if the particular web part is added in a page, it will give the page URL and it should be written to a output file.
function enumerateWebParts($Url)
$webApp = Get-SPWebApplication $Url #Get WebApplication URL
foreach($web in $webApp | Get-SPSite -Limit All | Get-SPWeb -Limit All) #foreach loop to iterate through all sites and webs of WebApplication
if ([Microsoft.SharePoint.Publishing.PublishingWeb]::IsPublishingWeb($web)) #Check if site is a publishing site
$pWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
$pages = $pWeb.PagesList
foreach ($item in $pages.Items)
$fileUrl = $webUrl + "/" + $item.File.Url
$manager = $item.file.GetLimitedWebPartManager([System.Web.UI.WebControls.Webparts.PersonalizationScope]::Shared);
$wps = $manager.webparts
foreach ($type in $wps) #loop through each type found $wps
#Write-Host " type searching";
Write-Host $type.GetType().Name;
if ($type.GetType().Name -eq "RightMenu") #if webpart $type -like KWizCom select webpart object
Write-Host "found";
$wps | select-object @{Expression={$pWeb.Url};Label="Web URL"},@{Expression={$fileUrl};Label="Page URL"},DisplayTitle, IsVisible, @{Expression={$type};Label="Type"}
Write-Host $fileUrl;
$page=$pweb.Url+$fileUrl;
Write-Output $page;
else #if web is not a publishing site
$pages = $null
$pages = $web.Lists["Site Pages"]
if ($pages)
foreach ($item in $pages.Items)
$fileUrl = $webUrl + "/" + $item.File.Url
$manager = $item.file.GetLimitedWebPartManager([System.Web.UI.WebControls.Webparts.PersonalizationScope]::Shared);
$wps = $manager.webparts
foreach ($type in $wps)
if ($type.GetType().Name -eq "RightMenu")
$wps | select-object @{Expression={$Web.Url};Label="Web URL"},@{Expression={$fileUrl};Label="Page URL"},DisplayTitle, IsVisible, @{Expression={$type};Label="Type"}
Write-Host $fileUrl;
$page=$pweb.Url+$fileUrl;
Write-Output $page;
else
# Write-Host “… completed processing” $web
$row = enumerateWebParts(‘http://sptest.danfoss.net’) #call the enumerateWebParts function pass it the URL for the web application
I run the command through D:\RightMenu.ps1 | Out-File D:\RightMenu.txt
Aruna

Try 
http://stackoverflow.com/questions/10340007/exporting-powershell-output-to-text-file
You can always redirect the output an exe to a file like so (even from cmd.exe):
powershell c:\test.ps1 > c:\test.log
Within PowerShell, you can also redirect individual commands to file
but in those cases you probably want to append to the log file rather
than overwrite it e.g.:
$logFile = 'c:\temp\test.log'
"Executing script $($MyInvocation.MyCommand.Path)" > $logFile
foreach ($proc in Get-Process) {
$proc.Name >> $logFile
"Another log message here" >> $logFile
If this helped you resolve your issue, please mark it Answered

Similar Messages

  • Powershell script not executing in Windows 8.1 TS

    I have this simple powershell script that will create a log file in a certain directory. I added a "Run Command Line" step in my task sequence to call my powershell script
    C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File .\POSTINSTALL.ps1
    When I did not specify any account in "Run this step as the following account" section, the log file was created in the directory. But when I specify an account in "Run this step as the following account", the log file was not created.
    The account that I have used have full admin rights on the directory as I have added the account in local admin group using another task sequence step. I have also modified the security rights of the folder to give all users and administrators to have full
    control of the folder, but the log file was not created. Any idea why the script only works with System account?
    Note that I have only experience this on a Windows 8.1 OS. The script works in Windows 7 whether I specify an account in "Run this step.." or not.

    If that is all you are doing, why not run it without content?
    powershell.exe -executionpolicy bypass -command "& {New-Item C:\Windows\PCLOGS\Logs\TS-Test.log -ItemType File}"
    We use Run Command Line steps in literally dozens of steps in our task sequences. I would remove the path and let the TS control which architecture of PowerShell to call, that may be your problem.
    Daniel Ratliff | http://www.PotentEngineer.com

  • Powershell Script Not putting any data in output

    I have a powershell script that matchs a text file with file names to a directory consisting of data files On the first match between these 2 it should copy the matched file in the directory to another directory.'
    The text file consists of file names only    The directory consists of the text data for these file name
    test1.txt                                                   test4
    test2.txt                                                   test3
    test3.txt                                                   test5
    Inside test2 test3 and test3 are DB deployments scripts.
    Since test3 is the first match the data file test3 should move to an output directory but its not 
    Here is my script
    $objFolder = "C:\Serena\ReleaseAutomationAgent\core\var\work\ABS_SQL\"  #(directory)
    $objFile = "C:\Serena\ReleaseAutomationAgent\core\var\work\tmp\compare2.txt" #(File)
    $outFile ="C:\Serena\ReleaseAutomationAgent\core\var\work\ABS_SQL\deploy\"  #Output Directory
    Compare-Object -ReferenceObject (gc $objFile) -DifferenceObject (gci $objFolder|select -ExpandProperty Name) -ExcludeDifferent -IncludeEqual|select -first 1 -Expand InputObject | %{Copy-Item "objFolder\$_" -Dest $outFile}
    Any help on this would be appreciated

    That seems horribly convoluted.
    I'd do something like this:
    $objFolder = "C:\Serena\ReleaseAutomationAgent\core\var\work\ABS_SQL\" #(directory)
    $objFile = "C:\Serena\ReleaseAutomationAgent\core\var\work\tmp\compare2.txt" #(File)
    $outFile ="C:\Serena\ReleaseAutomationAgent\core\var\work\ABS_SQL\deploy\" #Output Directory
    $compare = get-content $objFile
    gci $objFolder | where {$compare -contains $_.name} |
    %{Copy-Item "$objFolder\$_" -Dest $outFile}
    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

  • Powershell script not running in the task scheduler...

    I've created a .ps1 script to transfer a file using WinSCP can run it in the ISE environment, in the PS window, and with the run command. I've transferred the command I used in the run prompt to the task scheduler but it is not running. It is running everywhere
    else just not in the scheduler. It says that it completes okay and gives a return code of OpCode=2
    The action is set to run this: c:\Windows\System32\WindowsPowerShell\v1.0\Powershell.exe
    The Arguments: -ExecutionPolicy Bypass -file "C:\Users\me\scriptsWCP\FileTransferPS.ps1"
    Also have it running with the highest permission and as SYSTEM

    Hi,
    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

  • How to combine 3 PowerShell scripts to write results to CSV file?

    Hello,
    I have 3 domains, and I like to combine the results from the Get-ADUser and write the results into one CSV file.  Can this be done?  How to do this?  Below are the 3 Get-ADUser
    scripts:
    Get-ADUser -Filter {enabled -eq "true" -and title -like "*"} -SearchBase "DC=domain1, DC=com" -Properties hiredate, department, surname, displayname  export-csv "d:\scripts\pbtfusers.csv"
    Get-ADUser -Filter {enabled -eq "true" -and title -like "*"} -SearchBase "DC=domain2, DC=com" -Properties hiredate, department, surname, displayname  export-csv
    "d:\scripts\pbtfusers.csv"
    Get-ADUser -Filter {enabled -eq "true" -and title -like "*"} -SearchBase "DC=domain3, DC=com" -Properties hiredate, department, surname, displayname  export-csv
    "d:\scripts\pbtfusers.csv"
    Paul

    Sure:
    Get-ADUser tester1 | Export-Csv .\userOutput.csv
    Get-ADUser tester2 | Export-Csv .\userOutput.csv -Append
    Get-ADUser tester3 | Export-Csv .\userOutput.csv -Append
    Sample output:
    PS C:\Scripts\PowerShell Scripts\Misc Testing\9-3-2014> Import-Csv .\userOutput.csv | Select Name
    Name
    tester1
    tester2
    tester3
    This is an extremely simplified example. It returns three user objects and writes them all to the output file one at a time.
    Don't retire TechNet! -
    (Don't give up yet - 13,085+ strong and growing)

  • Applet writing on a output file

    I am new to JAVA and I've got jdk 1.4.1 downloaded.
    I am thinking it is possible to have a JAVA applet
    which writes on a output file.
    In order to do that, I tried to use the code below, where the Applet "write.class" should display a string on a painted area and write to file "myfile.txt".
    Now compilation is OK (no error or warning messages), and I tried to incorporate this Applet into a HTML code (by using the sintax <applet code="write.class" width=200 height=50> </applet>).
    When I open the HTML document using Internet Explorer the Applet is run, but the file "myfile.txt" is not created.
    Can somebody explain me what is going wrong?
    Any suggestion or comment is welcome and appreciated.
    import java.applet.Applet;
    import java.awt.*;
    import java.io.*;
    public class write extends Applet {
    public void paint(Graphics g) {
    g.drawString("The Java Applet is Writing!",20,30);
         main();
    public static void main(){ 
    FileOutputStream out;
    PrintStream p;
         try
              out = new FileOutputStream("myfile.txt");
    p = new PrintStream( out );
              p.println ("This is to be written to a file");
    p.close();
         catch (Exception e)
              System.err.println ("Error writing to file");

    applets are not allowed to write to the local file system.
    you wouldn't like something that came with a web site without your confirmation fill up your hard drive, would you?

  • Creating Powershell script to run against Multiple XML Files: Correcting Nordic characters. Renaming only the files that were corrected.

    Greetings,
    I am new to powershell and scripting and would like to create a powershell script to do the following to XML files.
    I would like to change the data received in XML files that contains special Nordic characters: such as 
    ä, Ä, é, ö, Ö, ü, Ü, and ß respectfully.
    The file names that gets drop to me come in with the following naming convention: C54ABC_111120140500_1, C54ABC_111120140500_2, C54ABC_111120140500_3, C54ABC_111120140500_4 all the way to C54ABC_111120140500_12.
    By automating the script, I would like the script to look into a directory containing these files and access the data within it and change the the data that has the special characters to the English Dictionary character equivalent.
    e.g. ä for a, Ä for A, é for e, ö for o, Ö for O, ü for u, Ü for U, and ß for ss.
    Once that step is complete. I would like to rename the file from C54ABC_111120140500_1.xml to C54ABC_111120140500_1_rctf.xml (adding an additional 5 characters to the end of a file that was corrected) if the file did not need any correction then renaming is
    not needed.
    the working directory (Source and destination) will remain in the same location. e.g. C:\Temp\
    Currently I was able to come up with the following, however I am stuck when it comes to the renaming part since, it requires "IF and Else" statments .... I think.
    $Source = "C:\Temp"
    $Destination = "C:\Temp"
    $regex33 = "\*.xml"
    (Get-Content $regex33) |
    ForEach-Object {$_ -replace "ä", "a" -replace "Ä", "A" -replace "é", "e" -replace "ö", "o" -replace "Ö", "O" -replace "ü", "u" -replace "Ü", "U" -replace "ß", "ss"}
    #Rename-Item -NewName {$_.name -replace -whatif}
    Your Assistance and Expertise is greatly appreciated.
    Thank you in advance KC.

    Hi KC
    You could try something like this.
    Let me know how you get on and if you've any questionds.
    cheers, Tim
    $Source = 'C:\Temp'
    Set-Location $source
    $xmlFiles = Get-ChildItem -Path $source -Filter *.xml
    ForEach ($xmlFile in $xmlFiles)
      $content = Get-Content -Path $xmlFile.FullName
      $renameFile = $false
      Switch -Wildcard ($content) {
        '*ä*'
          $renameFile = $true
          $content = $content -creplace 'ä', 'a'
        '*Ä*'
          $renameFile = $true
          $content = $content -creplace 'Ä', 'A'
        '*é*'
          $renameFile = $true
          $content = $content -creplace 'é', 'e'
        '*ö*'
          $renameFile = $true
          $content = $content -creplace 'ö', 'o'
        '*Ö*'
          $renameFile = $true
          $content = $content -creplace 'Ö', 'O'
        '*ü*'
          $renameFile = $true
          $content = $content -creplace 'ü', 'u'
        '*Ü*'
          $renameFile = $true
          $content = $content -creplace 'Ü', 'U'
        '*ß*'
          $renameFile = $true
          $content = $content -creplace 'ß', 'ss'
      If ($renameFile)
        $newFileName = "$($xmlFile.BaseName)_rctf.xml"
        $content | Out-File -FilePath $xmlFile.FullName -Force
        Rename-Item -Path $xmlFile.PSChildName -NewName $newFileName

  • Bridge CS3 not writing metadata to JPEG files

    For the last couple of months (without my noticing until a couple days ago) all JPEG files that I have edited using Bridge CS3 (on Windows XP) do not have the metadata built into the file. Here are the symptoms: use "File Info" to edit the metadata for a JPEG file (i.e. add a title, description, copyright info, etc.), all appears normal, but if you do any of the following, the metadata you entered disappears:
    - duplicate (the metadata does not exist in the duplicate file)
    - move or copy to another folder
    - open in Photoshop or any other software that can read metadata (File Info shows none of the metadata you entered)
    - rebuild the cache for the folder
    Strangely, the metadata still appears with the file when you look at it in Bridge as long as you don't do any of the above.
    This is really awful as I've put a lot of time into entering this metadata for hundreds of files. Older files (pre-Nov 08) don't have this problem and the metadata is "sticky" and doesn't get deleted. So, somehow my Bridge CS3 got corrupted along the way.
    Has anyone experienced this and more importantly -- do you have a solution? I've tried reseting all Bridge settings (but that of course purged the cache and deleted all my metadata.)

    Hey,
    There are various date/time fields shown in properties panel in Organizer. The dates mentioned in general section are read from OS whereas the dates in EXIF field are read from image's EXIF data. In EXIF data there are three date/time fields-
    1. Date time- This date/time info shows date modified of EXIF properties. So when you are writing a tag into imags's IPTC, you are doing some change in EXIF data. Hence this date should change to date when you are writing a tag into IPTC.
    2. Date time original - Represents date time when a image was shoot.
    3. Date digitized - Represents the date when the image was digitized (in digital camers there is hardly some delay between an image is shoot and it is digitized. So this field is always same as date original).
    So, in your scenario, Date time in EXIF should change whenever you are writing any tag into its IPTC.
    Please let me know if you need more info on it.
    ~Andromeda

  • PSE5 not writing tags to photo files

    Having invested hours, weeks, and months in the process of tagging my many thousands of family photographs within PSE5, I am dismayed to find that having taken the manual step of writing the tags to the files, that only some of them have indeed done so. Quite a few of my photo files are showing up in Windows Explorer with the tags I have given them safely in place - great. However, twice as many appear to not be tagged at all. Can anyone explain to me what has happened and how I can rectify it, please? The prospect of having to tag them all again leaves me wanting to go and stick my head in a blender.
    A second problem is that, inexplicably, PSE5 recently started creating duplicate photo files with a "edTMP" suffix - they recreate the exact same file with the exact same file size. The only difference is that, where tags have been saved to a photo, the "edTMP" version does not include the tags. So, I just delete these files, but with the number that PSE is creating, it is a very time consuming job. Does anyone have any idea why this is happening and how I can stop it, please?
    Many, many thanks in advance to anyone who can help me rectify these really maddening issues. Thanks! And best wishes.

    First problem - It might be possible that while using 'Write keyword tag and properties info to photos' option, Organizer may have shown some errors (saying like 'Skipping invalid files'). As a result write operation may not be applied on some files. This may happen if there are some permissions issues with images. Please check that all your files are writable.
    Second option - This is an extension of first problem. Whenever Organizer fails to do any file operation (in your case 'Write keyword tag..' option), it creates a temp file. There is no way of deleting these files from withing Organizer (you need to delete them manually).
    ~Andromeda

  • Syndicator Preview tab values are not same to Syndicator Output file

    HI All,
    I am struct with the following issue, can any one give there inputs where the issue is:
    In the MDM Syndicator preview tab I can see the look up flat multiple table values... But in the output file I cant abel to see the entire node at all... Do I need to make some configuration?
    Thanks
    Rajeev

    HI All,
    I am struct with the following issue, can any one give there inputs where the issue is:
    In the MDM Syndicator preview tab I can see the look up flat multiple table values... But in the output file I cant abel to see the entire node at all... Do I need to make some configuration?
    Thanks
    Rajeev

  • Writing to an output file

    Hello all,
        I have an ABAP program in BW which reads the data from a BW ODS active table and writes the output to an external file on the server.
        The file that is generated is huge(13 MB). The file is generated with the correct results, but along with the data, the program header(filename, path, etc) is also written to the output file which is undesirable. The header is written for every few hundred pages. I want to avoid this.
    Database is Oracle.
       The syntax for the file declaration is..
    PARAMETERS: fileout(120) type c lower case default 'xxxx.csv' 
                        obligatory.
    and the open statement is as follows....
    OPEN DATASET fileout FOR OUTPUT IN TEXT MODE ENCODING DEFUALT.
    In the above statement I want to try taking out the "ENCODING DEFAULT" clause, but it says "in TEXT MODE the ENCODING must be added". I have seen other programs which are already there without that clause.
       Any suggestions will greatly appreciated. Thanks.
    Message was edited by: Ajay

    I can't seem to re-create the problem.  You can you please post the exact code of the program, so that we may try to re-create your problem. 
    This program works fine in my WebAs 7.0  system.
    report  zrich_0001.
    data: d1(100) type c value '/usr/sap/NSP/SYS/test.txt'.
    data: begin of itab occurs 0,
          fld1(20) type c,
          fld2(20) type c,
          fld3(20) type c,
          fld4(20) type c,
          fld5(20) type c,
          fld6(20) type c,
          end of itab.
    data: wa like line of itab.
    start-of-selection.
      do 10000 times.
        wa-fld1 = sy-index.
        wa-fld2 = sy-index.
        wa-fld3 = sy-index.
        wa-fld4 = sy-index.
        wa-fld5 = sy-index.
        wa-fld6 = sy-index.
        append wa to itab.
      enddo.
      open dataset d1 for output in text mode encoding default.
      loop at itab.
        transfer itab to d1.
      endloop.
      close dataset d1.
    Regards,
    Rich HEilman

  • Barcode font not visible in Bursting output file

    My requirement is to email the xml report output to mailing list. I have attached the bursting control file to do this. But the email attachment file is not showing the barcode font.
    I have defined the font and font mapping set and updated the mapping set to the template code using the configuration setup. With this i m able to see the barcode font in the xml report output. But the email attachment is not showing the barcode font.
    I followed the method2 mentioned in the below link,
    http://blogs.oracle.com/xmlpublisher/2007/09/bursting_barcodes.html
    and font file in JRE_TOP/lib/fonts directory and placed the xdo.cfg file in JRE_TOP( in my client instance its called as AF_JRE_TOP). But still the email attachment did not show barcode font.
    Please let me know if any of the steps requires changes. Kindly assist me to get the barcode font in the bursting output.
    xdo.cfg file contents as follows,
    <config version="1.0.0" xmlns="http://xmlns.oracle.com/oxp/config/">
    <!-- Properties -->
    <properties>
    <!-- System level properties -->
    <!-- PLEASE SELECT A VALID TEMPFILE DIRECTORY!!! -->
    <property name="system-temp-dir">/tmp</property>
    <!-- PDF compression -->
    <property name="pdf-compression">true</property>
    <!-- PDF security -->
    <property name="pdf-security">false</property>
    <property name="pdf-open-password">user</property>
    <property name="pdf-permissions-password">owner</property>
    <property name="pdf-no-printing">true</property>
    <property name="pdf-no-changing-the-document">true</property>
    </properties>
    <!-- Font setting -->
    <fonts>
    <font family="Free 3 of 9 Extended" style="normal" weight="normal">
    <truetype path="/fonts/FRE3OF9X.ttf" />
    </font>
    </fonts>
    </config>
    Edited by: 830913 on Jan 24, 2011 9:46 PM
    Edited by: 830913 on Jan 24, 2011 9:50 PM

    Never Mind. I forgot to do font mappings :( (duh!!)

  • Re : Powershell does NOT return errorcode to CMD file thats invoking PS

    Hello there,
    I am trying to return the exit code from PS back to CMD file that invokes the PS. Funny thing is PS does print exit code as 1 but CMD files still shows errorlevel as 0..... not sure what is causing it. The catch block in PS , I attempted to make generic
    and seems catch the exception correctly and is also printing the errorcode as 1 in PS. but upon exit 1 in PS , CMD file still shows %ERRORCODE% as 0 !
    Appreciate suggestions on this.
    CMD File
    :DBLOGIN
    CALL login.cmd username
    if %errorlevel% == 1 goto badend
    SET PWORD=%PASS_WORD%
    :ADLOGIN
    CALL AD_login.cmd %5
    if %errorlevel% == 1 goto badend
    SET AD_PWORD=%AD_PASS_WORD%
    SET PS_DIR=%1
    SET ROOT_DIR=%2
    SET UNAME=%3
    SET CONNSTR=%4
    SET ELE_UNAME=%5
    SET GROUPNAME=%6
    SET GROUPDOMAINNAME=%7
    SET DIR=%8
    d:
    cd %ROOT_DIR%
    %PS_DIR% -File "%ROOT_DIR%\adsync.ps1" %UNAME% %PWORD% %CONNSTR% %ELE_UNAME% %AD_PWORD% %GROUPNAME% %GROUPDOMAINNAME% %DIR% 2>&1 | more
    echo error level is %ERRORLEVEL%
    if %ERRORLEVEL% NEQ 0 GOTO badend
    GOTO ENDPROC
    :badend
    REM BAD END %ERRORLEVEL%
    @ECHO OFF & ECHO. & DATE /T & TIME /T & ECHO. & @ECHO ON
    exit /B 55
    :ENDPROC
    REM ACCEPTABLE RETURN CODE FOUND
    REM Error Level - %ERRORLEVEL%
    @ECHO OFF & ECHO. & DATE /T & TIME /T & ECHO. & @ECHO ON
    EXIT /B 0
    The powershell code is : 
    Import-Module ActiveDirectory
    $returncode =0;
    try
    $forestName = ([System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()).Name
    $ADsPath = [ADSI]"GC://$forestName"
    $Search = New-Object System.DirectoryServices.DirectorySearcher($ADsPath)
    $OraClientDir=$args[7];
    echo $OraClientDir;
    [Reflection.Assembly]::LoadFile("$($OraClientDir)Oracle.DataAccess.dll")
    $DBUserName=$args[0];
    $DBPassword=$args[1];
    $DBSourceName=$args[2];
    $eleuser=$args[3];
    echo $eleuser;
    $elepword=ConvertTo-SecureString -String $args[4] -AsPlainText -Force;
    echo $elepword;
    $Credentials=New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $eleuser,$elepword;
    echo $Credentials;
    $ADGroupName=$args[5];
    echo $ADGroupName;
    $ADGroupServerName=$args[6];
    echo $ADGroupServerName;
    $ADGroupServerString="$($ADGroupName) -server ""$($ADGroupServerName)""" ;
    echo $ADGroupServerString;
    Write-Host \n;
    echo " Start time is : $(Get-Date -format "yyyy:MM:dd hh:mm:ss:tt") ";
    $con=New-Object Oracle.DataAccess.Client.OracleConnection("Data Source=$DBSourceName;User Id=$DBUserName;Password=$DBPassword")
    $con.open()
    $cmd=$con.CreateCommand()
    $cmd.CommandText="SELECT blah blah SQL"
    $rdr=$cmd.ExecuteReader()
    $found= $false;
    $counter=0;
    $counterNew=0;
    $group=Get-ADGroup $ADGroupName -server $ADGroupServerName;
    $members = @()
    Get-ADGroupMember -Identity $group | Select-Object -ExpandProperty sAMAccountName |ForEach-Object {$members += $_};
    $path="\logs\log_$(Get-Date -format yyyy_MM_dd_hh_mm_ss_tt).log";
    Write-Host "The total members in group " $group " are " $members.length;
    Add-Content -Path $path -Value ("The total members in group " + $group + " are " + $members.length ) -Force;
    while ($rdr.Read())
    for ($i=0;$i -lt $rdr.FieldCount ; $i++)
    $found= $false;
    $s=$rdr.GetValue($i);
    $Search.Filter = "(&(objectCategory=User)(SamAccountName=$s))"
    if ($Search.FindAll().Count -eq 0)
    Add-Content -Path $path -Value "The user $s does NOT exists in AD global catalog" -Force;
    Write-Host "The user : " $s "does NOT exists in AD global catalog" ;
    $counter++;
    else {
    try {
    foreach ($res in $Search.FindAll())
    $User = $res.GetDirectoryEntry();
    Add-Content -Path $path -Value ("The user " + $User.SamAccountName + " Found in AD global catalog") -Force;
    Write-Host "The user distinguished name is : " $User.DistinguishedName " Found in AD global catalog" ;
    $DC = $User.DistinguishedName.ToString();
    $DCString = $DC.SubString($DC.IndexOf("DC="));
    $FQDN = $DCString.replace("DC=","").replace(",",".");
    # Add-Content -Path $path -Value $FQDN -Force;
    $found = $true;
    if ( ($found) -and ($members -notcontains $s))
    $checkuser= Get-ADUser $User.SamAccountName.ToString() -Server $FQDN ;
    Add-ADGroupMember $group -Members $checkuser -Server $ADGroupServerName -Credential $Credentials;
    Add-Content -Path $path -Value ("Added user: " + $User.SamAccountName ) -Force ;
    Write-Host "Added user: " $User.SamAccountName;
    $counterNew++;
    } catch [Exception] {
    Write-Host $_.Exception.Message "is inner catch";
    $returncode =1;
    Add-Content -Path $path -Value "Total of : $counterNew users users have been added " -Force;
    Write-Host "Total of : $counterNew users users have been added to AD Group";
    Add-Content -Path $path -Value "Total of : $counter users do NOT exist in Windows AD global catalog";
    Write-Host "Total of : $counter users do NOT exist in Windows AD global catalog";
    catch [Exception] {
    Write-Host $_.Exception.Message "is outer catch";
    $returncode =1;
    Write-Host \n;
    echo " End time is : $(Get-Date -format "yyyy:MM:dd hh:mm:ss:tt") ";
    Write-Host "value of return code is " $returncode;
    exit $returncode;

    Maybe the webpages below can help someone compose a workaround
    https://connect.microsoft.com/PowerShell/feedback/details/750653/powershell-exe-doesn-t-return-correct-exit-codes-when-using-the-file-option
    https://connect.microsoft.com/PowerShell/feedback/details/750653/powershell-exe-doesn-t-return-correct-exit-codes-when-using-the-file-option#

  • ITunes not writing tag info to file

    Recently iTunes hasn't been writing the tag info to the mp3 files when I import a new cd. I've never had a problem with this until recently.
    I'm using iTunes 6.0.5 on a Intel Mini 1.66 with OS 10.4.6. When I insert a new disc it shows the proper track, artist, album, etc info. It titles the tracks correctly and puts them in my iTunes library correctly. However, when I check the tag info in MediaRage it shows nothing! I don't think it's a problem with MediaRage because I tried to import the cds on my Powerbook and they import fine.
    I discovered this when I recently needed to reformat my music harddrive. When I copied the files back into iTunes a bunch of tracks came up as unknown artist and album. When I checked them furhter I found they were the last 6 or 7 cds I had imported. So they went into iTunes initially with the correct info, but the tag info hadn't been written, so when I reimported them iTunes organized them into the unknown folder.
    I've been able to work around this by using the convert id3 tags command immediately after importing a new cd. Then all the info shows up correctly in MediaRage. But I shouldn't have to do this extra step! I've updated to the latest version of iTunes in case the last version was corrupted somehow. That didn't help. I've looked for the iTunes preferences file but can't find it.
    So sorry for the long ramble but I've searched everywhere and can't find a solution or even anyone else mentioning this problem.
    HELP!
    tia
    G4 Titanium Powerbook, Intel Mac Mini   Mac OS X (10.4.6)   ext WD 320gb

    It's difficult to say what's causing this problem, although at this moment in time there still seem to be a lot of bugs with various software when running on Intel-based Macs.
    Unfortunately, for some odd reason, iTunes writes ID3 v. 2.2 tags by default rather than the more acceptable v. 2.3 (or even 2.4). You might try ripping your CDs with Max using the provided (LAME) MP3 encoder. You should get more accurate rips to start with (using the paranoia ripper), and the highest qualtiy MP3s using the superior LAME encoder. Your files will have ID3 v. 2.4 tags written to them. You can also configure Max, in its preferences, to add files directly to your iTunes library upon encoding for perfect integration with iTunes. Hopefully this will work well for you and your files will retain their metadata.

  • Reports 2.5 over-writing an existing output file

    When I try to save the Reports 2.5 output to a file that already exists, the application seems to work. However, the Report Server logs indicate an error - Rep 1081 - Unable to open file ...
    When you check if the file was created, its even worse that the original file has already been deleted - (puff! ... gone).
    Am on NT4.0 as client, could this be an NT bug or am just missing something on my code?
    Hints and suggestions please.
    null

    I really appreciate your help, but I already changed the configuration to open a file path taking another ActiveX example as a reference. Here is my subVI's I used, but they are merged in LLB. I am sorry for my ignorance of how to extract all the subVI's from this file.
    Attachments:
    ExcelExamples.llb ‏62 KB

Maybe you are looking for