Powershell input validition - validation

I am trying to only allow a user to enter 2 letters when they rename a file if its exists.
It is not working as I wanted it. I am allowed to enter numbers.
if ($RenameLargeFiles.Length -gt '2') {
Write-Host " You may only enter 2 letters."
Pause
Clear-Host
Rename-LargeFiles
} else {
Rename-Item -Path $LargeFiles $RenameLargeFiles".txt"
$LargeFiles = $RenameLargeFiles
Set-Content -Value $Files -Path $LargeFiles
}
}
Set-StrictMode –Version Latest
$LargeFiles = "C:\PSScripts\LargeFiles.txt"
$PSScripts = "C:\PSScripts"
$TestPSScripts = Test-Path "C:\PSScripts"
switch ($TestPSScripts) {
'False' { New-Item -Type directory -Path $PSScripts }
}
function Test-Files {
$Files8 = ""
$Files8 = Read-Host " Please Enter the Complete Path. "
$TFiles8 = Test-Path $files8
if ($TFiles8 -eq 'True') {
Write-Host $Files8 "LOCATED."
} else {
Write-Host $Files8 "NOT FOUND"
Pause
Clear-Host
Test-Files
}
}
function Test-LargeFiles {
$LargeFiles = "C:\PSScripts\LargeFiles.txt"
$TestLargeFiles = Test-Path $LargeFiles
if ($TestLargeFiles -eq 'True') {
Write-Host $LargeFiles "already present"
Rename-LargeFiles
} else {
Write-Host $LargeFiles "NOT FOUND."
Write-Host $LargeFiles "created"
}
}
function Rename-LargeFiles {
$LargeFiles = "C:\PSScripts\LargeFiles.txt"
[string] $RenameLargeFiles = Read-Host " Please Enter 2 letters to rename" $LargeFiles
if ($RenameLargeFiles.Length -gt '2') {
Write-Host " You may only enter 2 letters."
Pause
Clear-Host
Rename-LargeFiles
} else {
Rename-Item -Path $LargeFiles $RenameLargeFiles".txt"
$LargeFiles = $RenameLargeFiles
Set-Content -Value $Files -Path $LargeFiles
}
}
Test-Files
$Files = Get-ChildItem -Recurse $Files8 | Sort-Object -Descending -Property Length | Select-Object -First 10
Test-LargeFiles
Add-Content -Value $Files -Path $LargeFiles
pause

Use a regex like so:
if ($RenameLargeFiles -notmatch '[aA-zZ]{2}') {
... display error message
}

Related

Server Pending Reboot

I am trying to modify my PowerShell script to find the best possible ways to check for Pending Reboots on our servers. This script checks the registry entries. However, I am seeing inconsistencies from other PowerShell scripts and wanting guidance on the best approach.
function PendingReboot ($comp) {
process {
try {
$WMI_OS = ""
$RegCon = ""
$WMI_OS = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $comp -ErrorAction Stop
if ($?){
try{
$RegCon = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]"LocalMachine",$comp)
If ($WMI_OS.BuildNumber -ge 6001){
$RegValueSetupex = ""
$RegValuePFRO2k8 = ""
$RegSubKeySM = $RegCon.OpenSubKey("SYSTEM\CurrentControlSet\Control\Session Manager\")
$RegValueSetupex = $RegSubKeySM.GetValue("SetupExecute",$null)
if ($RegValueSetupex){
$RegValueSetupex = $true
}
$RegSubKeySM = $RegCon.OpenSubKey("SYSTEM\CurrentControlSet\Control\Session Manager\")
$RegValuePFRO2k8 = $RegSubKeySM.GetValue("PendingFileRenameOperations",$null)
if ($RegValuePFRO2k8 ){
$RegValuePFRO2k8 = $true
}
$RegCon.Close()
if ( $RegValueSetupex -eq $true -or $RegValuePFRO2k8 -eq $true){
return '<font color="#FF0000">'+$true
}
else {
return $false
}
}
else{
$RegValuePFRO2k3 = $false;
$RegCon = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]"LocalMachine","$comp")
$RegSubKeySM = $RegCon.OpenSubKey("SYSTEM\CurrentControlSet\Control\Session Manager\")
$RegValuePFRO2k3 = $RegSubKeySM.GetValue("PendingFileRenameOperations",$null)
$RegCon.Close()
If ($RegValuePFRO2k3) {
return '<font color="#FF0000">'+$true;
}
else {
return $false;
}
}
}
catch {
return '<font color="#FFFF00">'+"Remote Registry Service KO"
}
}
else {
throw $error[0].Exception
}
}
catch {
return '<font color="#FF0000">'+"RPC Issue"
}
}
}
Try this.
function PendingBoot($comp) {
$pendingRebootTests = #(
#{
Name = 'RebootPending'
Test = { Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing' Name 'RebootPending' -ErrorAction Ignore }
TestType = 'ValueExists'
}
#{
Name = 'RebootRequired'
Test = { Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update' Name 'RebootRequired' -ErrorAction Ignore }
TestType = 'ValueExists'
}
#{
Name = 'PendingFileRenameOperations'
Test = { Get-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager' -Name 'PendingFileRenameOperations' -ErrorAction Ignore }
TestType = 'NonNullValue'
}
)
$session = New-PSSession -Computer SRV1
foreach ($test in $pendingRebootTests) {
$result = Invoke-Command -Session $session -ScriptBlock $test.Test
if ($test.TestType -eq 'ValueExists' -and $result) {
$true
} elseif ($test.TestType -eq 'NonNullValue' -and $result -and $result.($test.Name)) {
$true
} else {
$false
}
}
$session | Remove-PSSession
}

POWERSHELL on server 2019 : script not working

Here's powershell script :
copy-item "\\xxx.xlsx" -destination "c:\liste\liste.xlsx" -force
$filepath = "c:\liste\liste.xlsx"
$Excel = New-Object -ComObject excel.application
$Workbook = $excel.Workbooks.open($filepath)
$Worksheet = $Workbook.WorkSheets.item("Feuil1")
$Worksheet.activate()
$line = 4
$col = 1
$MobilePhone=''
$DECTPhone=''
$FixePhone=''
$DN=''
while ($worksheet.Cells.Item($line,1).Value())
{
if ($worksheet.Cells.Item($line,4).Value() -like "*06-??-??-??-??*" -or $worksheet.Cells.Item($line,4).Value() -like "*07-??-??-??-??*" -or $worksheet.Cells.Item($line,4).Value() -like "*???-???-????*" -or $worksheet.Cells.Item($line,4).Value() -like "*????-???-????-????*")
{
$MobilePhone = $worksheet.Cells.Item($line,4).Value()
}
if ($worksheet.Cells.Item($line,5).Value() -like "*[0-9][0-9][0-9][0-9]*")
{
$DECTPhone = $worksheet.Cells.Item($line,5).Value()
}
if ($worksheet.Cells.Item($line,6).Value() -like "*01-??-??-??-??*" -or $worksheet.Cells.Item($line,6).Value() -like "*02-??-??-??-??*" -or $worksheet.Cells.Item($line,6).Value() -like "*03-??-??-??-??*" -or $worksheet.Cells.Item($line,6).Value() -like "*04-??-??-??-??*" -or $worksheet.Cells.Item($line,6).Value() -like "*05-??-??-??-??*" -or $worksheet.Cells.Item($line,6).Value() -like "*09-??-??-??-??*" -or $worksheet.Cells.Item($line,6).Value() -like "*????-???-????-????*")
{
$FixePhone = $worksheet.Cells.Item($line,6).Value()
}
$NOM = $worksheet.Cells.Item($line,1).Value()
$PRENOM = $worksheet.Cells.Item($line,2).Value()
if ((Get-ADObject -LDAPFilter "(&(GivenName=$PRENOM)(Sn=$NOM))" | ft -HideTableHeaders DistinguishedName | Out-String).Trim())
{
$DN = (Get-ADObject -LDAPFilter "(&(GivenName=$PRENOM)(Sn=$NOM))" | ft -HideTableHeaders DistinguishedName | Out-String).Trim()
#Dans le cas ou l'utilisateur à plusieurs comptes, on place $DN dans un foreach
foreach ( $a in $($DN -split "`r`n") )
{
if ( $MobilePhone -eq '' )
{
Set-ADObject -Identity $a -Clear mobile
}
else
{
if ($MobilePhone -like "*0?-??-??-??-??*")
{
Set-ADObject -Identity $a -Replace #{mobile=$MobilePhone}
}
}
if ( $DECTPhone -eq '' )
{
Set-ADObject -Identity $a -Clear otherTelephone
}
else
{
Set-ADObject -Identity $a -Replace #{otherTelephone=$DECTPhone}
}
if ( $FixePhone -eq '' )
{
Set-ADObject -Identity $a -Clear telephoneNumber
}
else
{
if ($FixePhone -like "*0?-??-??-??-??*")
{
Set-ADObject -Identity $a -Replace #{telephoneNumber=$FixePhone}
}
}
}
}
$MobilePhone=''
$DECTPhone=''
$FixePhone=''
$DN=''
$line++
}
$workbook.Close()
$excel.Quit()
Script is working on Windows 2008 R2 but not on Windows server 2019.
Set-ADObject : Type non valide « System.Double ». Nom du paramètre : otherTelephone Au caractère Ligne:63 : 5
+ ... Set-ADObject -Identity $a -Replace #{otherTelephone=$DECT ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument : (CN=XXXX\, Xx...T,DC=XXX,DC=XXX:ADObject) [Set-ADObject], ArgumentException
+ FullyQualifiedErrorId : ActiveDirectoryCmdlet:System.ArgumentException,Microsoft.ActiveDirectory.Management.Commands.SetADObject
When i initialise $NOM and $PRENOM and $DN with get-adobject, set-adobject command works without system.double error.
Thanks for help.
Found.
You shall put double quote on every set-adobject lines.
Set-ADObject -Identity $a -Replace #{otherTelephone="$DECTPhone"}
Solved.

Copying files from Multiple Folders Where the File Name is a part of the folder

'I am trying to copy multiple files from multiple folders into another folder. The folders have a part of the file name in them.
For example -
I want to copy all the files that have the name "Phone" or "cell" and the serial number as a part of the file name. Each sub folder has the serial number as a part of the folder name.
C:\shared\112\products\112.phone blah blah.txt
C:\shared\112\products\112.my cell.txt
C:\shared\113\products\113.ugly phone.txt
C:\shared\113\products\113.the cell.txt
C:\shared\114\products\114.pretty phone.txt
C:\shared\115\products\115.phone lazy.txt
C:\shared\115\products\115.celly cell.txt
The problem is there are 20,000 serial numbers so I want to set up a list of serial numbers and pull the file based on a set of serial number.
Here is my script but it is not pulling anything.'
$FirstSearchlist = #(“112”, “113”)
$SecondSearchlist = #("phone","cell")
$dirArray = #("c:\Shared\")
$NotFound = "Not Found"
cls
function Recurse([string]$path) {
$fc = new-object -com scripting.filesystemobject
$folder = $fc.getfolder($path)
foreach ($i in $folder.files) {
[string]$FullPath = $i.Path
[string]$FileName = $i.Name
foreach($first in $FirstSearchlist) {
if ($filename.ToUpper().Contains($first.ToUpper())) {
foreach($second in $SecondSearchlist) {
if ($filename.ToUpper().Contains($second.ToUpper())) {
Write-Host $Fullpath
Copy-Item $Fullpath -Destination "C:\Shared\Phones" -Recurse
}
}
}
}
}
foreach ($i in $folder.subfolders) {
Recurse($i.path)
}
}
function main() {
foreach ($i in $FirstSearchlist){
$NewFolder = $dirArray + $i
foreach($SearchPath in $NewFolder) {
Recurse $SearchPath
}
}
}
main
This worked for me testing with the example set provided (but note in my testing C:\Shared is empty, may want to adjust down your folder tree depending):
Function Get-FileMatches($Filter){
$fileMatches = Get-ChildItem -Path "C:\Shared" -Recurse | ? {$_.Mode -notmatch 'd' -and $_.Name -match $Filter -and ($_.Name -match $SecondSearchlist[0] -or $_.Name -match $SecondSearchlist[1])}
return $fileMatches
}
Function Run-Script() {
$FirstSearchlist = #(“112”, “113”)
$SecondSearchlist = #("phone","cell")
$allMatches = #()
$phonesFolderExists = Test-Path "C:\Shared\Phones"
if($phonesFolderExists -eq $False)
{
New-Item -Path "C:\Shared\Phones" -ItemType Directory -Force
}
foreach($listItem in $FirstSearchList) {
$currentMatches = Get-FileMatches -Filter $listItem
if($currentMatches -ne $null)
{
foreach($item in $currentMatches)
{
$allMatches += $item
}
}
}
if($allMatches -ne $null)
{
foreach($item in $allMatches)
{
Copy-Item -Path $item.FullName -Destination "C:\Shared\Phones"
}
}
}
Run-Script

Get free disk space for different servers with separate credentials

I'm trying to query Disk space info on Grid box and Export it to CSV.
I was able to use Marc Weisel's script to make it use different credentials. I used computers.csv
to store the computer name and referenced credentials. This is working although the problem I'm facing is that Grid box opens for all the servers mentioned in the csv.
I want to view all disk space information on the same grid box.
Below are my script and module I'm using
Import-Module D:\get.psm1
Import-Module D:\out-CSV.psm1
$ComputerList = Import-Csv -Path d:\Computers.csv;
#$servers = 'laptop-pc','laptop-pc','laptop-pc'
$CredentialList = #{
Cred1 = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList 'laptop-pc\laptop', (ConvertTo-SecureString -String 'tamboli' -AsPlainText -Force);
#Cred2 = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList 'tnt\administrator', (ConvertTo-SecureString -String 'Atlantic12' -AsPlainText -Force);
}
foreach ($computer in $ComputerList )
{
Get-DiskFree -ComputerName $Computer.Name -Credential $CredentialList[$Computer.Credential] -Format | ? { $_.Type -like '*fixed*' } | select * -ExcludeProperty Type |
}
get.ps1
function Get-DiskFree
{
[CmdletBinding()]
param
(
[Parameter(Position=0,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true)]
[Alias('hostname')]
[Alias('cn')]
[string[]]$ComputerName = $env:COMPUTERNAME,
[Parameter(Position=1,
Mandatory=$false)]
[Alias('runas')]
[System.Management.Automation.Credential()]$Credential =
[System.Management.Automation.PSCredential]::Empty,
[Parameter(Position=2)]
[switch]$Format
)
BEGIN
{
function Format-HumanReadable
{
param ($size)
switch ($size)
{
{$_ -ge 1PB}{"{0:#.#'P'}" -f ($size / 1PB); break}
{$_ -ge 1TB}{"{0:#.#'T'}" -f ($size / 1TB); break}
{$_ -ge 1GB}{"{0:#.#'G'}" -f ($size / 1GB); break}
{$_ -ge 1MB}{"{0:#.#'M'}" -f ($size / 1MB); break}
{$_ -ge 1KB}{"{0:#'K'}" -f ($size / 1KB); break}
default {"{0}" -f ($size) + "B"}
}
}
$wmiq = 'SELECT * FROM Win32_LogicalDisk WHERE Size != Null AND DriveType >= 2'
}
PROCESS
{
foreach ($computer in $ComputerName)
{
try
{
if ($computer -eq $env:COMPUTERNAME)
{
$disks = Get-WmiObject -Query $wmiq `
-ComputerName $computer -ErrorAction Stop
}
else
{
$disks = Get-WmiObject -Query $wmiq `
-ComputerName $computer -Credential $Credential `
-ErrorAction Stop
}
if ($Format)
{
# Create array for $disk objects and then populate
$diskarray = #()
$disks | ForEach-Object { $diskarray += $_ }
$diskarray | Select-Object #{n='Name';e={$_.SystemName}},
#{n='Vol';e={$_.DeviceID}},
#{n='Size';e={Format-HumanReadable $_.Size}},
#{n='Used';e={Format-HumanReadable `
(($_.Size)-($_.FreeSpace))}},
#{n='Avail';e={Format-HumanReadable $_.FreeSpace}},
#{n='Use%';e={[int](((($_.Size)-($_.FreeSpace))`
/($_.Size) * 100))}},
#{n='FS';e={$_.FileSystem}},
#{n='Type';e={$_.Description}}
}
else
{
foreach ($disk in $disks)
{
$diskprops = #{'Volume'=$disk.DeviceID;
'Size'=$disk.Size;
'Used'=($disk.Size - $disk.FreeSpace);
'Available'=$disk.FreeSpace;
'FileSystem'=$disk.FileSystem;
'Type'=$disk.Description
'Computer'=$disk.SystemName;}
# Create custom PS object and apply type
$diskobj = New-Object -TypeName PSObject `
-Property $diskprops
$diskobj.PSObject.TypeNames.Insert(0,'BinaryNature.DiskFree')
Write-Output $diskobj
}
}
}
catch
{
# Check for common DCOM errors and display "friendly" output
switch ($_)
{
{ $_.Exception.ErrorCode -eq 0x800706ba } `
{ $err = 'Unavailable (Host Offline or Firewall)';
break; }
{ $_.CategoryInfo.Reason -eq 'UnauthorizedAccessException' } `
{ $err = 'Access denied (Check User Permissions)';
break; }
default { $err = $_.Exception.Message }
}
Write-Warning "$computer - $err"
}
}
}
END {}
}
You need to append the result of Get-DiskFree to an array in the loop, and pipe that result to the Grid View from outside your loop:
foreach ($computer in $ComputerList )
{
$result += Get-DiskFree -ComputerName $Computer.Name -Credential $CredentialList[$Computer.Credential] -Format | ? { $_.Type -like '*fixed*' } | select * -ExcludeProperty Type
}
$result | Out-GridView
Or, better yet, pipe the result from outside the Foreach-Object loop:
$ComputerList | % {
Get-DiskFree -ComputerName $_.Name -Credential $CredentialList[$_.Credential] -Format | ? { $_.Type -like '*fixed*' } | select * -ExcludeProperty Type
} | Out-GridView

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()
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.

Resources