From: Patrick Canterino <patrick@patrick-canterino.de>
Date: Tue, 6 Mar 2018 13:35:34 +0000 (+0100)
Subject: Suppress output of New-PSDrive and New-Item
X-Git-Url: https://git.p6c8.net/dsmonrot.git/commitdiff_plain/d76d903b4f6a1963cd7dbdab4bf130d5c03514a9?ds=sidebyside;hp=1393228635062138984a33279aadb8f5e77dbed6

Suppress output of New-PSDrive and New-Item
---

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"