user1161625
user1161625

Reputation: 662

Powershell Debug Output

I have a powershell script that creates some DotNetZip ZIP files on a persistent connection on multiple servers, then uses Start-BitsTransfer to move the ZIP files from the remote servers to the local.

I run pretty much the same script on two different servers, on one it barely prints anything to the screen. On the other, it outputs a LOT - binary looking stuff. Is this because there is some kind of debug setting that is turned on on the server that is outputting all of this info? Is there a way I can turn it off? I'd rather it be more clean like the first server that runs the script.

Thank you!

-Jim

Here is almost the entire script (without my servernames in the $webServers array:

Import-Module BitsTransfer

        foreach($i in $webServers) {

                if (!(Test-Path -path \\$i\d$\newDeploy)) {
                    New-Item \\$i\d$\newDeploy -type directory
                }
                if (!(Test-Path -path \\$i\d$\newDeploy\backup)) {
                    New-Item \\$i\d$\newDeploy\backup -type directory
                }   
                if(!(Test-Path \\$i\d$\newDeploy\Ionic.Zip.dll)) {
                    Start-BitsTransfer -Source \\$webDeployServer\d$\newDeploy\Ionic.Zip.dll -Destination \\$i\d$\newDeploy
                }

        }

        foreach($i in $webServers) {

            $sessionForI = New-PSSession -computername $i
            Invoke-Command -Session $sessionForI -ScriptBlock {

                if ((Test-Path D:\\newDeploy\\backup\\OffM.zip)) {
                    Remove-Item D:\\newDeploy\\backup\\OffM.zip
                }
                [System.Reflection.Assembly]::LoadFrom("D:\\newDeploy\\Ionic.Zip.dll");
                $zipfile = new-object Ionic.Zip.ZipFile
                $e = $zipfile.AddSelectedFiles("name != '*.e2e'","D:\inetpub\wwwroot\OffM", "OffM",1)
                $e = $zipfile.AddSelectedFiles("name != '*.e2e'","D:\inetpub\wwwroot\PaEnterprise", "PaEnterprise",1)
                $zipfile.Save("D:\\newDeploy\\backup\\OffM.zip")
                $zipfile.Dispose()

                if ((Test-Path D:\\newDeploy\\backup\\Others.zip)) {
                    Remove-Item D:\\newDeploy\\backup\\Others.zip
                }
                [System.Reflection.Assembly]::LoadFrom("D:\\newDeploy\\Ionic.Zip.dll");
                $zipfile = new-object Ionic.Zip.ZipFile
                $e = $zipfile.AddSelectedFiles("name != '*.e2e'","D:\inetpub\wwwroot\MstrInt-PO", "MstrInt-PO",1)
                $e = $zipfile.AddSelectedFiles("name != '*.e2e'","D:\inetpub\wwwroot\Maint", "Maint",1)
                $zipfile.Save("D:\\newDeploy\\backup\\Others.zip")
                $zipfile.Dispose()

                if ((Test-Path D:\\newDeploy\\backup\\PPO.zip)) {
                    Remove-Item D:\\newDeploy\\backup\\PPO.zip
                }
                [System.Reflection.Assembly]::LoadFrom("D:\\newDeploy\\Ionic.Zip.dll");
                $zipfile = new-object Ionic.Zip.ZipFile
                $e = $zipfile.AddSelectedFiles("name != '*.e2e'","D:\inetpub\wwwroot\HC", "HC",1)
                $e = $zipfile.AddSelectedFiles("name != '*.e2e'","D:\inetpub\wwwroot\PaOn", "PaOn",1)
                if($i -eq 'PYRALNWSP02V') {
                    $e = $zipfile.AddSelectedFiles("name != '*.e2e'","D:\inetpub\wwwroot\HearPl", "HearPl",1)
                } else {
                    $e = $zipfile.AddSelectedFiles("name != '*.e2e'","D:\inetpub\wwwroot\HearPaPlu", "HearPaPlu",1)
                }
                $zipfile.Save("D:\\newDeploy\\backup\\PPO.zip")
                $zipfile.Dispose()

                if ((Test-Path D:\\newDeploy\\backup\\TiMan.zip)) {
                    Remove-Item D:\\newDeploy\\backup\\TiMan.zip
                }
                [System.Reflection.Assembly]::LoadFrom("D:\\newDeploy\\Ionic.Zip.dll");
                $zipfile = new-object Ionic.Zip.ZipFile
                $e = $zipfile.AddSelectedFiles("name != '*.e2e'","D:\inetpub\wwwroot\TiManView", "TiManView",1)
                $e = $zipfile.AddSelectedFiles("name != '*.e2e'","D:\inetpub\wwwroot\TiManOnline", "TiManOnline",1)
                $e = $zipfile.AddSelectedFiles("name != '*.e2e'","D:\inetpub\wwwroot\TiManPOne", "TiManPOne",1)
                $zipfile.Save("D:\\newDeploy\\backup\\TiMan.zip")
                $zipfile.Dispose()

            }
            remove-PSSession -session $sessionForI

        }
        foreach($i in $webServers) {
            if(!(Test-Path -path D:\newDeploy\backup\$i)) {
                New-Item D:\newDeploy\backup\$i -type directory
            }
            Start-BitsTransfer -Source \\$i\d$\newDeploy\backup\OffM.zip -Destination D:\newDeploy\backup\$i
            Start-BitsTransfer -Source \\$i\d$\newDeploy\backup\Others.zip -Destination D:\newDeploy\backup\$i
            Start-BitsTransfer -Source \\$i\d$\newDeploy\backup\PPO.zip -Destination D:\newDeploy\backup\$i
            Start-BitsTransfer -Source \\$i\d$\newDeploy\backup\TiMan.zip -Destination D:\newDeploy\backup\$i
        }
        foreach($i in $webServers) {
            Remove-Item \\$i\d$\newDeploy\backup\OffM.zip
            Remove-Item \\$i\d$\newDeploy\backup\Others.zip
            Remove-Item \\$i\d$\newDeploy\backup\PPO.zip
            Remove-Item \\$i\d$\newDeploy\backup\TiMan.zip
        }
        [System.Reflection.Assembly]::LoadFrom("D:\\newDeploy\\Ionic.Zip.dll");
        $directoryToZip = "D:\newDeploy\backup"
        $date = get-date -format "M-d-yyyy"
        $zipfile = new-object Ionic.Zip.ZipFile
        $e = $zipfile.AddSelectedFiles("name != '*.e2e'",$directoryToZip, "",1)
        $zipfile.Save("D:\\newDeploy\\backup\\"+$date+"_WEBbackup.zip")
        $zipfile.Dispose()

Upvotes: 1

Views: 1145

Answers (1)

manojlds
manojlds

Reputation: 301037

There is a debug messages setting like that - $DebugPreference

It's default is SilentlyContinue. See if it is set to something else.

It would help if you also showed the difference in output. It could also be a verbose output as controlled by the $VerbosePreference

Look here to know about the preference varibales - http://technet.microsoft.com/en-us/library/dd347731.aspx

Update:

Add a [void] before [System.Reflection.Assembly]::LoadFrom statements so that the output doesn't pollute the script output.

Upvotes: 1

Related Questions