Quantcast
Channel: SCSM PowerShell Cmdlets
Viewing all 306 articles
Browse latest View live

Commented Unassigned: All Unassigned Service Requests script needed [11252]

$
0
0
Hello, I would like to write a script to pull all the unassigned service requests that were created 12hrs prior to current date. I need to be able to filter on specific support groups. It appears easier to do this for incidents but because there is no get-scsmservicerequest cmdlet, I am at a loss. Thanks
Comments: ** Comment from web user: bobske **

Hi Pat,

You can use the get-scsmobject -Class <someclass> instead to retrieve any object based on a specific class.

So in your case this could be a solution (if I undestood your request correct):

```
Import-Module smlets

#Get Date 12 hours ago
$Date12HoursAgo = (Get-Date).AddHours(-400)

#Get Assigned To relationship class
$RelAssignedTo = Get-SCSMRelationshipClass -Name system.workitemAssignedTo

#Get Service Request Class
$srClass = Get-SCSMClass -Name system.workitem.servicerequest$

#Get all SRs made from 12 hours ago to now.
$SRs = Get-SCSMObject -Class $srClass -Filter "CreatedDate -gt $Date12HoursAgo"
"No Assigned User on the following Service Requests:`n`n"
foreach ($SR in $SRs)
{

if(!(Get-SCSMRelatedObject -SMObject $SR -Relationship $RelAssignedTo))
{
$SR | ft Displayname, CreatedDate -HideTableHeaders
}
}
```


Commented Unassigned: All Unassigned Service Requests script needed [11252]

$
0
0
Hello, I would like to write a script to pull all the unassigned service requests that were created 12hrs prior to current date. I need to be able to filter on specific support groups. It appears easier to do this for incidents but because there is no get-scsmservicerequest cmdlet, I am at a loss. Thanks
Comments: ** Comment from web user: bobske **

Can't seem to edit comments :(. But forgot to fix the AddHours value, it's of course suppose to say -12 and not -400.

New Post: Get-SCSMObject not returning computers

$
0
0
I'm stumped. Hopefully someone can tell me what I'm doing wrong. I'm just trying to get a list of computers from SCSM. I'm querying classes and names that I know exist (I can see them from the SCSM console), and I'm getting no results back at all.

This is what I'm running:

$Class = Get-SCSMClass -Name Microsoft.Windows.Server.computer$
Get-SCSMObject -Class $Class -filter "PrincipalName -like servername"

This returns nothing at all, but again, I know the server name actually exists in SCSM.

I can also just do a Get-SCSMObject -Class $Class and get no results, either. I would think that this should return all items of the server class.

Thanks in advance for your help. This is driving me insane!

New Post: Using New-SCSMIncident to add support group (nested) e.g. ABC\1LS

$
0
0
How did you create the app from a powershell script?
Did you create a UI?

u0005293 wrote:
With very little powershell knowledge I managed to bodge a little app together that created, resolved and closed incidents for my service desk staff. They basically put an end user name in and click on a button that refers to the problem for stuff service desk people do on the fly, e.g. username click changed password. Anyway.... Its been quite popular and a few other teams where I work want to use it too, I have an issue though that their support groups are nested e.g. dept1\ dept1\1LS dept1\2LS I had a unique name for my dept so this wasn't an issue, New-SCSMIncident ....... with –SupportGroup "ICT" was fine, but it won't accept –SupportGroup "dept1\2LS" it would accept "2LS" but this could be any 1 of 4 departments. Any ideas? could I somehow use the full enumeration string? thanks Paul Wilson

New Post: Using New-SCSMIncident to add support group (nested) e.g. ABC\1LS

$
0
0
``` my code below for the UI, I've since found a couple of utilities that would have created this for me
Function MyMenu {

[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

$x=""
$y=""
$usrin=""

$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = "Log Quick Job"
$objForm.Size = New-Object System.Drawing.Size(310,300)
$objForm.StartPosition = "CenterScreen"

$objForm.KeyPreview = $True
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Enter")
{$x=$objTextBox.Text;$objForm.Close()}})
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape")
{$objForm.Close()}})




Change Pword

$PwordButton = New-Object System.Windows.Forms.Button
$PwordButton.Location = New-Object System.Drawing.Size(1,120)
$PwordButton.Size = New-Object System.Drawing.Size(75,23)
$PwordButton.Text = "Password"
$PwordButton.Add_Click({$x=$objTextBox.Text; $y="Changed User Password"; $source=$objTextBox3.Text; $objForm.Close()})
$objForm.Controls.Add($PwordButton)

Chioce1

$c1Button = New-Object System.Windows.Forms.Button
$c1Button.Location = New-Object System.Drawing.Size(1,144)
$c1Button.Size = New-Object System.Drawing.Size(75,23)
$c1Button.Text = "AcLockd"
$c1Button.Add_Click({$x=$objTextBox.Text; $y="choice1"; $source=$objTextBox3.Text; $objForm.Close()})
$objForm.Controls.Add($c1Button)

Chioce2

$C2Button = New-Object System.Windows.Forms.Button
$C2Button.Location = New-Object System.Drawing.Size(1,168)
$C2Button.Size = New-Object System.Drawing.Size(75,23)
$C2Button.Text = "Asoc Amnd"
$C2Button.Add_Click({$y="choice2"; $x=$objTextBox.Text; $usrin=$objTextBox2.Text; $source=$objTextBox3.Text; $objForm.Close()})
$objForm.Controls.Add($C2Button)

Chioce3

$C3Button = New-Object System.Windows.Forms.Button
$C3Button.Location = New-Object System.Drawing.Size(1,192)
$C3Button.Size = New-Object System.Drawing.Size(75,23)
$C3Button.Text = "Query"
$C3Button.Add_Click({$y="choice3"; $x=$objTextBox.Text; $usrin=$objTextBox2.Text; $source=$objTextBox3.Text; $objForm.Close()})
$objForm.Controls.Add($C3Button)

choice2.1

$CH21Button = New-Object System.Windows.Forms.Button
$CH21Button.Location = New-Object System.Drawing.Size(100,120)
$CH21Button.Size = New-Object System.Drawing.Size(75,23)
$CH21Button.Text = "MyPr Paper"
$CH21Button.Add_Click({$y="choice21"; $x=$objTextBox.Text; $usrin=$objTextBox2.Text; $source=$objTextBox3.Text; $objForm.Close()})
$objForm.Controls.Add($CH21Button)

choice2.2

$CH22Button = New-Object System.Windows.Forms.Button
$CH22Button.Location = New-Object System.Drawing.Size(100,144)
$CH22Button.Size = New-Object System.Drawing.Size(75,23)
$CH22Button.Text = "MyPr Toner"
$CH22Button.Add_Click({$y="choice22"; $x=$objTextBox.Text; $usrin=$objTextBox2.Text; $source=$objTextBox3.Text; $objForm.Close()})
$objForm.Controls.Add($CH22Button)

choice2.3

$CH23Button = New-Object System.Windows.Forms.Button
$CH23Button.Location = New-Object System.Drawing.Size(100,168)
$CH23Button.Size = New-Object System.Drawing.Size(75,23)
$CH23Button.Text = "S Phone"
$CH23Button.Add_Click({$y="choice23"; $x=$objTextBox.Text; $usrin=$objTextBox2.Text; $source=$objTextBox3.Text; $objForm.Close()})
$objForm.Controls.Add($CH23Button)

choice2.4

$CH24Button = New-Object System.Windows.Forms.Button
$CH24Button.Location = New-Object System.Drawing.Size(100,192)
$CH24Button.Size = New-Object System.Drawing.Size(75,23)
$CH24Button.Text = "Eduroam"
$CH24Button.Add_Click({$y="choice24"; $x=$objTextBox.Text; $usrin=$objTextBox2.Text; $source=$objTextBox3.Text; $objForm.Close()})
$objForm.Controls.Add($CH24Button)

choice3.1

$CH31Button = New-Object System.Windows.Forms.Button
$CH31Button.Location = New-Object System.Drawing.Size(200,120)
$CH31Button.Size = New-Object System.Drawing.Size(75,23)
$CH31Button.Text = "Non IT Query"
$CH31Button.Add_Click({$y="choice31"; $x=$objTextBox.Text; $usrin=$objTextBox2.Text; $source=$objTextBox3.Text; $objForm.Close()})
$objForm.Controls.Add($CH31Button)

choice3.2

$CH32Button = New-Object System.Windows.Forms.Button
$CH32Button.Location = New-Object System.Drawing.Size(200,144)
$CH32Button.Size = New-Object System.Drawing.Size(75,23)
$CH32Button.Text = "choice"
$CH32Button.Add_Click({$y="choice32"; $source=$objTextBox3.Text; $objForm.Close()})
$objForm.Controls.Add($CH32Button)

choice3.3

$CH33Button = New-Object System.Windows.Forms.Button
$CH33Button.Location = New-Object System.Drawing.Size(200,168)
$CH33Button.Size = New-Object System.Drawing.Size(75,23)
$CH33Button.Text = "choice"
$CH33Button.Add_Click({$y="choice33"; $source=$objTextBox3.Text; $objForm.Close()})
$objForm.Controls.Add($CH33Button)

choice3.4

$CH34Button = New-Object System.Windows.Forms.Button
$CH34Button.Location = New-Object System.Drawing.Size(200,192)
$CH34Button.Size = New-Object System.Drawing.Size(75,23)
$CH34Button.Text = "choice"
$CH34Button.Add_Click({$y="choice34"; $source=$objTextBox3.Text; $objForm.Close()})
$objForm.Controls.Add($CH34Button)

Cancel

$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(100,235)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = "Close"
$CancelButton.Add_Click({$exit = 1; $source = ""; $objForm.Close()})
$objForm.Controls.Add($CancelButton)

UserName box

$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(10,20)
$objLabel.Size = New-Object System.Drawing.Size(150,20)
$objLabel.Text = "User Name"
$objForm.Controls.Add($objLabel)

$objTextBox = New-Object System.Windows.Forms.TextBox
$objTextBox.Location = New-Object System.Drawing.Size(10,40)
$objTextBox.Size = New-Object System.Drawing.Size(150,20)
$objForm.Controls.Add($objTextBox)

Source box

$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(170,20)
$objLabel.Size = New-Object System.Drawing.Size(280,20)
$objLabel.Text = "Source (E,P or W)"
$objForm.Controls.Add($objLabel)

$objTextBox3 = New-Object System.Windows.Forms.TextBox
$objTextBox3.Location = New-Object System.Drawing.Size(170,40)
$objTextBox3.Size = New-Object System.Drawing.Size(90,20)
$objForm.Controls.Add($objTextBox3)

Problem text box

$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(10,60)
$objLabel.Size = New-Object System.Drawing.Size(280,20)
$objLabel.Text = "Description"
$objForm.Controls.Add($objLabel)

$objTextBox2 = New-Object System.Windows.Forms.TextBox
$objTextBox2.Location = New-Object System.Drawing.Size(10,80)
$objTextBox2.Size = New-Object System.Drawing.Size(260,20)
$objForm.Controls.Add($objTextBox2)

$objForm.Topmost = $True

$objForm.Add_Shown({$objForm.Activate()})
[void] $objForm.ShowDialog()

username and job are now x and y

}

New Post: Get-SCSMObject not returning computers

$
0
0
Maybe you're looking at the wrong class. Have you tried Microsoft.Windows.Computer$ instead?

Try to go backwards instead like this:

$Class = Get-SCSMClass -Name system.entity #most parent class

$obj = Get-SCSMObject -Class $Class -Filter "Name -like servername" #make sure to have filter here, or you're gonna wait all night : )

$obj.GetLeastDerivedNonAbstractClass()

This will get you the class of the object.

New Post: Service requests creation

$
0
0
Hey everyone.
I'm implementing an Icident Request from Service Request converter by Thomas Ellermann http://gallery.technet.microsoft.com/Create-Incident-from-f19aaea0#content
and I faced a problem:
When creating Service Request, using New-SCSMObject is it possible to add Support Group?
And the other question is - is it possible to auto-open Service Request in console after creation?
Thanks in advance!

Closed Unassigned: All Unassigned Service Requests script needed [11252]

$
0
0
Hello, I would like to write a script to pull all the unassigned service requests that were created 12hrs prior to current date. I need to be able to filter on specific support groups. It appears easier to do this for incidents but because there is no get-scsmservicerequest cmdlet, I am at a loss. Thanks
Comments: Bobske is right.

Commented Issue: Get-SMProperty PowerShell 3 Incompatibility [10983]

$
0
0
When trying to run get-smproperty using Powershell 3, One will receive an error similar to the following:

```
add-member : Cannot add a member with the name "Class" because a member with that name already
exists. If you want to overwrite the member anyway, use the Force parameter to overwrite it.
At line:2 char:35
+ $class.GetProperties("recursive")|add-member -pass NoteProperty Class $class |
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (SRText1:PSObject) [Add-Member], InvalidOperation
Exception
+ FullyQualifiedErrorId : MemberAlreadyExists,Microsoft.PowerShell.Commands.AddMemberCommand
```

Repro steps:

1. Open Powershell V3
2. Import SMlets module
3. Run : get-smproperty -classname [classname guid from XML or SCSMAuthoring Tool]

Workaround:
1. Open powershell v2 (start > run > powershell -v 2)
2. Run commands as normal.
Comments: ** Comment from web user: radtravis **

Interesting. Works the first time. Fails subsequent times.

Edited Issue: Get-SMProperty PowerShell 3 Incompatibility [10983]

$
0
0
When trying to run get-smproperty using Powershell 3, One will receive an error similar to the following:

```
add-member : Cannot add a member with the name "Class" because a member with that name already
exists. If you want to overwrite the member anyway, use the Force parameter to overwrite it.
At line:2 char:35
+ $class.GetProperties("recursive")|add-member -pass NoteProperty Class $class |
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (SRText1:PSObject) [Add-Member], InvalidOperation
Exception
+ FullyQualifiedErrorId : MemberAlreadyExists,Microsoft.PowerShell.Commands.AddMemberCommand
```

Repro steps:

1. Open Powershell V3
2. Import SMlets module
3. Run : get-smproperty -classname [classname guid from XML or SCSMAuthoring Tool]

Workaround:
1. Open powershell v2 (start > run > powershell -v 2)
2. Run commands as normal.

Edited Issue: -UserComment switch for Set-SCSMIncident is not documented [10770]

$
0
0
-UserComment switch for Set-SCSMIncident (original work item 7118) is not document in usage syntax. Please add it to usage syntax so it is easily discoverable

Commented Issue: System.Exception: The specified snap-in 'SMlets' failed to load [10705]

$
0
0
System.Exception: The specified snap-in 'SMlets' failed to load with below exception

System.Management.Automation.PSArgumentException: No snap-ins have been registered for Windows PowerShell version 2.

I have created several powershell scripts that run fine with I run them on the server, however, when I package them in the SM Authoring tool, and deploy them (import MP & copy DLLs) they fail to load the SMlets module.

I believe I have beta3 installed. (how do I check?)

This is SCSM 2012 - on all x64 server Windows 2008 R2

I was initially trying to have the module load via the GUI option in the Authoring tool, then i tried to remove that, and add the import and removal directly in the script.

But is keeps faling with that error... I have only installed SMlets on the management server, not the DW... (do I need to?)

Here is a simple script that fails.
$a = (get-module|%{$_.name}) -join " "
if(!$a.Contains("SMLets")){Import-Module SMLets -ErrorVariable err -Force}

$CRClass = get-scsmclass -name System.WorkItem.ChangeRequest$
$CRobj = Get-SCSMObject -Class $CRClass -Filter "ID -eq $CRID"

if ($CRobj.Status.displayname -eq "approved")
{
$i = 0
if ($CRobj.ActualStartDate -ne $null) {$i++}
if ($CRobj.ActualEndDate -ne $null) {$i++}
if ($CRobj.ImplementationResults -ne $null) {$i++}
}

if ($i -eq 3){Set-SCSMObject -SMObject $CRobj -Property status -Value "executed"}

Remove-module smlets -force
Comments: ** Comment from web user: radtravis **

This is some weird PowerShell behavior. I don't think we can fix it in SMLets.

Closed Issue: System.Exception: The specified snap-in 'SMlets' failed to load [10705]

$
0
0
System.Exception: The specified snap-in 'SMlets' failed to load with below exception

System.Management.Automation.PSArgumentException: No snap-ins have been registered for Windows PowerShell version 2.

I have created several powershell scripts that run fine with I run them on the server, however, when I package them in the SM Authoring tool, and deploy them (import MP & copy DLLs) they fail to load the SMlets module.

I believe I have beta3 installed. (how do I check?)

This is SCSM 2012 - on all x64 server Windows 2008 R2

I was initially trying to have the module load via the GUI option in the Authoring tool, then i tried to remove that, and add the import and removal directly in the script.

But is keeps faling with that error... I have only installed SMlets on the management server, not the DW... (do I need to?)

Here is a simple script that fails.
$a = (get-module|%{$_.name}) -join " "
if(!$a.Contains("SMLets")){Import-Module SMLets -ErrorVariable err -Force}

$CRClass = get-scsmclass -name System.WorkItem.ChangeRequest$
$CRobj = Get-SCSMObject -Class $CRClass -Filter "ID -eq $CRID"

if ($CRobj.Status.displayname -eq "approved")
{
$i = 0
if ($CRobj.ActualStartDate -ne $null) {$i++}
if ($CRobj.ActualEndDate -ne $null) {$i++}
if ($CRobj.ImplementationResults -ne $null) {$i++}
}

if ($i -eq 3){Set-SCSMObject -SMObject $CRobj -Property status -Value "executed"}

Remove-module smlets -force

Commented Issue: Cannot create Service Request using Request Offering that doesn't have questsions. [10317]

$
0
0
I have a generic Service Request Offering with no questions that is used for one-off requests. When I try to script the creation of the Service Request, I get an error "Object reference not set to the instance of an object". If I use an Offering with Questions, it works fine.
Comments: ** Comment from web user: radtravis **

Can you please share the script that works and the script that doesn't work?

Edited Issue: Issues invoking SMlets from a remote machine [10188]

$
0
0
I have SCSM installed in a lab, on a member server. I'm on a laptop that sits outside the domain. I have SMlets installed there too, as well as the authoring toolkit and the SCSM console.
 
When I try to load the SMlets, the first time I was getting errors because they couldn't find the SDK Binaries folder in the SCSM install folder. These do not seem to be installed with the authoring toolkit nor with the SCSM console. I had to copy them over from the server. It would be useful if the SMlets checked for this and reported an appropriate error, telling users what to do.
 
Next, once they were loaded, I can invoke them with simple calls, such as Get-SCSMIncident. When I do that however, since SCSM isn't installed locally, I get an unhelpful error:
 
Get-SCSMIncident : The Data Access service is either not running or not yet initialized. Check the event log for more i
nformation.
At line:1 char:17
+ get-scsmincident <<<<
+ CategoryInfo : InvalidOperation: (localhost:String) [Get-SCSMIncident], ServiceNotRunningException
+ FullyQualifiedErrorId : GenericMessage,SMLets.SCSMIncidentGet
 
This should be designed better so that the cmdlets check to see if SCSM is installed on the local machine if they're run locally (it could check once and cache it, because it does the check on import), and then if you invoke a local command by accident it should tell you SCSM isn't installed on the local machine.
 
Also, it would be quite useful to add a Connect-SCSMServer cmdlet, where I could specify the server name and the credentials, and then from that point on every other SMLet I would call would use that connection. That would be much, much easier for remote management of SCSM.

Edited Feature: The Credential parameter needs to accept string input as well as PSCredential [10187]

$
0
0
Today the Credential parameter is implemented inconsistently in these cmdlets. In core PowerShell, you can pass in a string and it will automatically convert to PSCredential using a type converter, which results in a prompt being displayed as if you had called Get-Credential. The SMlets don't do this however, so you must explicitly use Get-Credential, which should not be necessary.
 
For example, I should be able to do this:
 
Get-SCSMIncident -ComputerName scsm -Credential SCLab\Administrator
 
But I cannot. I have to do this instead:
 
Get-SCSMIncident -ComputerName scsm -Credential (Get-Credential SCLab\Administrator)
 
Please fix this so that it's consistent with the rest of PowerShell.

Edited Issue: Incident Priority is not being set in New-SCSMIncident [8943]

$
0
0
The .Priority field is not being set dependent on the urgency and impact.

Commented Issue: Unable to import module after upgrading to SCSM 2012 SP1 [10764]

$
0
0
After upgrading to SCSM 2012 SP1, the following exception is thrown when attempting to import the SMlets module. I suspect they will need a recompile against the the SP1 bits.

Command execution stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Cannot load Windows PowerShell snap-in C:\Program Files\Common Files\SMLets\SMLets.Module.dll because of the following error: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
Loader Exceptions:

Could not load file or assembly 'Microsoft.EnterpriseManagement.Core, Version=7.0.5000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
Could not load file or assembly 'Microsoft.EnterpriseManagement.Core, Version=7.0.5000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
Could not load file or assembly 'Microsoft.EnterpriseManagement.Core, Version=7.0.5000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
Comments: ** Comment from web user: radtravis **

Closing this issue as it works for me and there is no activity on it.

Closed Issue: Unable to import module after upgrading to SCSM 2012 SP1 [10764]

$
0
0
After upgrading to SCSM 2012 SP1, the following exception is thrown when attempting to import the SMlets module. I suspect they will need a recompile against the the SP1 bits.

Command execution stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Cannot load Windows PowerShell snap-in C:\Program Files\Common Files\SMLets\SMLets.Module.dll because of the following error: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
Loader Exceptions:

Could not load file or assembly 'Microsoft.EnterpriseManagement.Core, Version=7.0.5000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
Could not load file or assembly 'Microsoft.EnterpriseManagement.Core, Version=7.0.5000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
Could not load file or assembly 'Microsoft.EnterpriseManagement.Core, Version=7.0.5000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

Edited Issue: Add filtering capacity to Get-SCSMRelationshipObject [7978]

$
0
0
it should be possible to restrict the results of Get-SCSMRelationshipObject once the type/source/target is declared
Viewing all 306 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>