today12
Goto Top

Problem mit UNC-Pfad ? powershell-skript

Hallo liebe Community,

ich hab ein kleines Verständnis Problem mit UNC-Pfade.

ich möchte mein Skript auf ein Netzlaufwerk legen, so dass jeder darauf zugreifen kann.

param (

[string]$hostname

)

function Show-BalloonTip
{
	
	[CmdletBinding(SupportsShouldProcess = $true)]
	param
	(
		[Parameter(Mandatory = $true)]
		$Text,
		[Parameter(Mandatory = $true)]
		$Title,
		[ValidateSet('None', 'Info', 'Warning', 'Error')]  
		$Icon = 'Info',  
		$Timeout = 100000
	)
	
	Add-Type -AssemblyName System.Windows.Forms
	
	if ($script:balloon -eq $null)
	{
		$script:balloon = New-Object System.Windows.Forms.NotifyIcon
	}
	
	$path = Get-Process -id $pid | Select-Object -ExpandProperty Path
	$balloon.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($path)
	$balloon.BalloonTipIcon = $Icon
	$balloon.BalloonTipText = $Text
	$balloon.BalloonTipTitle = $Title
	$balloon.Visible = $true
	
	$balloon.ShowBalloonTip($Timeout)
}




if (! (Test-Connection -ComputerName $hostname -count 1))
{ Show-BalloonTip -Text "nicht erfolgreich...!" -Title "Ping to $hostname" -Icon Error }  

else
{
	Show-BalloonTip -Text "erfolgreich..." -Title "Ping to $hostname" -Timeout 8000  
	
	
	#ermittle aktuell angemeldeter User
	$abf = wmic /node:"$hostname" computersystem get username  
	[string]$abf1 = $abf[2].split("\")[1]  
	
	
	#PW abläufer ...		
	[string]$user = $abf1.TrimEnd(" ")  
	
	$PWexp = Get-ADUser -identity $user -Properties msDS-UserPasswordExpiryTimeComputed |
	select samaccountname, @{ Name = "Expiration Date"; Expression = { [datetime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed") } }  
	$okaus = $PWexp.'Expiration Date'.ToString("dd.MM.yyyy hh:mm")  
	
	
	#Lastreboot
	$wmi = Get-WmiObject -Class Win32_OperatingSystem -Computer $hostname
	$ausgabe = $wmi
	$ausgabeexit = ($wmi.LastBootUpTime)
	$ausgabeexit = [Management.ManagementDateTimeConverter]::ToDateTime($ausgabeexit).ToString("dd.MM.yyyy hh:mm")  
	
	
	#Ausgabe 
	#Show-BalloonTip -Text $ausgabeexit -Title "LastReboot" -Icon Info -Timeout 30000 
	Show-BalloonTip -Text "Lastreboot: $ausgabeexit  ::  PW-Ablaufd.: $okaus" -Title "Info @ $abf1" -Icon Info  
	
		
}


Folgendes Problem tritt auf wenn ich das über CMD starte.

(Das Skript wurde in eine .exe kompiliert)
mspaint_2016-05-11_15-25-12


Wenn ich aber das Programm über ein gemountetes Netzlaufwerk starte, funktioniert das einwandfrei.

Kann mir jemand erklären warum das so ist bzw. was ich an mein Skript ändern soll ?

Danke schon mal im Voraus.

lg

Content-Key: 304219

Url: https://administrator.de/contentid/304219

Printed on: April 19, 2024 at 03:04 o'clock

Mitglied: 129148
129148 May 11, 2016 updated at 14:00:23 (UTC)
Goto Top
Die Funktion ExtractAssociatedIcon unterstützt keine UNC-Pfade, steht doch explizit in der Doku unter Exceptions
https://msdn.microsoft.com/de-de/library/system.drawing.icon.extractasso ...

ArgumentException	

Die filePath ist kein Hinweis auf eine gültige Datei.

- oder -

Die filePath Gibt einen Universal Naming Convention (UNC)-Pfad.
Kopier dir das File in einen lokalen Pfad und von dort extrahierst du das Icon.
Member: colinardo
colinardo May 25, 2016 at 11:04:46 (UTC)
Goto Top
Wenns das dann war, den Beitrag bitte noch auf gelöst setzen. Merci.