Powershell Script Probleme
Verfasst: Do Jun 21, 2018 8:02 am
Moin Leute,
ich mal wieder...
Ich habe eine Funktion in ein Powershell-Skript eingebaut (aus dem INet und wegen der ANSI/ASCII Probleme des Editors per Hand in den Editor getippelt). Nach der Handarbeit habe ich das Script in eine Datei kopiert und das Teil in einer PS1 Datei auf dem Zielrechner laufen lassen, wo es ohne Fehler lief. Nur in ACMP gibt es eine Liste von Fehlern, die ein wenig so aussehen, als wenn ACMP Probleme mit der PS-Syntax hätte. Anbei das Log im alf-Format.
Vielleicht habt ihr ja Ideen, wie man das Script dennoch zum Laufen bekommt?
Danke schon mal für alle Tips & Tricks oder gar Lösungen... Sven
Hier das Script:
===================================================================================================================================
function Pin-App{
param(
[parameter(mandatory=$true)][ValidateNotNullOrEmpty()][string[]]$appname,
[switch]$unpin
)
$actionstring = @{$true='Von "Start" lösen|Unpin from Start';$false='An "Start" anheften|Pin to Start'}[$unpin.IsPresent]
$action = @{$true='unpinned from';$false='pinned to'}[$unpin.IsPresent]
$apps = (New-Object -Com Shell.Application).NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}').Items() | ?{$_.Name -in $appname}
if($apps) {
$notfound = compare $appname $apps.Name -PassThru
if ($notfound) {write-error "These App(s) were not found: $($notfound -join ",")"}
foreach ($app in $apps) {
$appaction = $app.Verbs() | ?{$_.Name.replace('&', '') -match $actionstring}
if ($appaction) {
$appaction | %{$_.DoIt(); return "App '$($app.Name)' $action Start"}
} else {
write-error "App '$($app.Name)' is already pinned to start or action not supported."
}
}
} else {
write-error "App(s) not found: $($appname -join ",")"
}
}
Copy-Item -Path "%PROJECTDIR%Geräte und Drucker.lnk" -Destination "$env:userprofile\AppData\Roaming\Microsoft\Windows\Start Menu\Programs"
Copy-Item -Path "%PROJECTDIR%Geräte und Drucker.lnk" -Destination "c:\Users\Default\AppData\Roaming\Microsoft\Windows\Start Menu\Programs"
Import-StartLayout -layoutpath "%PROJECTDIR%DefaultLayouts.xml" -mountpath c:\
Copy-Item -Path "%PROJECTDIR%DefaultLayouts.xml" -Destination "$env:userprofile\AppData\local\Microsoft\Windows\Shell"
Pin-App('Geräte und Drucker')
==============================================================================================================
ich mal wieder...
Ich habe eine Funktion in ein Powershell-Skript eingebaut (aus dem INet und wegen der ANSI/ASCII Probleme des Editors per Hand in den Editor getippelt). Nach der Handarbeit habe ich das Script in eine Datei kopiert und das Teil in einer PS1 Datei auf dem Zielrechner laufen lassen, wo es ohne Fehler lief. Nur in ACMP gibt es eine Liste von Fehlern, die ein wenig so aussehen, als wenn ACMP Probleme mit der PS-Syntax hätte. Anbei das Log im alf-Format.
Vielleicht habt ihr ja Ideen, wie man das Script dennoch zum Laufen bekommt?
Danke schon mal für alle Tips & Tricks oder gar Lösungen... Sven
Hier das Script:
===================================================================================================================================
function Pin-App{
param(
[parameter(mandatory=$true)][ValidateNotNullOrEmpty()][string[]]$appname,
[switch]$unpin
)
$actionstring = @{$true='Von "Start" lösen|Unpin from Start';$false='An "Start" anheften|Pin to Start'}[$unpin.IsPresent]
$action = @{$true='unpinned from';$false='pinned to'}[$unpin.IsPresent]
$apps = (New-Object -Com Shell.Application).NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}').Items() | ?{$_.Name -in $appname}
if($apps) {
$notfound = compare $appname $apps.Name -PassThru
if ($notfound) {write-error "These App(s) were not found: $($notfound -join ",")"}
foreach ($app in $apps) {
$appaction = $app.Verbs() | ?{$_.Name.replace('&', '') -match $actionstring}
if ($appaction) {
$appaction | %{$_.DoIt(); return "App '$($app.Name)' $action Start"}
} else {
write-error "App '$($app.Name)' is already pinned to start or action not supported."
}
}
} else {
write-error "App(s) not found: $($appname -join ",")"
}
}
Copy-Item -Path "%PROJECTDIR%Geräte und Drucker.lnk" -Destination "$env:userprofile\AppData\Roaming\Microsoft\Windows\Start Menu\Programs"
Copy-Item -Path "%PROJECTDIR%Geräte und Drucker.lnk" -Destination "c:\Users\Default\AppData\Roaming\Microsoft\Windows\Start Menu\Programs"
Import-StartLayout -layoutpath "%PROJECTDIR%DefaultLayouts.xml" -mountpath c:\
Copy-Item -Path "%PROJECTDIR%DefaultLayouts.xml" -Destination "$env:userprofile\AppData\local\Microsoft\Windows\Shell"
Pin-App('Geräte und Drucker')
==============================================================================================================