Tag: PowerShell
-
PowerShell: redirect (System.Xml.XmlDocument).Save() to console
I saw the code below somewhere, and could not remember how to do it later when I needed it. System.Xml.XmlDocument has a built in method to save the document to a file. I wanted to simulate that, but redirect it to the console. I finally found the code how to do it. $xml = new-object…
-
PowerShell to list SharePoint 2007 lists
I wanted to get a quick list of all the lists in our SharePoint 2007 environment. With PowerShell 2, it is easy.
-
PowerShell to get a users DistinguishedName
Why can’t I remember that to find a user’s Distinguished Name all i have to do is type the PowerShell cmdlet: Get-ADUser username And for a group: Get-ADGroup groupname And for a computer: Get-ADComputer computername Why can’t I remember that? It is also a quick way to find the OU of an object!
-
PowerShell code to query a table, and put the XML results into a SharePoint Document Library
If you look at this prior post, I showed how you can use an xml file in a document library as a source for an input box’s jQuery autocomplete. I wanted to automate the creation of these XML files and upload them to a SharePoint Document Library. For example, I wanted to query Microsoft CRM…
-
PowerShell Modules – Export-ModuleMember only if plugin is installed!
I have been working to move my scripts to modules. It just occurred to me that I can conditionally Export-ModuleMember if a plugin is installed. For example: Or I could export based on $env:computername. I like that idea. Only this scripts that are supposed to run on that machine are available! This just occurred to…
-
My PowerShell command to backup SQL server
Below is my PowerShell code to backup SQL servers. This will create a folder in the destination with the ServerName, then a subfolder with the date, and then a subfolder with the hour. You can backup a single database or all of them. You must have the PowerShell SQL snap ins installed: Add-PSSnapin -name SqlServerProviderSnapin110…
-
PowerShell code to update a CRM 2011 field (using REST/oData)
In this earlier post I showed how to loop through all the contacts in CRM 2011. Next thing I wanted to do was to update a field on each Account. So I needed to figure out how to update data, not just read it. Here is the code to do that:
-
PowerShell, JSON, oData and CRM 2011 (or SharePoint 2010)
I am working on how to consume data from/to SharePoint 2010 and from/to CRM 2011. I decided to try and see if I can get the data to display in PowerShell, figuring if I can get it there, I should be able to get it anywhere? Here is the code to loop through all the…
-
How to tell if your PowerShell session is remote
I wanted to write a conditional to prevent certain things from runing if in a remote PSSession. If you are in a standard PowerShell session the following is returned: [Environment]::GetCommandLineArgs()[0] = C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe If you are in a remote PSSession: [Environment]::GetCommandLineArgs()[0] = C:\Windows\system32\wsmprovhost.exe
-
How to tell if your PowerShell function was called by name or by alias
I been wanting to write functions that act differently depending on how they were called. I am not sure if this is good practice or not, but I like the idea. Turns out all you need is “$MyInvocation.InvocationName” Look at they following code: If you call the function by alias you get : This function…
