stuck in powershell please help

Dec 13, 2011 at 7:08 PM

Hi All,

I am trying to create a powershell script that walks through multiple folders which contains blg files.

After indexing these files I would like to kickoff pal.ps1 with the appropiate arguments but I get stuck in this section. I do not know how to call the pal.ps1 with the appropriate arguments from within my powershell script. I included my script.

If you have any idea how to get this done I would most appreciate this!

Kind regards, Peter

$Pal_in   = 'C:\Pal\RawPalData\Pal_In';
$Pal_Archive = 'c:\Pal\RawPalData\Pal_Archive';
$path2Pal  = 'C:\Program Files\PAL\PAL v2.1';
$PalScript  = $path2Pal + "\Pal.ps1";
$ReportPath  = 'C:\Pal\PalReports';
$Extension  = '*.blg';

#Winframe Variabelen
$SqlServers = "SRV51020","SRV51021";

$Index = Get-ChildItem -Path $Pal_In -Recurse $Extension | Select-Object;
 
foreach ($i in $index)
 {
  foreach ($Server in $SqlServers)
   {
    if ($i.FullName -match $Server)
     {
      $arg = " -log " + "'" + $i.Fullname +
        "' -thresholdfile " + "'"+ $Path2Pal +
        "\SQLServer.xml' -interval '300'  -IsOutputHtml " + '$True' +
        " -HtmlOutputFileName '[LogFileName]_PAL_ANALYSIS_[DateTimeStamp].htm' -IsOutputXml " + '$False' +
        " -XmlOutputFileName '[LogFileName]_PAL_ANALYSIS_[DateTimeStamp].xml -OutputDir " + $ReportPath +
        " -AllCounterStats " + '$False' + "-NumberOfProcessors '16' -ThreeGBSwitch " + '$False' + " -SixtyFourBit " + '$True' +
        " -TotalMemory '92' -RAID5Drives 'NULL' -RAID1Drives 'NULL'";
      $ArchiveFolder = $Pal_Archive + "\" + $Server;
      $DestinationFolder = ($pal_archive + '\' + $Server) + $i.DirectoryName.substring(($Pal_in.Length));
      $SourceSubfolder = $Pal_in + $i.DirectoryName.substring(($Pal_in.Length));
      $SourceFile = ($i.fullname.tostring());
      #if (!(test-path $ArchiveFolder)){md $ArchiveFolder};
      #if (!(test-path $DestinationFolder)){md $DestinationFolder};
      #Move-Item ($i.fullname.tostring()) $DestinationFolder;
      #rd $SourceSubFolder;
     }
   }
 }

Coordinator
Dec 14, 2011 at 2:03 AM

It looks like you are getting close. You can call other PowerShell scripts using the Invoke-Expression cmdlet.

FYI. I plan on creating a PAL Collection and Analysis user interface within the next few months.

Dec 14, 2011 at 4:53 AM

Hi Clint,

thank you for your response. I tried to use invoke-expression but parsing all of the arguments in the correct way with akll of the $ and ' signs in the arguments list was a no go, at least in my efforts. If you have any tips on parsing through these arguments please let me know...

I was hoping to get the script done this week so we can start with the automation of the pal reports.

Dec 14, 2011 at 5:46 AM

so I tried some else. I changed the path of the pal installation to c:\programs\pal

I also changed somethings to the script:

#====================================================================================
#Language        : Powershell
#Version         : 0.1
#Name            : PalPerformanceSql.ps1
#Author          :
#Date            : laatste wijziging: 12-12-2011
#Description     : Pal
#Comment         :
#Keywords        : Performance
#=====================================================================================
#Syntax: PalPerformanceSql.ps1
#====================================================================================

#Variabelen / constanten / arguments
$Pal_in   = 'C:\Pal\RawPalData\Pal_In';
$Pal_Archive = 'c:\Pal\RawPalData\Pal_Archive';
$path2Pal  = 'C:\Programs\PAL\';
$PalScript  = $path2Pal + "\Pal.ps1";
$ReportPath  = 'C:\Pal\PalReports';
$Extension  = '*.blg';

#Winframe Variabelen
$SqlServers = "RDW51020","RDW51021";

$Index = Get-ChildItem -Path $Pal_In -Recurse $Extension | Select-Object;
 
foreach ($i in $index)
 {
  foreach ($Server in $SqlServers)
   {
    if ($i.FullName -match $Server)
     {
      $arg = " -log " + "'" + $i.Fullname +
        "' -thresholdfile " + "'"+ $Path2Pal +
        "\SQLServer.xml' -interval '300' -IsOutputHtml " + '$True' +
        " -HtmlOutputFileName '[LogFileName]_PAL_ANALYSIS_[DateTimeStamp].htm' -IsOutputXml " + '$False' +
        " -XmlOutputFileName '[LogFileName]_PAL_ANALYSIS_[DateTimeStamp].xml' -OutputDir " + $ReportPath +
        " -AllCounterStats " + '$False' + " -NumberOfProcessors '16' -ThreeGBSwitch " + '$False' + " -SixtyFourBit " + '$True' +
        " -TotalMemory '92' -RAID5Drives 'NULL' -RAID1Drives 'NULL'";
      $Arg;
      Invoke-expression "$PalScript $Arg";
      $ArchiveFolder = $Pal_Archive + "\" + $Server;
      $DestinationFolder = ($pal_archive + '\' + $Server) + $i.DirectoryName.substring(($Pal_in.Length));
      $SourceSubfolder = $Pal_in + $i.DirectoryName.substring(($Pal_in.Length));
      $SourceFile = ($i.fullname.tostring());
      #if (!(test-path $ArchiveFolder)){md $ArchiveFolder};
      #if (!(test-path $DestinationFolder)){md $DestinationFolder};
      #Move-Item ($i.fullname.tostring()) $DestinationFolder;
      #rd $SourceSubFolder;
     }
   }
 }

Powershell Output: The script failed due to call depth overflow.  The call depth reached 1001 and the maximum is 1000.
At line:0 char:0

results for $Arg:

PS U:\> $arg
 -log 'C:\Pal\RawPalData\Pal_In\RDW51020_20111205-000013\PAL_Microsoft_SQL_Server_2005_2008.blg' -thresholdfile 'C:\Programs\PAL\\SQLServer.xml' -interval '300' -IsOutputHtml $True -HtmlOutputFileName '[LogFileName]_PAL_ANALYSIS_[DateTimeS
tamp].htm' -IsOutputXml $False -XmlOutputFileName '[LogFileName]_PAL_ANALYSIS_[DateTimeStamp].xml' -OutputDir C:\Pal\PalReports -AllCounterStats $False -NumberOfProcessors '16' -ThreeGBSwitch $False -SixtyFourBit $True -TotalMemory '92' -R
AID5Drives 'NULL' -RAID1Drives 'NULL'

any ideas?

Dec 14, 2011 at 6:32 AM

i also created another pal.ps1 which shows all the passthrough parameters:



#requires -Version 2.0
param($Log,$ThresholdFile="QuickSystemOverview.xml",$Interval='AUTO',$IsOutputHtml=$True,$IsOutputXml=$False,$HtmlOutputFileName="[LogFileName]_PAL_ANALYSIS_[DateTimeStamp]_[GUID].htm",$XmlOutputFileName="[LogFileName]_PAL_ANALYSIS_[DateTimeStamp]_[GUID].xml",$OutputDir="[My Documents]\PAL Reports",$AllCounterStats=$False,$BeginTime=$null,$EndTime=$null)
Set-StrictMode -Version 2 #// Contributed by Jeffrey Snover

$log;
$thresholdFile;
$interval;
$isOutputHtml;
$IsOutputXml;
$HtmlOutputFileName;
$XmlOutputFileName;
$OutputDir;
$AllCounterStats;
$BeginTime;
$EndTime;

 

this shows all the parsed arguments...

Dec 15, 2011 at 5:06 AM

To all readers..

 

stop searching, found it... be sure to, if you pass the arguments to pass the correct arguments... :-O

Jan 30, 2013 at 7:25 PM
Edited Jan 30, 2013 at 7:50 PM

Slopertje, which arguments did you miss? I ask because all the parameters in pal.ps1 have automatic default values. 

If I launch from powershell cli using the following command:

.\pal.ps1 -log 'HealthCheck_SystemOverview_000076.blg'

I receive the same error

The script failed due to call depth overflow. The call depth reached 1001 and the maximum is 1000.
CategoryInfo: InvalidOperation: (1001:Int32) [], ParentContains ErrorRecordException
FullyQualifiedErrorId : CallDepthOverflow

However if I launch from powershell cli or script using the following command:

powershell .\pal.ps1 -log 'HealthCheck_SystemOverview_000076.blg'
 

It works as expected. I'm not sure why it works by re-invoking a powershell cli, but it seems to. Hopefully this helps others.