ich weiß das es zu diesem Thema schon einige Posts gibt, die mir auch schon weitergeholfen haben. Trotzdem muss ich das Thema Powershell hier noch mal aufgreifen.
Was soll gemacht werden? Ziel ist es ein Produktpaket zu erstellen, mit dem ich an nicht AD PCs gewisse Einstellungen vornehmen kann. Das Powershell Script selbst funktioniert, wenn ich es als Nutzer aufrufe.
Meine erste Herangehensweise war es das Script als Cmd Aufruf zu starten.
Code: Alles auswählen
[DosBatch_start]
[DosBatch_start]
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "Start-Process PowerShell -ArgumentList '-ExecutionPolicy Unrestricted','-File %~dp0\PreparePC.ps1' -Verb RunAs"
Dann bin ich im Forum auf die Möglichkeit von ExecWith gestoßen und habe meinen Aufruf entsprechend umgebaut.
Code: Alles auswählen
Message "Fuehre Powershell Script aus"
;starte Powershell script 1 aus
if not ($RebootFlag$ = "1")
Set $RebootFlag$ = "1"
;DosBatch_start
DosBatch_PSPolicy
ExecWith_powershell1 "%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe"
Registry_SaveRebootFlag
ExitWindows /ImmediateReboot
else
;starte Powershell script 2 Aktivierung von Bitlocker
Set $RebootFlag$ = "0"
;DosBatch_start2
DosBatch_PSPolicy
ExecWith_powershell2 "%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe"
Registry_SaveRebootFlag
endif
[Registry_SaveRebootFlag]
openKey [$WinstRegKey$]
set "RebootFlag" = "$RebootFlag$"
[Files_Kopieren]
[DosBatch_PSPolicy]
powershell.exe Set-ExecutionPolicy Unrestricted
[ExecWith_powershell1]
######################
#Desktop Links anlegen#
#####################
$target = "C:\Users\Public\Desktop\"
$URL1 = "https://www.google.de"
$URL2 = "https://www.maps.google.de"
$URL3 = "https://bla.bla.de"
$Shell = New-Object -ComObject ("WScript.Shell")
$Link = $Shell.CreateShortcut( $target + "URL1.url")
$Link.TargetPath = $URL1;
$Link.Save()
$Link = $Shell.CreateShortcut($target + "URL2.url")
$Link.TargetPath = $URL";
$Link.Save()
$Link = $Shell.CreateShortcut($target + "URL3.url")
$Link.TargetPath = $URL3;
$Link.Save()
##################
#Installiere Root CA#
##################
$null = Import-Certificate -FilePath ("%ScriptPath%\CA\CA-2017.cer") -CertStoreLocation "Cert:\LocalMachine\ca" -Verbose
$null = Import-Certificate -FilePath ("%ScriptPath%\CA\CA.cer") -CertStoreLocation "Cert:\LocalMachine\ca" -Verbose
#############
#WLAN Profil #
#############
$cmd = "netsh wlan add profile filename="%ScriptPath%\Files\wlan1.xml"
invoke-expression $cmd
#######################
# Bitlocker Vorbereitung #
#######################
$cmd = "bdehdcfg -target default -quiet"
invoke-expression $cmd
Code: Alles auswählen
[5] [Apr 24 12:23:00:131] message Fuehre Powershell Script aus
(124) [6] [Apr 24 12:23:00:134] If
(125) [6] [Apr 24 12:23:00:134] not ($RebootFlag$ = "1") <<< result true
(126) [6] [Apr 24 12:23:00:134] Then
(127) [6] [Apr 24 12:23:00:134] Set $RebootFlag$ = "1"
(128) [6] [Apr 24 12:23:00:134] The value of the variable "$RebootFlag$" is now: "1"
(129) [5] [Apr 24 12:23:00:134] Execution of: DosBatch_PSPolicy
(130) [6] [Apr 24 12:23:01:762] ExitCode 0
(131) [6] [Apr 24 12:23:01:766] Search "c:\opsi.org\tmp\"
(132) [6] [Apr 24 12:23:01:766] Search "c:\opsi.org\tmp\_opsiscript_*"
(133) [6] [Apr 24 12:23:01:766] File "c:\opsi.org\tmp\_opsiscript_Dy75Tc21.cmd"
(134) [6] [Apr 24 12:23:01:766] The file is 0 day(s) old, no deletion
(135) [5] [Apr 24 12:23:01:770] Execution of: ExecWith_powershell1 "C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe"
(136) [5] [Apr 24 12:23:01:770]
(137) [5] [Apr 24 12:23:01:770] Execution of ExecWith_powershell1 "C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe"
(138) [6] [Apr 24 12:23:03:449] ExitCode 1
(139) [6] [Apr 24 12:23:03:455] Search "c:\opsi.org\tmp\"
(140) [6] [Apr 24 12:23:03:455] Search "c:\opsi.org\tmp\_opsiscript_*"
(141) [6] [Apr 24 12:23:03:455] File "c:\opsi.org\tmp\_opsiscript_Dy75Tc21.cmd"
(142) [6] [Apr 24 12:23:03:455] The file is 0 day(s) old, no deletion
(143) [5] [Apr 24 12:23:03:456] Execution of: Registry_SaveRebootFlag
(144) [5] [Apr 24 12:23:03:457]
(145) [6] [Apr 24 12:23:03:457] Registry key [HKLM\SOFTWARE\WOW6432Node\opsi.org\winst] opened
(146) [6] [Apr 24 12:23:03:458] Variable "RebootFlag" had value "0"
(147) [6] [Apr 24 12:23:03:458] Info: "RebootFlag" changed to "1"
(148) [6] [Apr 24 12:23:03:458] Key closed
(149) [6] [Apr 24 12:23:03:458] ExitWindows set to Immediate Reboot
(150) [6] [Apr 24 12:23:03:458] Process stopped
(151) [1] [Apr 24 12:23:03:458] ] ___________________
(152) [1] [Apr 24 12:23:03:458] script finished: success
Schon mal Danke für die Hilfe!
Gruß
aus Potsdam