Top-Themen

AppleEntwicklungHardwareInternetLinuxMicrosoftMultimediaNetzwerkeOff TopicSicherheitSonstige SystemeVirtualisierungWeiterbildungZusammenarbeit

Aktuelle Themen

Administrator.de FeedbackApache ServerAppleAssemblerAudioAusbildungAuslandBackupBasicBatch & ShellBenchmarksBibliotheken & ToolkitsBlogsCloud-DiensteClusterCMSCPU, RAM, MainboardsCSSC und C++DatenbankenDatenschutzDebianDigitiales FernsehenDNSDrucker und ScannerDSL, VDSLE-BooksE-BusinessE-MailEntwicklungErkennung und -AbwehrExchange ServerFestplatten, SSD, RaidFirewallFlatratesGoogle AndroidGrafikGrafikkarten & MonitoreGroupwareHardwareHosting & HousingHTMLHumor (lol)Hyper-VIconsIDE & EditorenInformationsdiensteInstallationInstant MessagingInternetInternet DomäneniOSISDN & AnaloganschlüsseiTunesJavaJavaScriptKiXtartKVMLAN, WAN, WirelessLinuxLinux DesktopLinux NetzwerkLinux ToolsLinux UserverwaltungLizenzierungMac OS XMicrosoftMicrosoft OfficeMikroTik RouterOSMonitoringMultimediaMultimedia & ZubehörNetzwerkeNetzwerkgrundlagenNetzwerkmanagementNetzwerkprotokolleNotebook & ZubehörNovell NetwareOff TopicOpenOffice, LibreOfficeOutlook & MailPapierkorbPascal und DelphiPeripheriegerätePerlPHPPythonRechtliche FragenRedHat, CentOS, FedoraRouter & RoutingSambaSAN, NAS, DASSchriftartenSchulung & TrainingSEOServerServer-HardwareSicherheitSicherheits-ToolsSicherheitsgrundlagenSolarisSonstige SystemeSoziale NetzwerkeSpeicherkartenStudentenjobs & PraktikumSuche ProjektpartnerSuseSwitche und HubsTipps & TricksTK-Netze & GeräteUbuntuUMTS, EDGE & GPRSUtilitiesVB for ApplicationsVerschlüsselung & ZertifikateVideo & StreamingViren und TrojanerVirtualisierungVisual StudioVmwareVoice over IPWebbrowserWebentwicklungWeiterbildungWindows 7Windows 8Windows 10Windows InstallationWindows MobileWindows NetzwerkWindows ServerWindows SystemdateienWindows ToolsWindows UpdateWindows UserverwaltungWindows VistaWindows XPXenserverXMLZusammenarbeit
GELÖST

Powershell Invoke-Command Problem

Frage Microsoft Windows Tools

Mitglied: skahle85

skahle85 (Level 1) - Jetzt verbinden

09.09.2014, aktualisiert 16:56 Uhr, 1539 Aufrufe, 2 Kommentare, 1 Danke

Hallo liebe Gemeinde,

ich bin gerade dabei mir über Powershell ISE meine Scriptsammlung zusammen zu führen. Im ersten Schritt hatte ich mir eine "kleine" scriptdatei geschrieben in der alle Befehle per Auswahl ausgeführt werden:
01.
 Import-Module ActiveDirectory 
02.
Add-PSSnapin quest.activeroles.admanagement 
03.
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 
04.
do { 
05.
  do { 
06.
    write-host "" 
07.
    write-host "X - Exit" 
08.
    write-host "A - Ausgabe der GPO´s" 
09.
    write-host "B - Export GPO" 
10.
    write-host "C - Import GPO" 
11.
    write-host "D - Server Edition Upgrade" 
12.
    write-host "E - Change Product Key" 
13.
    write-host "F - Set Global User Identity" 
14.
    write-host "G - Change User Password" 
15.
    write-host "H - Redirect an OU" 
16.
    write-host "I - Enable Mailbox for Users in OU" 
17.
    write-host "J - Add Mailbox for User in specified OU" 
18.
    write-host "K - ADD OU" 
19.
    write-host "L - ADD Group" 
20.
    write-host "M - New Email Address Policy" 
21.
    write-host "N - Forward Mails to SMTP Address" 
22.
    write-host "O - Disable Forwarding to SMTP Address" 
23.
    write-host "P - View Forwarding Status for User" 
24.
    write-host "Q - New Distribution list" 
25.
    write-host "R - Add Users to Distribution list from a csv file" 
26.
    write-host "S - Command 4" 
27.
    write-host "T - Command 4" 
28.
    write-host "U - Command 4" 
29.
    write-host "V - Command 4" 
30.
    write-host "W - Command 4" 
31.
    write-host "Y - Command 4" 
32.
    write-host "Z - Command 4" 
33.
    write-host "" 
34.
    write-host -nonewline "Select command and press Enter: " 
35.
    $choice = read-host 
36.
    write-host "" 
37.
    $ok = @("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","Y","Z","X") -contains $choice 
38.
    if ( -not $ok) { write-host "Invalid selection" } 
39.
40.
  until ( $ok ) 
41.
  switch ( $choice ) { 
42.
     "A" { 
43.
     Get-GPO -all 
44.
     break 
45.
46.
     "B" { 
47.
     write-host -nonewline "GPO NAME and press Enter: " 
48.
     $Name = read-host 
49.
     write-host -nonewline "Export Path and press Enter: " 
50.
     $PATH = read-host 
51.
     Backup-GPO -Name $NAME -Path $PATH 
52.
     break 
53.
54.
     "C" { 
55.
     write-host -nonewline "GPO NAME and press Enter: "     
56.
     $Name = read-host 
57.
     write-host -nonewline "NEW GPO NAME and press Enter: "     
58.
     $NAME1 = read-host 
59.
     write-host -nonewline "Import Path and press Enter: " 
60.
     $PATH = read-host  
61.
     Import-GPO -BackupGPOName $NAME -TargetName $NAME1 -CreateIfNeeded -Path $PATH 
62.
     break 
63.
64.
     "D" { 
65.
     write-host -nonewline "Doesnt work with Domain Controllern" 
66.
     write-host -nonewline "Edition Name: " 
67.
     $Product = read-host 
68.
     write-host -nonewline "Product Key: " 
69.
     $ProductKey = read-host     
70.
     DISM /online /Set-Edition: $Product /ProductKey: $ProductKey /AcceptEula 
71.
     break 
72.
73.
     "E" { 
74.
     write-host -nonewline "Product Key: " 
75.
     $ProductKey = read-host     
76.
     slmgr -ipk $ProductKey 
77.
     break 
78.
79.
     "F" { 
80.
     write-host -nonewline "OU with Employees: " 
81.
     $OU = read-host 
82.
     write-host -nonewline "Hosted OU of OU Employees: " 
83.
     $OU1 = read-host 
84.
     write-host -nonewline "Next Hosted OU (leave blank if no more OU is present: " 
85.
     $OU2 = read-host 
86.
     write-host -nonewline "Next Hosted OU (leave blank if no more OU is present: " 
87.
     $OU3 = read-host 
88.
     write-host -nonewline "Domain Name without .local: " 
89.
     $DOMAIN = read-host 
90.
     write-host -nonewline "Enter City: " 
91.
     $city = read-host 
92.
     write-host -nonewline "Enter Street: " 
93.
     $street = read-host 
94.
     write-host -nonewline "Enter Postal Code: " 
95.
     $PostalCode = read-host 
96.
     write-host -nonewline "Enter State: " 
97.
     $State = read-host 
98.
     write-host -nonewline "Enter Organization: " 
99.
     $Organization = read-host 
100.
     Get-ADUser -SearchBase ou= $OU,ou= $OU1,ou= $OU2,ou= $OU3,dc= $DOMAIN,dc=local -Filter * | Set-ADUser -Identity $_ -City $city -StreetAddress $street -PostalCode $PostalCode -State $State -Company $Organization 
101.
     break 
102.
103.
     "G" { 
104.
     write-host -nonewline "Username: " 
105.
     $USER = read-host 
106.
     write-host -nonewline "New Password: " 
107.
     Set-ADAccountPassword $USER -NewPassword $newpwd -Reset -PassThru | Set-ADuser -ChangePasswordAtLogon $True 
108.
     break 
109.
110.
     "H" { 
111.
     write-host -nonewline "OU Destination: " 
112.
     $OU = read-host 
113.
     write-host -nonewline "overall OU: " 
114.
     $OU1 = read-host 
115.
     write-host -nonewline "Domain without .local: " 
116.
     $DOMAIN = read-host             
117.
     redircmp OU= $OU,OU= $OU1,DC= $DOMAIN,DC=local 
118.
     break 
119.
120.
     "I" { 
121.
     write-host -nonewline "Enter OU like domain.local/OU/OU1/OU with Employees: " 
122.
     $OU = read-host 
123.
     write-host -nonewline "which Database: " 
124.
     $DATABASE = read-host             
125.
     Get-User –OrganizationalUnit $OU | Enable-Mailbox -Database $DATABASE 
126.
     break         
127.
128.
 
129.
     "J" { 
130.
     write-host -nonewline "Enter OU like domain.local/OU/OU1/OU with Employees: " 
131.
     $OU = read-host 
132.
     write-host -nonewline "which Database: " 
133.
     $DATABASE = read-host             
134.
     Get-User –OrganizationalUnit $OU | Enable-Mailbox -Database $DATABASE 
135.
     break         
136.
137.
     "K" { 
138.
     write-host -nonewline "Enter OU like OU=NAME,OU=NAME,DC=DOMAIN,DC=local: " 
139.
     $OU = read-host 
140.
     dsadd ou $OU 
141.
     break         
142.
143.
     "L" { 
144.
     write-host -nonewline "Enter Group like CN=NAME,OU=NAME,DC=DOMAIN,DC=local: " 
145.
     $OU = read-host 
146.
     dsadd group $OU 
147.
     break         
148.
149.
     "M" { 
150.
     write-host -nonewline "New Name for Address Policy: " 
151.
     $NAME = read-host 
152.
     write-host -nonewline "Conditional State or Province: " 
153.
     $STATE = read-host 
154.
     write-host -nonewline "Address Policy @Domainname: " 
155.
     $SMTP = read-host 
156.
     New-EmailAddressPolicy -Name $NAME -IncludedRecipients MailboxUsers -ConditionalStateorProvince $STATE -EnabledEmailAddressTemplates $SMTP 
157.
     break         
158.
159.
     "N" { 
160.
     write-host -nonewline "Username: " 
161.
     $NAME = read-host 
162.
     write-host -nonewline "Forwarding SMTP Address: " 
163.
     $SMTP = read-host 
164.
     set-mailbox -Identity $NAME -DeliverToMailboxAndForward $true -ForwardingSmtpAddress $SMTP 
165.
     break         
166.
167.
     "O" { 
168.
     write-host -nonewline "Username: " 
169.
     $NAME = read-host 
170.
     set-mailbox -Identity $NAME -DeliverToMailboxAndForward $false -ForwardingSmtpAddress $null 
171.
     break         
172.
173.
     "P" { 
174.
     write-host -nonewline "Username: " 
175.
     $NAME = read-host 
176.
     Get-Mailbox -Identity $NAME | fl *Forwarding* 
177.
     break         
178.
179.
     "Q" { 
180.
     write-host -nonewline "Distribution Name: " 
181.
     $NAME = read-host 
182.
     write-host -nonewline "Sam Account Name: " 
183.
     $SAM = read-host 
184.
     write-host -nonewline "Alias Name: " 
185.
     $ALIAS = read-host 
186.
     new-DistributionGroup -Name $NAME -SamAccountName $SAM -Alias $ALIAS 
187.
     break         
188.
189.
     "R" {     
190.
     write-host -nonewline "CSV file location: " 
191.
     $CSV = read-host 
192.
     write-host -nonewline "Distribution list: " 
193.
     $DISTR = read-host     
194.
     import-csv $CSV | foreach {add-distributiongroupmember -id $DISTR $_.PrimarySmtpAddress }         
195.
     break         
196.
197.
198.
199.
until ( $choice -eq "X" )


Im 2. Schritt bin ich gerade dabei mir eine GUI drüber zu basteln damit ich (wenn fertig) mit wenigen Klicks meine Aufgaben erledigen kann.
Hier hänge ich gerade bei einem eigentlich kleinen Problem welches ich aber nun endlich mal gelöst haben will und einfach keine Ideen mehr habe.
Folgendes:
per
01.
function resetPW { 
02.
$wks=$InputBox.text; 
03.
$User=$InputBoxUser.text; 
04.
#$pwd=$InputBoxPW.text; 
05.
$UserResult=Invoke-Command -ComputerName $wks -ScriptBlock{Set-ADAccountPassword $User -NewPassword $newpwd -Reset -PassThru | Set-ADuser -ChangePasswordAtLogon $True} 
06.
                 } #end
versuche ich das Passwort eines Users zurückzusetzen und bekomme aber den Fehler:
Das Argument für den Parameter "Identity" kann nicht überprüft werden. Das Argument ist NULL. Geben Sie ein Argument an, das nicht NULL ist, und führen Sie dann
den Befehl erneut aus.
+ CategoryInfo : InvalidData: ( [Set-ADAccountPassword], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.SetADAccountPassword
+ PSComputerName : DC

Wenn ich aber den Befehl per Powershell direkt ausführe mit ausgefüllten Credentials funktioniert es.
01.
Set-ADAccountPassword user1 -NewPassword $newpwd -Reset -PassThru | Set-ADuser -ChangePasswordAtLogon $True
Es scheint, das die Text Box die ich zur user eingabe nutzen möchte NICHT abgefragt wird.
Hier mal das komplette Script in der Hoffnung das mir jemand helfen kann.
01.
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")  
02.
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")  #loading the necessary .net libraries (using void to suppress output) 
03.
 
04.
#Window Options 
05.
$Form = New-Object System.Windows.Forms.Form    #creating the form (this will be the "primary" window) 
06.
$Form.Size = New-Object System.Drawing.Size(1024,768)  #the size in px of the window length, height 
07.
Add-Type -AssemblyName System.Windows.Forms 
08.
$Image = [system.drawing.image]::FromFile("$($Env:Public)\water.jpg") 
09.
$Form.BackgroundImage = $Image 
10.
$Form.BackgroundImageLayout = "Stretch" # None, Tile, Center, Stretch, Zoom 
11.
$Form.StartPosition = "CenterScreen" #loads the window in the center of the screen 
12.
$Form.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedToolWindow #modifies the window border 
13.
$Form.Text = "Powershell GUI Utility" #window description 
14.
 
15.
 
16.
#Funktion PING 
17.
function pingInfo { 
18.
$wks=$InputBox.text; #takes the text from the input box into the variable $wks 
19.
$pingResult=ping $wks | fl | out-string; 
20.
$outputBox.text=$pingResult #send the ping results to the output box 
21.
                     } #end 
22.
 
23.
#Funktion NSlookup 
24.
function nsLookup { 
25.
$wks=$InputBox.text; #takes the text from the input box into the variable $wks 
26.
$lookupResult=[System.Net.Dns]::GetHostAddresses($wks) | fl | out-string; 
27.
$outputBox.text=$lookupResult #send the nslookup results to the output box 
28.
                     } #end  
29.
 
30.
#Funktion GPO 
31.
function GPO { 
32.
$wks=$InputBox.text; #takes the text from the input box into the variable $wks 
33.
$GPOResult=Invoke-Command -ComputerName $wks -ScriptBlock { Get-GPO -all } | fl | out-string;  
34.
$outputBox.text=$GPOResult #send the results to the output box 
35.
              } #end 
36.
 
37.
#Funktion Reset Password 
38.
function resetPW { 
39.
$wks=$InputBox.text; 
40.
$User=$InputBoxUser.text; 
41.
#$pwd=$InputBoxPW.text; 
42.
$UserResult=Invoke-Command -ComputerName $wks -ScriptBlock{Set-ADAccountPassword $User -NewPassword $newpwd -Reset -PassThru | Set-ADuser -ChangePasswordAtLogon $True} 
43.
                 } #end 
44.
 
45.
#Funktion Ad User 
46.
function adUser { 
47.
$wks=$InputBox.text; #takes the text from the input box into the variable $wks 
48.
$UserResult=Invoke-Command -ComputerName $wks -ScriptBlock { Get-ADUser -Filter *} | fl | out-string; #populate the var with the value you selected 
49.
$outputBox.text=$UserResult #send the results to the output box 
50.
                } #end procInfo  
51.
 
52.
#Funktion SMTP Forwarding Status 
53.
function smtpFWstats { 
54.
$Name=$InputboxUser.text; 
55.
$wks=$InputBox.text; #takes the text from the input box into the variable $wks 
56.
$smtpFWstatus=Get-Mailbox -Resultsize Unlimited | Where {$_.ForwardingAddress -ne $null} | Select Name, @{Expression={$_.ForwardingAddress};Label="Forwarded to"}, @{Expression={$_.DeliverToMailboxAndForward};Label="Mailbox & Forward"} | fl | out-string; #populate the var with the value you selected 
57.
$outputBox.text=$smtpFWstatus #send the results to the output box 
58.
                } #end procInfo     
59.
            
60.
 
61.
#Start Textfields 
62.
#Input 
63.
$InputBox = New-Object System.Windows.Forms.TextBox #creating the text box 
64.
$InputBox.Location = New-Object System.Drawing.Size(10,120) #location of the text box (px) in relation to the primary window's edges (length, height) 
65.
$InputBox.Size = New-Object System.Drawing.Size(150,20) #the size in px of the text box (length, height) 
66.
$InputBox.Text = "Computername" 
67.
$Form.Controls.Add($InputBox) #activating the text box inside the primary window 
68.
 
69.
#Input Username 
70.
$InputBoxUser = New-Object System.Windows.Forms.TextBox #creating the text box 
71.
$InputBoxUser.Location = New-Object System.Drawing.Size(165,120) #location of the text box (px) in relation to the primary window's edges (length, height) 
72.
$InputBoxUser.Size = New-Object System.Drawing.Size(150,20) #the size in px of the text box (length, height) 
73.
$InputBoxUser.Text = "User Logon Name" 
74.
$Form.Controls.Add($InputBoxUser) #activating the text box inside the primary window 
75.
 
76.
#Input Password 
77.
#$InputBoxPW = New-Object System.Windows.Forms.TextBox #creating the text box 
78.
#$InputBoxPW.Location = New-Object System.Drawing.Size(320,120) #location of the text box (px) in relation to the primary window's edges (length, height) 
79.
#$InputBoxPW.Size = New-Object System.Drawing.Size(150,20) #the size in px of the text box (length, height) 
80.
#$InputBoxPW.UseSystemPasswordChar = $True 
81.
#$InputBoxPW.Text = "Password" 
82.
#$Form.Controls.Add($InputBoxPW) #activating the text box inside the primary window 
83.
 
84.
#Output 
85.
$outputBox = New-Object System.Windows.Forms.TextBox #creating the text box 
86.
$outputBox.Location = New-Object System.Drawing.Size(10,150) #location of the text box (px) in relation to the primary window's edges (length, height) 
87.
$outputBox.Size = New-Object System.Drawing.Size(1000,500) #the size in px of the text box (length, height) 
88.
$outputBox.MultiLine = $True #declaring the text box as multi-line 
89.
$outputBox.ScrollBars = "Vertical" #adding scroll bars if required 
90.
$outputBox.Font = New-Object System.Drawing.Font("Verdana",8,[System.Drawing.FontStyle]::Italic) #Textbox Font 
91.
$Form.Controls.Add($outputBox) #activating the text box inside the primary window 
92.
#End Textfields 
93.
 
94.
#Ping Buttons 
95.
$Button = New-Object System.Windows.Forms.Button #create the button 
96.
$Button.Location = New-Object System.Drawing.Size(20,35) #location of the button (px) in relation to the primary window's edges (length, height) 
97.
$Button.Size = New-Object System.Drawing.Size(100,23) #the size in px of the button (length, height) 
98.
$Button.Text = "Ping" #labeling the button 
99.
$Button.Cursor = [System.Windows.Forms.Cursors]::Hand 
100.
$Button.BackColor = [System.Drawing.Color]::LightGreen 
101.
$Button.Font = New-Object System.Drawing.Font ("Verdana",10, [System.Drawing.FontStyle]::Regular) 
102.
$Button.Add_Click({}) #the action triggered by the button 
103.
$Form.Controls.Add($Button) #activating the button inside the primary window 
104.
$Button.Add_Click({pingInfo}) 
105.
 
106.
#NSlookup Buttons 
107.
$Button = New-Object System.Windows.Forms.Button #create the button 
108.
$Button.Location = New-Object System.Drawing.Size(20,60) #location of the button (px) in relation to the primary window's edges (length, height) 
109.
$Button.Size = New-Object System.Drawing.Size(100,23) #the size in px of the button (length, height) 
110.
$Button.Text = "NS Lookup" #labeling the button 
111.
$Button.Cursor = [System.Windows.Forms.Cursors]::Hand 
112.
$Button.BackColor = [System.Drawing.Color]::LightGreen 
113.
$Button.Font = New-Object System.Drawing.Font ("Verdana",10, [System.Drawing.FontStyle]::Regular) 
114.
$Button.Add_Click({}) #the action triggered by the button 
115.
$Form.Controls.Add($Button) #activating the button inside the primary window 
116.
$Button.Add_Click({nsLookup}) 
117.
 
118.
#Get GPO Button 
119.
$Button = New-Object System.Windows.Forms.Button #create the button 
120.
$Button.Location = New-Object System.Drawing.Size(20,10) #location of the button (px) in relation to the primary window's edges (length, height) 
121.
$Button.Size = New-Object System.Drawing.Size(100,23) #the size in px of the button (length, height) 
122.
$Button.Text = "Get GPO´s" #labeling the button 
123.
$Button.Cursor = [System.Windows.Forms.Cursors]::Hand 
124.
$Button.BackColor = [System.Drawing.Color]::LightGreen 
125.
$Button.Font = New-Object System.Drawing.Font("Verdana",10,[System.Drawing.FontStyle]::Regular) 
126.
$Button.Add_Click({}) #the action triggered by the button 
127.
$Form.Controls.Add($Button) #activating the button inside the primary window 
128.
$Button.Add_Click({GPO}) 
129.
 
130.
#Set New User Password 
131.
$Button = New-Object System.Windows.Forms.Button #create the button 
132.
$Button.Location = New-Object System.Drawing.Size(120,10) #location of the button (px) in relation to the primary window's edges (length, height) 
133.
$Button.Size = New-Object System.Drawing.Size(130,23) #the size in px of the button (length, height) 
134.
$Button.Text = "Reset Password" #labeling the button 
135.
$Button.Cursor = [System.Windows.Forms.Cursors]::Hand 
136.
$Button.BackColor = [System.Drawing.Color]::LightGreen 
137.
$Button.Font = New-Object System.Drawing.Font("Verdana",10,[System.Drawing.FontStyle]::Regular) 
138.
$Button.Add_Click({}) #the action triggered by the button 
139.
$Form.Controls.Add($Button) #activating the button inside the primary window 
140.
$Button.Add_Click({resetPW}) 
141.
 
142.
#Get AD User Button 
143.
$Button = New-Object System.Windows.Forms.Button #create the button 
144.
$Button.Location = New-Object System.Drawing.Size(120,35) #location of the button (px) in relation to the primary window's edges (length, height) 
145.
$Button.Size = New-Object System.Drawing.Size(130,23) #the size in px of the button (length, height) 
146.
$Button.Text = "Get All AD User" #labeling the button 
147.
$Button.Cursor = [System.Windows.Forms.Cursors]::Hand 
148.
$Button.BackColor = [System.Drawing.Color]::LightGreen 
149.
$Button.Font = New-Object System.Drawing.Font("Verdana",10,[System.Drawing.FontStyle]::Regular) 
150.
$Button.Add_Click({}) #the action triggered by the button 
151.
$Form.Controls.Add($Button) #activating the button inside the primary window 
152.
$Button.Add_Click({adUser}) 
153.
 
154.
#SMTP Forward Status 
155.
$Button = New-Object System.Windows.Forms.Button #create the button 
156.
$Button.Location = New-Object System.Drawing.Size(400,10) #location of the button (px) in relation to the primary window's edges (length, height) 
157.
$Button.Size = New-Object System.Drawing.Size(130,23) #the size in px of the button (length, height) 
158.
$Button.Text = "SMTP FW Status" #labeling the button 
159.
$Button.Cursor = [System.Windows.Forms.Cursors]::Hand 
160.
$Button.BackColor = [System.Drawing.Color]::LightBlue 
161.
$Button.Font = New-Object System.Drawing.Font("Verdana",10,[System.Drawing.FontStyle]::Regular) 
162.
$Button.Add_Click({}) #the action triggered by the button 
163.
$Form.Controls.Add($Button) #activating the button inside the primary window 
164.
$Button.Add_Click({smtpFWstats}) 
165.
 
166.
#Cancel Buttons 
167.
$ExitButton = New-Object System.Windows.Forms.Button #create the button 
168.
$ExitButton.Location = New-Object System.Drawing.Size(900,710) #location of the button (px) in relation to the primary window's edges (length, height) 
169.
$ExitButton.Size = New-Object System.Drawing.Size(100,23) #the size in px of the button (length, height) 
170.
$ExitButton.Text = "Exit" #labeling the button 
171.
$ExitButton.Add_Click({}) #the action triggered by the button 
172.
$Form.Controls.Add($ExitButton) #activating the button inside the primary window 
173.
$ExitButton.Add_Click({$Form.Close()}) 
174.
 
175.
 
176.
 
177.
#activate 
178.
[void] $Form.ShowDialog() 
179.
[void] $Form.Add_Shown({$Form.Activate()})
Vielen Dank schon mal
Grüße
Merlin
Mitglied: colinardo
LÖSUNG 09.09.2014, aktualisiert um 16:56 Uhr
Hallo Merlin,
dein Problem ist, dass dein Befehl bzw. der Scriptblock auf dem Remotecomputer ausgeführt wird und somit dort deine Variablen nicht vorhanden sind ! Um das zu umgehen kannst du im Befehl invoke-command mit dem Parameter -argumentlist ein Array an Variablen als Argumente an den Scriptblock übergeben die dann im Scriptblock mit $args[0] , $args[1], usw abgerufen werden können:
01.
$UserResult=Invoke-Command -ComputerName $wks -argumentlist $User,$newpwd  -ScriptBlock{Set-ADAccountPassword $args[0] -NewPassword $args[1] -Reset -PassThru | Set-ADuser -ChangePasswordAtLogon $True} }
Grüße Uwe
Bitte warten ..
Mitglied: skahle85
09.09.2014 um 16:59 Uhr
:D HA

Perfekt!!!

ein Riesen Danke für diesen, ich werde ihn definitv öfter nutzen, Hinweis ein Array an Argumenten zu übergeben.

<close>Schwuppsdiwupps</close>
Bitte warten ..
Neuester Wissensbeitrag
Ähnliche Inhalte
Batch & Shell
Powershell Workflow, CSV Stapelverarbeitung Problem (6)

Frage von Rippchen zum Thema Batch & Shell ...

Batch & Shell
Problem mit UNC-Pfad ? powershell-skript (2)

Frage von today12 zum Thema Batch & Shell ...

Windows Netzwerk
Problem mit PSexec64 von Sysinternals (2)

Frage von MaxMoritz6 zum Thema Windows Netzwerk ...

Heiß diskutierte Inhalte
Windows Userverwaltung
Ausgeschiedene Mitarbeiter im Unternehmen - was tun mit den AD Konten? (33)

Frage von patz223 zum Thema Windows Userverwaltung ...

LAN, WAN, Wireless
FritzBox, zwei Server, verschiedene Netze (21)

Frage von DavidGl zum Thema LAN, WAN, Wireless ...

Viren und Trojaner
Aufgepasst: Neue Ransomware Goldeneye verbreitet sich rasant (20)

Link von Penny.Cilin zum Thema Viren und Trojaner ...