We have a functional test framework written in powershell that we use to verify the NuGet's behavior in Visual Studio.
For NuGet Visual Studio Extension
Expand Tokens on Items Using a Sitecore PowerShell Extensions Toolbox Script
During one segment of the presentation, I shared how one can seamlessly add scripts to the SPE Toolbox — a repository of utility scripts if you will — and used the following script when showing this:
Merging Nessus XML Reports with PowerShell
One of the most frequent tasks that friends have asked me is how can they merge Nessus XML reports. On this blog post I will cover how to do it using PowerShell. The process is very simple since Microsoft .Net Framework makes working with this type of data a breeze.
Finding orphaned, disconnected, inaccessible, invalid vms using PowerCLI.
Today i want to show a way of finding vms that are orphaned, disconnected, inaccessible, invalid vms using PowerCLI.
Again , we will be utilizing get-view for that with proper filter.
If the VM gets into status of disconnected, orphaned, inaccessible or invalid it will change it’s connectionstate property. So , basics:
how can we know what kind of connectionstate are thee ?
NetApp PowerShell Toolkit 101: Cluster Configuration
Using the NetApp PowerShell Toolkit (NPTK) can sometimes be a daunting task. Fortunately, it is pretty intuitive on how to configure most aspects of your storage system. Let’s start by looking at some of the cluster level configuration items that can be managed using the NTPK.
EMC XtremIO and PowerShell
I have had the opportunity to work with XtremIO quite a bit lately. One of the benefits of working for an EMC partner is lab gearJ. XtremIO hast a REST based API and I wondered what others in the community had done with the API for XtremIO and PowerShell. I started searching for the available PowerShell functionality and found a couple of different modules.
Rapid PowerShell Development with ISESteroids
Should you frequently experience de-ja-vus while writing PowerShell code – “didn’t I type in this [function|loop|statement|you name it] before?”, “how did this darn syntax for [you name it] work again?”– now there may be a cure available with the latest release of ISESteroids.
Quick Start Guide for the Pure Storage PowerShell Toolkit
The interest in the PowerShell Toolkit has grown over the last several months and I wanted to take a moment to provide some guidance on how to get started whether you are using Windows 7, Windows 8, Windows Server 2008 R2, or Windows Server 2012/R2.
How to Use PowerShell to Call Apprenda’s REST API
Windows PowerShell has quickly emerged as one of the most valuable tools for IT professionals. Its debugging tools, easy to understand syntax, and the ability to take advantage of any .NET library make it one of the most powerful integration and scripting tools out there. The fact that it allows you to accomplish tasks quickly ensures that many of the mistakes that happen with manual repetitive tasks are eliminated.
Missing DnsServer module and get-DNSServerResourceRecord
I am trying to leverage the get-DNSServerResourceRecord that comes with Powershell 4.0. On my windows 7 machine, the IT staff (I am not local admin on my machine) has installed WMF 4.0 and RSAT and enabled the latter under the Control Panel. I can see the tools, particularly the DNS mmc under the start menu. When I attempt to use it within powershell, I get "get-dnsserverresourcerecord is not recognized as the name of a cmdlet"
It seems missing from the list of available modules:
Directory: C:\Windows\system32\WindowsPowerShell\v1.0\Modules
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Manifest 1.0.0.0 ActiveDirectory {Get-ADRootDSE, Ne..
Manifest 1.0.0.0 AppLocker {Set-AppLockerPoli..
Manifest 1.0.0.0 BitsTransfer {Add-BitsFile, Rem..
Manifest 1.0.0.0 CimCmdlets {Get-CimAssociated..
Manifest 1.0.0.0 FailoverClusters {Add-ClusterDisk, ..
Manifest 1.0.0.0 GroupPolicy {Backup-GPO, Copy-..
Script 1.0.0.0 ISE {New-IseSnippet, I..
Manifest 3.0.0.0 Microsoft.PowerShell.Diagnostics {Get-WinEvent, Get..
Manifest 3.0.0.0 Microsoft.PowerShell.Host {Start-Transcript,..
Manifest 3.1.0.0 Microsoft.PowerShell.Management {Add-Content, Clea..
Manifest 3.0.0.0 Microsoft.PowerShell.Security {Get-Acl, Set-Acl,..
Manifest 3.1.0.0 Microsoft.PowerShell.Utility {Format-List, Form..
Manifest 3.0.0.0 Microsoft.WSMan.Management {Disable-WSManCred..
Manifest 1.0.0.0 NetworkLoadBalancingClusters {Add-NlbClusterNod..
Binary 1.0 PSDesiredStateConfiguration {Set-DscLocalConfi..
Script 1.0.0.0 PSDiagnostics {Disable-PSTrace, ..
Binary 1.1.0.0 PSScheduledJob {New-JobTrigger, A..
Manifest 2.0.0.0 PSWorkflow {New-PSWorkflowExe..
Manifest 1.0.0.0 PSWorkflowUtility Invoke-AsWorkflow
Manifest 1.0.0.0 TroubleshootingPack {Get-Troubleshooti..
What do I need to do to use this new cmdlet?
Date Time formating changes in script
I have a bigger script that has a section like this in it were I ask each DC for the last login and convert it to a readable format and I think formatting is the issue but I don’t know how to solve it.
$DC01=Get-ADUser $_.SamAccountName -Serverdc01-PropertiesLastLogon|Select-Object @{n='LastLogon';e={[DateTime]::FromFileTime($_.LastLogon)}} |Select-Object-ExpandPropertyLastLogon
$DC02=Get-ADUser$_.SamAccountName -Serverdc02-PropertiesLastLogon|Select-Object @{n='LastLogon';e={[DateTime]::FromFileTime($_.LastLogon)}} |Select-Object-ExpandPropertyLastLogon
$DC03=Get-ADUser$_.SamAccountName -Serverdc03-PropertiesLastLogon|Select-Object @{n='LastLogon';e={[DateTime]::FromFileTime($_.LastLogon)}} |Select-Object-ExpandPropertyLastLogon
$DC04=Get-ADUser$_.SamAccountName -Serverdc04-PropertiesLastLogon|Select-Object @{n='LastLogon';e={[DateTime]::FromFileTime($_.LastLogon)}} |Select-Object-ExpandPropertyLastLogon
If I now check that data and manipulate it I get the following
PS U:\> $dc01
20 April 2015 16:20:46
PS U:\> $dc02
22 April 2015 08:39:03
PS U:\> $dc03
17 April 2015 15:32:07
PS U:\> $dc04
22 April 2015 08:14:11
I like the format 22 April 2015 08:14:11 and want to keep it like that
If I now add them to a variable the format changes to American date format of MM/DD/YYYY HH:MM:SS. I want to either keep is as 22 April 2015 08:14:11 or have UK format of DD/MM/YYY HH:MM:SS. The server I’m running this on has it’s region set to UK
$LastTrueLogon="$dc01","$dc02","$dc03","$dc04"
PS U:\> $LastTrueLogon
04/20/2015 16:20:46
04/22/2015 08:39:03
04/17/2015 15:32:07
04/22/2015 08:14:11
$LastTrueLogon | Sort-Object | Select-Object -Last 1
04/22/2015 08:39:03
It is because a report is being generated for the service desk and it confuses them, I removed the times in the text below to compact it down (It still doesn't line up in the post), but I want to retain it in my report
DisplayName SamAccountName EmployeeNumber DC01 DC02 DC03 DC04 LastTrueLogon
Young, Sarah casepsy 32081A 05/12/2014 13/07/2014 28/08/2014 05/12/2014 12/05/2014
Changing Network Priority Stack Order
In a Windows 7 environment, all of our laptops are coming out imaged with the Network connections listed in order as follows: Local Area Connection 2, Wireless Network connection, Local Area Connection. This creates a problem when our laptop users are on their docking station, they are staying connected to the Wireless, when we want them on the Ethernet while on the dock.
To manually change the order of the stack, I can go to Control Panel > Network and Sharing Center > Change Adapter Settings > Advanced > Advanced Settings > and with the green up arrows, i can move Local Area Connection to the top followed by Local Area Connection 2, then wireless last.
I have over 200 laptops on the network and I was wondering if there was a script I could use to automate this process.
help with powershell logon script
Hi all,
I need assistance in powershell logon script to run powershell console with administrative privileges for non admin accounts.
Currently below is my logon script but some how i couldn't change my wallpaper of users logging into workstation. I feel because of console not have privilege
#setting disablefirstwizard settings
Set-itemproperty -path HKLM:\software\Microsoft\windows\internet explorer\main -name disablefirstwizard -value 1
#setting of wallpaper
Set-itemproperty -path HKCU:\Control Panel\Desktop -name wallpaper -value C:\windows\.bmp
rundll32.exe user32.dll, updateperusersystemparameters
Is there a possibility to set console environment so that rest of script will be running under user specified at top irrespective of logged in user(Guest).
$user = "test"
$password = "password"
#setting disablefirstwizard settings
Set-itemproperty -path HKLM:\software\Microsoft\windows\internet explorer\main -name disablefirstwizard -value 1
#setting of wallpaper
Set-itemproperty -path HKCU:\Control Panel\Desktop -name wallpaper -value C:\windows\.bmp
rundll32.exe user32.dll, updateperusersystemparameters
Please let me know if i need to add more information.
Thanks in advance.
thanks,
Vamsi
powershell excel search replace issue with loop
What I'm doing here is to search excel sheet for a value, if value matches it will be replaced by first value in a given text file:
example:
search for value text find the first instance replace with first value in a given text file which is "read", search again for text find again replace with "read" until can't find "text", now search for second value in array "text1", search in excel sheet find it replace with second line in given text value, which is "read1" and so on.
I have the script that is working somewhat, issue is it will replace all array values with only first line of text file which is "read", it is not looping through the second line of text file.
Can someone please help.
code:
test.txt file read as:
read
read1
read2
$text="text","text1","text2","text3"$replace=get-contentC:\script\test.txt$File="C:\script\test.xlsx"# Setup Excel, open $File and set the the first worksheet$i=0$Excel=New-Object-ComObjectExcel.Application$Excel.visible=$true$Workbook=$Excel.workbooks.open($file)$Worksheets=$Workbooks.worksheets$Worksheet=$Workbook.Worksheets.Item(1)$Range=$Worksheet.Range("A1","Z10").EntireColumnForeach($SearchStringin$text){$Search=$Range.find($SearchString)if($search-ne$null){$SearchString$replace[$i]$FirstAddress=$search.Addressdo{$Search.value()=$replace[$i]$search=$Range.FindNext($search)}while($search-ne$null-and$search.Address-ne$FirstAddress)$i++}}$WorkBook.Save()$WorkBook.Close()[void]$excel.quit()
adding wpf external on powershell
Hi Team,
I am creating an application for my work, but the only resources that I got is the built in powershell ISE from my desktop. I was able to do some applications for my co-leagues @ work using powershell + WPF. Now I am planning to create new application but this time I want to use EXTERNAL FILE for my <resourcedictionary>. But I spent a month (honestly) figuring out how to do it but I got none. I do believe powershell + WPF can do a Slick app. Please help me how to make it possible.
Here is my code #####
#build the GUI
Clear-host
cd "D:\powershell\Lesson\metro\"
Add-Type -AssemblyName PresentationCore,PresentationFramework,WindowsBase,system.windows.forms
[xml]$xaml = @"
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WindowStartupLocation="CenterScreen" Name="Main"
Width="800" Height="700" ShowInTaskbar="True">
<Window.Resources>
<ResourceDictionary Source="sample.xaml" />
</Window.Resources>
</Window>
"@
$reader = (New-Object System.Xml.XmlNodeReader $xaml)
$Window = [Windows.Markup.XamlReader]::Load($reader)
$Window.ShowDialog()
Here is the error ###############################################
Exception calling "Load" with "1" argument(s): "'sample.xaml' value cannot be assigned to property 'Source' of object 'System.Windows.ResourceDictionary'. Cannot locate resource 'samp
le.xaml'. Error at object 'System.Windows.ResourceDictionary'."
At D:\powershell\Lesson\metro\Basic_WPF.ps1:20 char:44
+ $Window = [Windows.Markup.XamlReader]::Load <<<< ($reader)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Merging two columns in a CSV
Merging two columns in a CSV to make a third
$objs=@();
$output=Import-csv-Path"U:\Abook1.csv"|ForEach {
$Object=New-ObjectPSObject-Property @{
CN =[String]::Concat($_.Surname,$_.Firstname)
Firstname=$_.firstname
Surname=$_.Surname
PersonalRef=$_.PersonalRef
}
$objs+=$Object;
}
$objs
$objs|Export-CSvU:\LeaversFeb2015.csv
Outputs this
CN Firstname PersonalRef Surname
HallJonathan Jonathan 1234156 Hall
I need CN to be Hall, Jonathan so how to I add the separator to
CN =[String]::Concat($_.Surname,$_.Firstname)
-filter and where
Hi All,
I am very new to powershell and it is just days I started learning it. I have some idea on batch scripting. I am confused when should I use -filter command and where(or where-object) commands. What is the main difference and when should we use -filter and where commands. For ex, in this command,
Get-Process | Where-Object {$_.handles -gt 200}
why can't I use get-process -filter handles -gt 200
Chaitanya.
doesn't contain a method named 'op_Addition'.
Hi, I look for a solution to add\delete PSObjects from an array. It looks like if their only one item remains in the array it is not possible to add a new object. This example get an error with adding a new object. With this line it is working $X=$AllQ | Where-Object {$_.Queue -neQ1"} $AllQ
= @()
For ($i=0;$i-lt 10;$i++) {
$X=New-ObjectPSObject-Property$QProps
$X.Queue="Q$i"
$X.Depth= $i
$AllQ+=$X
}
$X
= @()
$X
=$AllQ | Where-Object {$_.Queue -eqQ1"}
$A=New-ObjectPSObject-Property$QProps
$A.Queue="XX"
$A.Depth= 0
$X+=$A
exit
Method invocation failed because [System.Management.Automation.PSObject] doesn't contain a method named 'op_Addition'. At C:\Users\spbpho\AppData\Local\Temp\2\f5b794ec-9548-4d85-b162-e085df99a264.ps1:17 char:8 + $X += <<<< $A + CategoryInfo : InvalidOperation: (op_Addition:String) [], RuntimeException + FullyQualifiedErrorId : MethodNotFound
Cannot find a file with gci
Ok, i'm thoroughly confused.. I'm having a problem finding a file with gci and it totally exists because i'm staring at it in windows explorer
gci '\\server\share\folder\folder\folder\REV_Letter_Taft[1].DOC.hosdfmk' -force
Thats the actual file name actual filename
and if I copy the file to my local c drive and do gci REV_Letter_Taft[1].DOC.hosdfmk i get nothing. I get no errors, but no information on the file.
I must be missing something
get-wmiobject - the rpc server is unavailable - timeout issue
Hi,
I am doing a WMI query within my script, and random servers keep timing out and jumping into the CATCH portion of the Try/Catch and not every time I run it either.
Try {
$Service = Get-WmiObject -Class Win32_Service -ComputerName $Computer -EnableAllPrivileges -ErrorAction Stop | Select Caption, State, PathName | ? {$_.PathName -like "*sqlservr.exe*" -and $_.Caption -notlike "*$*" -and $_.Caption -notlike "*#*"}
}
Catch{
write-host "WMI Connection Failed $error[0]"
}
However after the script finishes, I test these servers' WMI and it responds.
Turns out the failure is due to a Timeout. WMI querry takes too long and powershell drops it with The RPC server is unavailable. (Exception from HRESULT: 0x800706BA) Timeout expired.
Is there any way to extend the timeout period of the query?
Thank you,
Russ