From d76d903b4f6a1963cd7dbdab4bf130d5c03514a9 Mon Sep 17 00:00:00 2001 From: Patrick Canterino Date: Tue, 6 Mar 2018 14:35:34 +0100 Subject: [PATCH 1/1] Suppress output of New-PSDrive and New-Item --- TODO.md | 2 +- dsmonrot.ps1 | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/TODO.md b/TODO.md index 84b50f2..2326604 100644 --- a/TODO.md +++ b/TODO.md @@ -5,4 +5,4 @@ - [x] ~~Check if the network drive already exists before connecting~~ ⇒ `New-PSDrive` throws an exception if drive is already connected - [ ] Create a log file for the script - [ ] Clean up the messages sent to the console or send them to the debug or error streams (e.g. `Write-Debug` or `Write-Error`) -- [ ] Suppress output of some commands \ No newline at end of file +- [x] Suppress output of some commands \ No newline at end of file diff --git a/dsmonrot.ps1 b/dsmonrot.ps1 index 0323afb..c0ee230 100644 --- a/dsmonrot.ps1 +++ b/dsmonrot.ps1 @@ -134,12 +134,12 @@ if($smbDrive) { $secSmbPassword = $smbPassword | ConvertTo-SecureString -asPlainText -Force $smbCredential = New-Object System.Management.Automation.PSCredential($smbUser, $secSmbPassword) - New-PSDrive -Name $smbDrive -PSProvider "FileSystem" -Root $smbPath -Credential $smbCredential -Persist -ErrorAction Stop + New-PSDrive -Name $smbDrive -PSProvider "FileSystem" -Root $smbPath -Credential $smbCredential -Persist -ErrorAction Stop | Out-Null } else { Write-Host "Without credentials" - New-PSDrive -Name $smbDrive -PSProvider "FileSystem" -Root $smbPath -Persist -ErrorAction Stop + New-PSDrive -Name $smbDrive -PSProvider "FileSystem" -Root $smbPath -Persist -ErrorAction Stop | Out-Null } $smbConnected = $True @@ -177,7 +177,7 @@ if($errorMessages.Count -eq 0) { Write-Host "Creating directory $backupTargetDiff" try { - New-Item -ItemType directory -Path $backupTargetDiff -ErrorAction Stop + New-Item -ItemType directory -Path $backupTargetDiff -ErrorAction Stop | Out-Null } catch { Write-Host "Could not create directory $backupTargetDiff`: $_.Exception.Message" @@ -215,7 +215,7 @@ if($errorMessages.Count -eq 0) { Write-Host "Creating directory $backupTarget" try { - New-Item -ItemType directory -Path $backupTarget -ErrorAction Stop + New-Item -ItemType directory -Path $backupTarget -ErrorAction Stop | Out-Null } catch { Write-Host "Could not create directory $backupTarget`: $_.Exception.Message" @@ -228,7 +228,7 @@ if($errorMessages.Count -eq 0) { Write-Host "Creating directory $backupTargetFull" try { - New-Item -ItemType directory -Path $backupTargetFull -ErrorAction Stop + New-Item -ItemType directory -Path $backupTargetFull -ErrorAction Stop | Out-Null } catch { Write-Host "Could not create directory $backupTargetFull`: $_.Exception.Message" -- 2.34.1