Add a config item to windows computer via powershell script
Hello All
I am looking for a script which will add a config item into windows computer . I have some thing like this which will add the configuration item into an incident . But I want to add to a computer record in all windows computer. I think I am failing to find
the source for windows computer records
$incident
= get-scsmclass
m.incident$ |get-scsmobject
-filter "DisplayName -eq 'IR8 - test'"
$computer
= get-scsmclass
Microsoft.Windows.Computer$|get-scsmobject
-filter "PrincipalName -eq 'test'"
$relationship
= Get-SCSMRelationshipClass
-name System.WorkItemAboutConfigItem
New-SCSMRelationshipObject
-Relationship $relationship
-Source $incident
-Target $computer
-bulk
I really don't understand what your are trying to do. do you want to add a new windows computer object to the database, or add an existing windows computer object to the list of related items on a work item?
if you are trying to create a windows computer by hand, i would recommend against it. there are much easier ways to get that data from SCCM or AD via connectors. maybe you could elaborate on your need?
If you are trying to relate an existing windows computer to a work item, then your script is correct. you just need to get the computer object in one hand, the work item in the other and mash them together with a New-SCSMRelationship around the correct Relationship
class. remember that About (System.WorkItemAboutConfigItem) is for the Affected config item, where as Relates (System.WorkItemRelatesToConfigItem) is for the related config items. an arrow affects the target and is related to the archer; don't get them confused.
the only other interpretation (and the one i find least likely) is that you are trying to relate two computers together, in which case the script is still correct, except, obviously, the relationship class should be System.ConfigItemRelatesToConfigItem,
and you would need to get a windows computer in each hand.
Similar Messages
-
Looking for a way to install Windows Intune via powershell
I'm very new to Powershell and completely lost on how to do this.
Looking for a way to install Windows Intune via powershell from a self extracting zip file I will send to remote users. This will also need to run Corp admin level privileges to install.
Thank you in advance for your help.Hi Mtirado,
For Windows Intune issue, I recommemd you can post in dedicated forum for more effective support:
https://social.technet.microsoft.com/Forums/en-US/home?category=windowsintune
If you get the initial Powershell script, and the script encounter error or problem, you can post back with current script and issue.
Thanks for your understanding.
If you have any feedback on our support, please click here.
Best Regards,
Anna Wang
TechNet Community Support -
Accessing a Windows computer via ARD
Just downloaded the ARD app and have successfully connected to my wife's MacBook, but I'm having troubles connecting to a Windows XP computer using RealVNC. I'm not sure what user name and password ARD is looking for from the XP computer. When connecting to the XP computer via RealVNC viewer, I'm not asked for a username (It's greyed out) but only a password.
Any insights?
Thanks in advance.
LoboHi
From the mac can you telnet to the PC on port 5900? Instead of paying for the Enterprise Version of RealVNC to install on the mac you could have used the free RDC for Mac:
http://www.microsoft.com/downloads/en/details.aspx?FamilyID=68346e0d-44d3-4065-9 9bb-b664b27ee1f0&displayLang=en
Tony -
How to Add Multiple Driver Packages Using Reference File via PowerShell
Hey All -
I've got a task I'm working on which would be much easier via PowerShell. I tried figuring it out, but couldn't so thought I'd post.
The Task
I need to create about 50 new, empty driver packages (most are in the same folder in the console) and am trying to find a method of doing so where I may use a source text file / csv file as reference in the command line. Each package has a unique name
and source path. Here are examples:
- Latitude E5440 Win7 x86 [A01] \\server\drivers\5440x86
- Latitude E5440 Win7 x64 [A01] \\server\drivers\5440x64
The Structure
All of the ones I want to add via PowerShell will go into the same folder in the console. They will be in the folder "root\New Drivers\Dell CAB Drivers"
Any ideas or will this just take more time than it's worth for 50? Thanks!
Ben K.Also, the creation of the driver package won't be your biggest challenge, as it's as simple as New-CMDriverPackage (see:
http://technet.microsoft.com/en-us/library/jj821724(v=sc.20).aspx).
The biggest challenge is relating your models to a share name (unless they're all Latitude).
My Blog: http://www.petervanderwoude.nl/
Follow me on twitter: pvanderwoude -
Add Multiple Domains as an External Relay via powershell from a list
Hello,
I have a requirement to add a few hundred external domains as a relay and would like to accomplish this via powershell. I'm familiar with the command to submit 1 at a time but would like to have it read them all in from a list if possible. Any help would
be great!
Thank you,
EricHello Eric,
Just replied similar question in a thread, you can refer to that...
http://social.technet.microsoft.com/Forums/exchange/en-US/b84cd2e7-5fb3-4a1d-9bcc-41acdb7142a2/adding-multiple-accepted-domains-with-importcsv?forum=exchangesvrdeploy -
Trying to add Admin account in project server 2010 via powershell
Dear All
Unfortunately some one removed admin account from PWA 2010 so i have tried to add admin account via powershell command
New-SPProjectSiteAdministrator -AdminAccount "dir\santosh" -Url "https://myserver/PWA"
New-SPProjectSiteAdministrator : <nativehr>0x80070005</nativehr><nativestack></nativestack> At line:1 char:31 + New-SPProjectSiteAdministrator <<<< -AdminAccount "dir\santosh"
-Url "https://myserver/PWA" + CategoryInfo : InvalidData: (Microsoft.Offic...ewAdministrator:PSCmdletNewAdministrator) [New-SPProjectSiteAdministrator], Unaut
horizedAccessException + FullyQualifiedErrorId : Microsoft.Office.Project.Server.Cmdlet.PSCmdletNewAdministrator
Getting above error
Help me
Regards
SanthuHello,
Can't you log in with an account that is already in the Administrators group then add the new account? I think you will need to run the command with a user account that already has admin access to PWA - I don't currently have an environment to test this
on.
Paul
Paul Mather | Twitter |
http://pwmather.wordpress.com | CPS -
Our network was hit recently with virus previously unknown, O97M.Crigent. It is a nasty Macro virus that targets Microsoft Office Documents & Spreadsheets and uses a combination of Macros and Scripts via Powershell.
How do I disable PowerShell scripting via Group Policy?
Will this raise any issues such as random application or network failures or other issues?
Can I apply it to the entire domain or should I be selective and only apply it to the workstations?
Network Summary: Windows 2008 Active Directoy Server, 75% Windows 7, 25% Windows XP workstations.
DouglasOfSanMarcosDisabling Windows PowerShell can be done with GPO:
Computer Configuration | Administrative Templates | Windows Components | Windows PowerShell
From GPO Description: "This setting exists under both "Computer Configuration" and "User Configuration" in the group policy editor. The "Computer Configuration" has precedence over "User Configuration."
By default this option is restricted any way on computers.
I would be very selective when apply it at all:
Workstations - I would apply to test group of workstations first, just to see that there are no side effects before applying to all computers.
Server - I wouldn't apply it at all. I have seen too many issues when setting this policy on Exchange and other systems.
If you are using a Group Policy to define a PowerShell logon, logoff or computer script, that script will disregard any execution policy set locally or through a GPO.
http://4sysops.com/archives/set-powershell-execution-policy-with-group-policy/
http://technet.microsoft.com/en-us/library/hh849812.aspx
Please take a moment to Vote as Helpful and/or Mark as Answer where applicable. Thanks. -
Hi,
I´m in a situation where I need to disable static IP option on all Domain machines (workstations). I have found many different forum topics about that but nothing is suitable for me. Let me describe a situation:
* In our environment every computer have specific IP configured in DHCP (specific MAC = specific IP). Machines Must be configured DHCP enabled!
* In our environment all developers are local admins in their computers. This can´t be changed as we are IT corporation and this is our policy.
* As every IP have specific rights in Firewall to access different places then some IT guys are quite smart to change their IP to static IP that have more access then they should have.
This last thing is my main problem! We have working PKI and NPS in both WLAN and LAN so only domain and certified computers can have access to our local network. My mission is to prevent local admins to change IP addressess by themselves but I can´t find
a good solution for doing that. I have tought about Powershell script that is published by SCCM or GPO to all workstations and script idea is to find network card that is "connected to" our "domain.com" network. If this is true then automatically
DHCP will be enabled for that interface (Set-NetIPInterface -Dhcp Enabled). I know that here is an open window for some moment when script will be ran again or GPO policy will be refreshed but it´s better then nothing. In this script I have one problem - I
can´t find a solution about how to find network interface that is connected to our "domain.com"? It seems that there is no easy way to do that.
Is there any other and better solution to accomplished this situation. Any good ideas will be appreciated.
Best Regards,
TaaviHi,
the real answer is the one you don't want to hear: don't make your users local admninistrators.
Local administrators will always be able to get araound any security measurement you put in place. For gpo's for example, they can identify the involved registry key, configure it to their desired value and
remove privileges for everyone but themselves to write the key. Upcoming 'gpupdate' will not be able to write the values...
For your script, I would recommend to just configure all adapters to dhcp on the client computers. After all the location detection depends on the network Location Awareness service. If your users disable that one (an rermove the appropriate privileges from
registry ;) ) your script would again be useless.
That being said, as you post to the security forums my answer is focussed on the security off your solution. if you need assistance in creating this script, I would advice to post back in the Scripting guys forums (and leave out the why as you will otherwise
agin be pointed on the flawed security ;) )
I think get-connectionprofile might already be helpull on 8.1
MCP/MCSA/MCTS/MCITP -
Calculate factorial via powershell scripting
hello guys i written script until calculate the factorial via powershell but i do not know what does not work !
function factorial( [int] $n )
$result = 1;
if ( $n -gt 1 )
$result = $n * ( factorial ( $n - 1 ) )
$result
this function can not work with big number like that 999 how can i solve that problem?I get similar results, with a slightly different function. I get results up to at least 170. From 180 through at least 990 I get "Infinity" for the answer. At 999 I get your error, which I believe cannot be avoided. Even if you avoided the
call depth error, PowerShell seems to refuse to deal with such large numbers, and simply outputs "Infinity".
This article goes into factorials in depth:http://en.wikipedia.org/wiki/Factorial
It includes a table for very large values, plus a formula for approximating factorials of large numbers. You might be able to code the approximation formula.
Richard Mueller - MVP Directory Services -
58" Cloud TV...can no longer connect to Windows computer via MediaShare
Have a Dell all in one and 58" Toshiba Cloud TV. Love the TV, but have had nothing but trouble with the MediaShare function. Sometimes it finds the computer on my network, sometimes not. Now won't at all for the last week. Have tried rebooting computer, TV, and wireless router. No effect. Dell is running Windows 8.1 and has file sharing and network discovery turned on.
mcafee is a horrible piece of software along with norton the only reason they have tons of users is because they pay pc makers to preinstall it and most nonTech users just pay up after the 30days of free virus scanning
-
Connecting to Windows Computer via wireless network (Password issue)
I have a wireless network set up at my house, and we all can see each other's shared computers, and the windows machines can connect to each other without a problem.. but my Mac cannot connect to them, but they can connect to me. When I goto "Connect to Server" it asks me for a username and password for the windows machine.. I don't know what to do from here!!! Please help, thanks a bunch
In your Sharing panel, did you go into "Options" and check the box for sharing via SMB?
Then from XP you should be able to reach the Mac via //(ip# or DNS name)/
and you should see the available shares. -
Major issue trying to network with windows computer via smb
I'm pretty much ready to get rid of osx all together at this point and go to windows 7. I've tried all kinds of tricks for mount/unmounting smb shares, but I still constantly get random lockups...sometimes not even coming out of sleep. Any one else having this many problems with trying to access shares on windows? the worst part is when these crashes occur I can't force terminate any processes only a hard power down and restart fixes it.
any suggestions would be appreciatedThat got me thinking. Are you just connecting via the Finder? Maybe try setting up Autofs. I used it with sshfs all the time. Unfortunately, I know little about SMB.
I was looking for a good link and came across this PDF from Apple. I have never seen it before but had done quite a bit of research on autofs. I have to find more of these "Technical White Papers" from Apple. -
Mounting Samba (Windows) drive via shell script
This question is for the seasoned Unix geeks among us.
I have a `zsh' script (read bash/ksh on steriods) at work that prepares my build environment prior to running an Ant script (read `make' for Java). The Ant script actually looks for code that is on a shared directory, usually mounted over Samba (cifs). If I forget to manually mount this drive (Finder > Go > Connect to Server...) then the script will bomb.
Now, I have tried various attempts at using the `mount_*' commands, but can't seem to get them to actually mount a drive. I'm fairly certain that `mount_smbfs' is what I want to use, but calling it doesn't seem to work as the `man' file suggests. Naturally, I want to add this mounting call to my environment setup prior to calling the build script.
Any tips from a seasoned Unix hack out there? Thanks!
TimThere is a unix forum here which would be a better place for this question, but I believe the problem is you haven't created a mount point in the Volumes folder which would then be the path argument.
Here is the examples from the mount_afp
EXAMPLES
The following example illustrates how to mount the afp volume server.com-
pany.com/volumename/ at the mount point /Volumes/mntpnt:
mkdir /Volumes/mntpnt
mount_afp afp://username:[email protected]/volumename/ /Volumes/mntpnt
This example shows the proper url to use to mount the volume guestVolume
from the afp server myserver as guest:
mkdir /Volumes/guest
mount_afp "afp://;AUTH=No%20User%20Authent@myserver/guestVolume" /Volumes/guest
This example shows the proper url to use to mount the volume myVolume
from the afp server myserver using Kerberos authentication:
mkdir /Volumes/myVolume
mount_afp "afp://;AUTH=Client%20Krb%20v2@myserver/myVolume" /Volumes/myVolume -
Uninstalled a program via PowerShell script, but it still shows up in Programs and Features
I wrote a script that uninstalls a program just fine, but it still shows up in Programs and Features due to its entries still existing in the Registry.
Here is a portion of my script:
Start-Process
-FilePath MsiExec
-ArgumentList "/X$($MyProgram.ProdID)",
'/quiet'
-NoNewWindow -Wait
-PassThru
I believe the reason it is still showing up in Programs and Features is because I am missing some MsiExec switch to instruct it to be removed. I vaguely recall dealing with this about two years ago and I wrote a script that did exactly this, but now I completely
forgot what it was.
Can someone help me out here, please?
Thank youI realize that, but honestly don't know where else to submit a question like this in the forums? Also, the vendor is Microsoft. What I am trying to uninstall is any Forefront component, because when I deployed the SCEP client via SCCM 2012 the SCEP client
was not able to uninstall some of the Forefront components.
Here is my script:
$NewLine = "`r`n"
$NewLine
Write-Output "Please wait ..."
#region ---------- Declare WMI Variables to be Used ----------
$CM12R2ClientInstalled = Get-WmiObject -Class Win32_Product |
Where-Object -FilterScript { $_.Name -eq "Configuration Manager Client" -and $_.Version -ge "5.00.7958.1000" }
$FCSInstalled = Get-WmiObject -Class Win32Reg_AddRemovePrograms |
Where-Object -FilterScript { $_.DisplayName -match "Forefront" }
$SCEPInstalled = Get-WmiObject -Class Win32Reg_AddRemovePrograms |
Where-Object -FilterScript { $_.DisplayName -eq "System Center Endpoint Protection" }
#endregion ---------- Declare Variables to be Used ----------
#region --------- Check if the SCCM 2012 R2 Client is Installed ---------
$CM12ClientService = Get-Service -Name CcmExec
If (($CM12R2ClientInstalled -ne $null) -and ($CM12ClientService -ne $null))
$NewLine
Write-Output "The $($CM12R2ClientInstalled.Name) $($CM12R2ClientInstalled.Version) is installed on $($env:COMPUTERNAME)"
#endregion --------- Check if the SCCM 2012 R2 Client is Installed ---------
#region -------- Uninstall any Forefront Component if any are Installed ---------
If ($FCSInstalled)
$NewLine
Write-Output "The following Forefront component(s) are installed on $($env:COMPUTERNAME):"
$NewLine
$FCSInstalled.DisplayName
Foreach ($FCS in $FCSInstalled)
$NewLine
Write-Output "Preparing to uninstall $($FCS.DisplayName)"
$UninstallFCS = Start-Process -FilePath MsiExec -ArgumentList "/X$($FCS.ProdID)", 'REMOVEDATA=1' -NoNewWindow -Wait -PassThru
If ($($UninstallFCS.ExitCode) -eq '0')
$NewLine
Write-Output "$($FCS.DisplayName) uninstalled successfully!"
$NewLine
#endregion -------- Uninstall any Forefront Component if any are Installed ---------
#region --------- Install the SCEP Client if it is Not Installed ----------
If ($SCEPInstalled -eq $null)
$NewLine
Write-Output "The System Center Endpoint Protection client is not installed on $($env:COMPUTERNAME)"
$InstallSCEP = Start-Process -FilePath "C:\Windows\ccmsetup\SCEPInstall.exe" -ArgumentList '/s', '/q', '/NoSigsUpdateAtInitialExp', '/policy "C:\Windows\CCM\EPAMPolicy.xml"' -NoNewWindow -Wait -PassThru
If ($($InstallSCEP.ExitCode) -eq '0')
$NewLine
Write-Output "System Center Endpoint Protection installed successfully!"
$NewLine
Else
$NewLine
Write-Warning -Message "System Center Endpoint Protection failed to install on $($env:COMPUTERNAME) with exit error: $($InstallSCEP.ExitCode)"
$NewLine
#endregion --------- Install the SCEP Client if it is Not Installed ----------
Else
$NewLine
Write-Output "The System Center Endpoint Protection client is already installed on $($env:COMPUTERNAME)!"
$NewLine
Else
$NewLine
Write-Warning -Message "$($FCS.DisplayName) failed to uninstall on $($env:COMPUTERNAME) with exit error: $($UninstallFCS.ExitCode)"
$NewLine
Else
$NewLine
Write-Output "No Forefront components are installed on $($env:COMPUTERNAME)!"
#region ---------- Install the SCEP Client if it is NOT Installed ----------
If ($SCEPInstalled -eq $null)
$NewLine
Write-Output "The System Center Endpoint Protection client is not installed on $($env:COMPUTERNAME)"
$InstallSCEP = Start-Process -FilePath "C:\Windows\ccmsetup\SCEPInstall.exe" -ArgumentList '/s', '/q', '/NoSigsUpdateAtInitialExp', '/policy "C:\Windows\CCM\EPAMPolicy.xml"' -NoNewWindow -Wait -PassThru
If ($($InstallSCEP.ExitCode) -eq '0')
$NewLine
Write-Output "System Center Endpoint Protection installed successfully!"
$NewLine
Else
$NewLine
Write-Warning -Message "System Center Endpoint Protection failed to install on $($env:COMPUTERNAME) with exit error: $($InstallSCEP.ExitCode)"
$NewLine
#endregion --------- Install the SCEP Client if it is Not Installed ----------
Else
$NewLine
Write-Output "The System Center Endpoint Protection client is already installed on $($env:COMPUTERNAME)!"
$NewLine
Else
$NewLine
Write-Output "The System Center Configuration Manager 2012 R2 client is not installed on $($env:COMPUTERNAME)!"
$NewLine -
Strange behavior from script when dismounting content databases via PowerShell script
So, this is my first time posting a question here. I have taught myself PowerShell and for the most between friends, co-workers, or internet forums, I have been able to pick through most of the issues I have seen. This one has me stuck.
So, a little background, I have a script that goes through each web app in a farm, finds the database that hosts the root site, and detaches all other content databases from the farm. It also writes a csv file so that a process can come along after the
fact to re-attach the databases. I use this for patching so psconfig does not take quite as long as we have more than 50 content databases. Here is the odd part. After the first content database is detached, the second one is skipped, but
the remainder are detached. So, I have two databases left per web app. One that holds the root site and whatever the second database is after the first detach. If I comment out the line that actually does the detach, this does not happen.
Now, using ISE and adding break points, what I have found is that when I initially populate the array with the content databases ($var=$webapp.contentdatabase) all databases are in there. When I start the foreach, all databases are in there. Right
up to the point that I detach the first database, all databases are still in the array variable. As soon as I detach that database, the database that I detached gets removed from the array. It does this even if I set the variable to read only.
It only happens with the first database detached in each web app. I will try to explain this again with an example. This test farm has 4 databases. DB1, DB2, DB3, and DB4. DB1 holds the root site. The logic pulls the webapp info.
It gets the URL of the webapp. It takes that info and finds the site collection with that name (the root site). Finds the database name from there. It then gets a list of all databases in the webapp and starts to loop through. So the
first one in the list is DB1. It has the root site, so logic says do not delete. It comes back to the loop with the next database DB2. At this point, the array still has all 4 databases in the array. DB2 does not host the root site,
so the logic gathers information and calls dismount-spcontentdatabase. As soon as that is called, that database is removed from the array. So, at this point, we have processes postion 0 and position 1 in the array. Since the original position
1 has been removed, DB3 is now at postion 1. So, the loop continues. Sine we have now skipped DB3, we find DB4 and dismount. Now, we have in the array DB1,DB3, and DB4. My test environment has more and all are still there except for
the first one removed. I have banged my head against the desk with this one. If someone has some insight, I would appreciate it.
Here is the code that does it.
get-spwebapplication | foreach-object {
$webapp=$_
$waname=$webapp.displayname
$waurl=$webapp.url
$cdbs=$webapp.contentdatabases
$rsite=get-spsite $waurl -erroraction silentlycontinue
$rsitedb=$rsite.contentdatabase
$rsitedbn=$rsitedb.name
foreach ($cdb in $cdbs) {
$cdbs=$cdbs2
$cdbname=$cdb.name
#Write-Host "$cdbname" -foregroundcolor red
if ($cdbname -ne $rsitedbn) {
$warn=$cdb.warningsitecount
$max=$cdb.maximumsitecount
$current=$cdb.currentsitecount
$dbserver=$cdb.server
Write-output "$waname,$cdbname,$dbserver,$warn,$max,$current" >> $outfile
Write-host "dismounting $cdbname" -foregroundcolor green
dismount-spcontentdatabase -identity $cdbname -confirm:$false
else {
Write-host "$cdbname holds root site. No action." -foregroundcolor yellowwhat about keeping an array of all the non-root collections (may be database name) instead of dismounting them in the foreach loop of all the databases? After we have all the databases that need to be deleted, in a for loop starting with 0 and
counting to the number of databases, check the name of the database for each index and dismount that database
pseudo code would be
$dbstobedismounted = @()
foreach($cdb in $cdbs)
$dbstobedismounted + = $cdb.Name //instead of actually dismounting
for(int i=0;i<$webapp.ContentDataBases.Count;i++)
$dabasename = $webapp.ContentDataBases[i].Name
foreach($dbtobedismounted in $dbstobedismounted)
if($databasename -eq $dbtobedismounted )
dismount-spcontentdatabase -dentty $webapp.ContentDataBases[i]
I'm sure you might have to do some modifications to make it work, but the point I'm making is instead of dismounting in the foreach loop, have a list and dismount in another for loop. Hope it helps.
rani
Maybe you are looking for
-
Post Author: dmface15 CA Forum: Administration I am working in a new enviorment and i am trying to save a report to the Crystal Server via the CMC. I am uploading the report from the objects tab and attempting to save to a folder. The report has 1 st
-
Is there a way to calculate a date field based on aother date field in sharepoint list?
In a SharePoint list, I have a 'Start of Use Date' and need to ensure the 'Review Date' is no more than 14 months after the 'Start of Use Date', but can't figure out the formula. Can you help?
-
What do you guys think about having a standard way to document thread safety of a class and its methods? Javadoc tool would place all the thread safety information in a standard place, and if there was no @threadsafety tag then it would default to so
-
File Explorer Customization - Adding Groups to Tabs?
A similar question has been asked on a different Thread but doesn't answer mine. link - http://social.technet.microsoft.com/Forums/en-US/a370afb3-712f-4535-8a3f-ebe1f04a1002/file-explorer-ribbon-customization?forum=w8itprogeneral In say Excel for exa
-
How to use graphs in flash?
User can change values in textbox and accordingly graphs change. Is it possible to do that in flash and which component we need to include for including graphs? Kind Regards Ankur