Benutzer-Werkzeuge

Webseiten-Werkzeuge


powershell:sharepruefen

Auf Share prüfen

Script

function check-ifexists-share ([string]$share,[string]$Username,[string]$PW)
{
	$ErrorActionPreference = "Stop"
	$Credential = New-Object System.Management.Automation.PSCredential($Username,(ConvertTo-Securestring $PW -AsPlainText -force))
	$Target = $share.Split("\")
	$TargetServer = $Target[2]
	$TargetShare = $Target[3]
	try 
	{
		$RemoteShares = Get-WMIObject win32_share -ComputerName $TargetServer -Credential $Credential
	} catch [System.Management.Automation.ActionPreferenceStopException] {
		#Write-Host "Server $TargetServer antwortet nicht oder existiert nicht!"
		#write-Host $_.Exception.getType()
		#System.Management.Automation.ActionPreferenceStopException für Commandlets, die non-TErminating Exceptions abwerfen!
		#$ErrorActionPreference muss dafür auf "Stop" gesetzt werden! (Default-Wert "Continue")
		return $FALSE
	}
	$RemoteShare = $RemoteShares | where-object {$_.Name -eq $Targetshare}
	if ($RemoteShare -eq $NULL -or $Remoteshare -eq "")
	{
		#write-host "Share $share existiert nicht!"
		return $FALSE
	} else
	{
		#write-host "Share $share existiert!"
		return $true
	}
}
 
$a = check-ifexists-share "\\viafs2\homes$" "via\serviceumra" "blablubb"
$b = check-ifexists-share "\\viafs2\homes$\blablubb" "via\serviceumra" "blablubb"
$c = check-ifexists-share "\\viafs3\homes$" "via\serviceumra" "blablubb"
$d = check-ifexists-share "\\viafs2\homes$\" "via\serviceumra" "blablubb"

powershell/sharepruefen.txt · Zuletzt geändert: 2016/04/02 00:49 von 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki