Hey there
I got another problem:
I created a Script:
# Active Directory Modul laden
Import-Module ActiveDirectory
# Gruppe abfragen
param([Parameter(Mandatory=$true)]
[String]$Group)
# Active Directory Modul laden
Import-Module ActiveDirectory
echo $Group
$title = "Welche Vorlage möchten Sie verwenden?"
$message = "1.Neue_Störung 2.Update_Störung 3.Störungsabschluss 4.Hinweismeldung"
$eins = New-Object System.Management.Automation.Host.ChoiceDescription "&1", "1"
$zwei = New-Object System.Management.Automation.Host.ChoiceDescription "&2", "2"
$drei = New-Object System.Management.Automation.Host.ChoiceDescription "&3", "3"
$vier = New-Object System.Management.Automation.Host.ChoiceDescription "&4", "4"
$options = [System.Management.Automation.Host.ChoiceDescription[]]($eins, $zwei,$drei,$vier)
$choice_groups=$host.ui.PromptForChoice($title, $message, $options, 1)
If ($choice_groups -eq 0){
$path = "H:\edv\IT_Operations\IT- Service Koordination\02_Eskalationsmanagement\00_Vorlagen zu Eskalationen\000_Muster und Vorlagen\01_Neue Störung.oft"
}
If ($choice_groups -eq 1){
$path = "H:\edv\IT_Operations\IT- Service Koordination\02_Eskalationsmanagement\00_Vorlagen zu Eskalationen\000_Muster und Vorlagen\02_Update Störung.oft"
}
If ($choice_groups -eq 2){
$path = "H:\edv\IT_Operations\IT- Service Koordination\02_Eskalationsmanagement\00_Vorlagen zu Eskalationen\000_Muster und Vorlagen\03_Störungabschluss.oft"
}
If ($choice_groups -eq 3){
$path = "H:\edv\IT_Operations\IT- Service Koordination\02_Eskalationsmanagement\00_Vorlagen zu Eskalationen\000_Muster und Vorlagen\00_[Hinweismeldung].oft"
}
# Email-Adressen ermitteln
$EmailAddresses = Get-ADGroupMember $Group -Recursive | Get-ADUser -Properties mail | Select mail
echo $EmailAddresses
ForEach ($EmailAddress In $EmailAddresses){
$OLAddresses = $EmailAddress.mail + ";" + $OLAddresses
}
# Outlookmail erstellen
$OL = New-Object -comObject Outlook.Application
$Mail = $OL.CreateItemFromTemplate($path)
$Mail.TO = $OLAddresses
#$Mail.BCC = $OLAddresses
$Mail.Display()
Everything is fine when I start it on my device. But when I start it on another device it returns an error that “param” is not a name of a cmdlet , function or a scriptfile.
Now my question. Why does it work on my device but nowhere else. Is there something I have to activate?
Well the first two lines are on the wrong place. When I start the Script in the ISE it works on every device. But when I rightclick it and say “open with PowerShell” it now works nowhere. The PowerShell-Window popsup and disappear.
# Gruppe abfragen
param(
[Parameter(Mandatory=$true)]
[String]$Group)
# Active Directory Modul laden
Import-Module ActiveDirectory
echo $Group
$title = "Welche Vorlage möchten Sie verwenden?"
$message = "1.Neue_Störung 2.Update_Störung 3.Störungsabschluss 4.Hinweismeldung"
$eins = New-Object System.Management.Automation.Host.ChoiceDescription "&1", "1"
$zwei = New-Object System.Management.Automation.Host.ChoiceDescription "&2", "2"
$drei = New-Object System.Management.Automation.Host.ChoiceDescription "&3", "3"
$vier = New-Object System.Management.Automation.Host.ChoiceDescription "&4", "4"
$options = [System.Management.Automation.Host.ChoiceDescription[]]($eins, $zwei,$drei,$vier)
$choice_groups=$host.ui.PromptForChoice($title, $message, $options, 1)
If ($choice_groups -eq 0){
$path = "H:\edv\IT_Operations\IT- Service Koordination\02_Eskalationsmanagement\00_Vorlagen zu Eskalationen\000_Muster und Vorlagen\01_Neue Störung.oft"
}
If ($choice_groups -eq 1){
$path = "H:\edv\IT_Operations\IT- Service Koordination\02_Eskalationsmanagement\00_Vorlagen zu Eskalationen\000_Muster und Vorlagen\02_Update Störung.oft"
}
If ($choice_groups -eq 2){
$path = "H:\edv\IT_Operations\IT- Service Koordination\02_Eskalationsmanagement\00_Vorlagen zu Eskalationen\000_Muster und Vorlagen\03_Störungabschluss.oft"
}
If ($choice_groups -eq 3){
$path = "H:\edv\IT_Operations\IT- Service Koordination\02_Eskalationsmanagement\00_Vorlagen zu Eskalationen\000_Muster und Vorlagen\00_[Hinweismeldung].oft"
}
# Email-Adressen ermitteln
$EmailAddresses = Get-ADGroupMember $Group -Recursive | Get-ADUser -Properties mail | Select mail
echo $EmailAddresses
ForEach ($EmailAddress In $EmailAddresses){
$OLAddresses = $EmailAddress.mail + ";" + $OLAddresses
}
# Outlookmail erstellen
$OL = New-Object -comObject Outlook.Application
$Mail = $OL.CreateItemFromTemplate($path)
$Mail.TO = $OLAddresses
#$Mail.BCC = $OLAddresses
$Mail.Display()
I’m on the PowerShell journey myself but I did notice something at the beginning of your code.
You are specifying a parameter (Group) that is mandatory which is fine but how are you populating a value into that parameter?
If you want to use your script as a cmdlet (advanced function), it would be much easier to make it a module, then you can easily specify the parameter name. Otherwise you have to dot-source the script file each time you want to run it then call the function with the parameter and its value.
I can’t be more specific and I’m guessing, I cheat and use a GUI tool, but most likely the problem is that some Forms assemblies need to be loaded when running from the console. ISE loads them automatically.
Well now I just opened the PowerShel Console and drag and drop my “.ps1” into it. That works But when I rightclick it and say “open with PowerShell” it doesn’t work. Where is the difference between these two procedures?
I found the problem. When i use rightclick and say “open with PowerShell” it uses another console then I open for the drag and drop thing. I changed it and it works. Thanks to everyone