For issues relating to Windows PowerShell, version 3.0.
0
votes
0answers
16 views
Poweshell remote application(.cmd) deployment
I am beginner with PowerShell and struggling to get this around with the help from different sites, My requirement and scenario is
I have a windows server 2008(rktdepy) with PowerShell installed and ...
0
votes
1answer
25 views
Powershell script works interactively, not within a script
Code works interactively, in a PS1 file it does not. to reproduce, open powershell, paste the function and then run get-job to see the task. type get-job | remove-job when done and then put code in ...
0
votes
2answers
21 views
How Do I Catch by FullyQualifiedErrorId in PowerShell?
I have a script that creates new AD Objects (via New-ADObject, as it happens). If the object already exists, I need to catch and handle that. However, the exception type isn't nearly as explicit as ...
0
votes
1answer
13 views
How Can I Silence this PowerShell Error?
I have an If statement in my script checking if an AD Object already exists. However, none of these evaluations prevent the host from printing the undesired evaluation "Directory object not found."
...
0
votes
1answer
12 views
Add column to SharePoint Online 2013 list via Powershell v3
Can anybody tell me how to do this? None of the examples I have found seem to work.
My site is https://blah.sharepoint.com/technology and my list is called 'pfa'. I want to add some text columns.
I ...
1
vote
1answer
13 views
How Can I Regex Match The Common Name of This DN?
Given the string CN=Smith\, John,OU=Users,OU=IT,DC=contoso,DC=com, I am seeking to match the complete common name, including the comma after it. I'm really trying to remove this part, so matching the ...
0
votes
1answer
20 views
Interacting with USER OU in Powershell
User is not your typical OU in Active Directory and I am trying to interact with it to pull its information down. If I run
get-adorganizationlunit -filter 'name -eq "User"'
I receive no output which ...
1
vote
1answer
36 views
A simple Try/catch doesn't working
This is my code, it's very simple:
$TargetFolder = 'M:\'
try{
$Getfolderlist = Get-ChildItem $TargetFolder -Recurse | ? { $_.PSIsContainer -and $_.Name -eq 'old' }
}catch {
Write-Host "Error ! ...
0
votes
1answer
18 views
Powershell Get-Content ReadCount maintains sequence of records?
I am using Powershell to process a text file and this is the sample code I am trying to use.
Get-Content -ReadCount 10 $FilePath | foreach {...
What am I concerned about is, will ReadCount maintain ...
0
votes
1answer
36 views
How to diagnose this exception from Invoke-Sqlcmd?
I'm running the following command (smallest reproducible example I could come up with):
Invoke-Sqlcmd "select * from sys.databases" | %{
Invoke-Sqlcmd "select 1"
}
I'm getting the ...
1
vote
1answer
35 views
Powershell - Select String - Export multiple Lines
At First: Please excuse for my bad english
I´m Searching for a String called "Please try again later" in a Textfile.
Can someone tell me, how i can export the line with the match including n lines ...
1
vote
0answers
18 views
How to add a standalone window to powershell ise
I want to create a usercontrol for Powershell ISE, I have searched how to add add-on to the right pane of the ide, is there a way to popup a standalone window when I click a button from my custom ...
0
votes
2answers
61 views
Format-Table forgets some properties, but Format-List shows them all. Why?
Given the below PowerShell 3 script, Format-Table does not list all properties as columns (it skips NoRemove), but Format-List does, and you can force the properties to be there using Select-Object.
...
2
votes
1answer
32 views
PowerShell Hashtable Sorting
I'm having an issue sorting a hashtable. I've broken down my code to just bare necessities so as not to overwhelm anyone with my original script.
Write-Host "PowerShell Version = " ...
1
vote
2answers
37 views
Powershell tasks from local machine to remote machine
I am performing below tasks on remote machine from a local machine:
Creating/Deleting/Modifying some directory
Copying some folder from local to remote machine
Installing some .exe silently with ...
0
votes
1answer
29 views
Custom Properties on PowerShell 3.0
I'm very new to power shell but what I'm I doing wrong.
Here is my script
Write-Host "PowerShell Version = " ([string]$psversiontable.psversion)
for($i=1; $i -le 3; $i++)
{
$failedObject = ...
0
votes
1answer
24 views
Why Does Get-ADObject Not Filter ObjectClass=“user” Correctly?
Problem
Get-ADObject -Filter {ObjectClass = "User"}
Returns both users and computers. The object classes display correctly as "user" or "computer".
Get-ADobject -Filter {ObjectClass = "Computer"}
...
1
vote
2answers
20 views
Powershell - Hast Table Escape Quotes
I would like to retrieve a value associated with a specific item in the hash table TEST
but its not working. Could you help me?
$TEST=
@{"Monday" = "A"; "Tuesday" = "B"; "Wednesday" = "C"; ...
0
votes
1answer
15 views
Assigning Multiple ips to a NIC using powershell
I am trying to assign multiple ips to a NIC on a windows server. Is there any way I could dynamically generate the ip addresses and assign it to the NIC
0
votes
2answers
45 views
Recursively deleting files within folders without prompting the user via Powershell
I'm currently trying to remove all the files within a folder named Local. The script below does this, but it prompts the user in a PowerShell window. If I append the -Force flag my script then ...
0
votes
1answer
17 views
Powershell V3 ConvertTo-json with embedded hashtable
I'm having a problem with ConvertTo-Json and was trying to understand the behavior and/or what I'm doing wrong.
Consider this sequence of commands:
...
0
votes
0answers
52 views
Invoke-SQLCMD doesn't release Database Connection
I'm writing a powershell script that reads the contents of sys.sysobjvalues System Base Table. This only possible with a DAC connection. The problem I'm experiencing, is that Invoke-Sqlcmd leaves the ...
3
votes
2answers
57 views
Remove a Member from a PowerShell Object?
I need to remove a member (specifically, a NoteProperty) from an object. How do I accomplish this?
0
votes
0answers
71 views
Editing Web Config File By Using PowerShell
I have this web config
<appSettings>
<add key="mykey1" value="false"/>
<add key="mykey2" value="true"/>
<add key="mykey3" value="false"/>
...
2
votes
1answer
44 views
PowerShell: select string in standard output?
PS C:\squid\sbin> .\squid.exe -v
Squid Cache: Version 2.7.STABLE8
configure options: --enable-win32-service --enable-storeio='ufs aufs null coss' --enable-default-hostsfile=none --enable
...
0
votes
1answer
122 views
Editing Web Config file using Microsoft PowerShell
i want to modify my web config file using powershell . i stuck in somewhere . i want to update appsettings and also connectionsstring information at the same time when i change them in powershel
I ...
0
votes
1answer
33 views
How to detect whether a script is dot-sourced, or loaded as part of a module using powershell v2+?
Given a ps1 file as part of a module with the following code:
function Get-Greeting {
'Hello {0}' -f $Env:Username
}
Export-ModuleMember -Function:Get-Greeting
When loaded as part of the ...
0
votes
1answer
14 views
Error redirection not working
I am trying to pipe the output of a script to a text file.
This works:
MyScript > c:\output.txt
The problem with this is that errors are not included in the output in the text file (on screen ...
0
votes
1answer
19 views
Azure Management Service API gives deployment configuration in some Encrypted format
I am using this code to get the deployment configurations.
X509Store certificateStore = new X509Store(StoreName.My, StoreLocation.LocalMachine);
certificateStore.Open(OpenFlags.ReadOnly);
...
1
vote
2answers
52 views
Getting all open PS Sessions on a remote server (from new console window)
I can start 5 new PS sessions on a remote server and see them all by running Get-PSSession
PS C:\> New-PSSession -ComputerName MyServerName
Id Name ComputerName State ...
0
votes
1answer
35 views
Copy-item Files in Folders and subfolders in the same directory structure of source server using Powershell
I am struggling really hard to get this below script worked to copy the files in folders and sub folders in the proper structure (As the source server).
Lets say, there are folders mentioned below:
...
0
votes
0answers
20 views
Powershell Scheduled task creation
I have a script that needs to schedule a task to run a .ps1 when a specific user logs in for the first time on to the machine. I have the following code:
$userid = userxyz
Copy-Item ...
0
votes
0answers
34 views
How can I read directly the output of Invoke-Method as an xml without using an intermediate file?
I have a restful service that returns this XML:(shortened)
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:atom="http://www.w3.org/2005/Atom">
<id>http://xxxxx.com/search</id>
...
1
vote
1answer
50 views
how to filter name/value pairs under a registry key by name and value in PowerShell?
I'm trying to get a feel for the idioms to use in PowerShell.
Given this script:
$path = 'hkcu:\Software\Microsoft\Windows\CurrentVersion\Extensions'
$key = Get-Item $path
$key
I get the output at ...
0
votes
0answers
28 views
Powershell 3.0 Memory Leak when loading SQL Server Trace Files
I'm stuggling with a Powershell memory leak. I'm executing a script like this one:
[System.Reflection.Assembly]::LoadWithPartialName( `
"Microsoft.SqlServer.Smo") | Out-Null;
...
3
votes
4answers
168 views
Retain first file for each date
I want to keep 5 last generated file in my directory, retaining only the first file of each date, because inside my subfolders, I have generated files multiple times in the same day.
I have multiple ...
0
votes
3answers
76 views
Delete files older than 15days using powershell
i need to delete some million files that have been created on a purge folder.I need to delete the files that have only bee created before 15 days. Im using powershell to do this. I'm pretty new to ...
0
votes
2answers
19 views
How can I specify the type of a parameter when the object type is from a web service?
I'm writing a PowerShell module. I have a Get-MyPerson function which accepts an Identity parameter, calls a web service and returns an object of type PERSON (the return type from the web service).
...
0
votes
0answers
50 views
Parse an Json Object using Newtonsoft Json and Powershell
I am accepting a json object as a command line input & then trying to parse it in Powershell 3.0.
The code is as below -
# Accept the command line json parameter
param(
[string]$json = $(throw ...
5
votes
2answers
83 views
Returning the result of a function call with/without parentheses
Why is there a difference in the return values of F and G in the following code?
Function F {
Return (New-Object Collections.Generic.LinkedList[Object])
}
Function G {
Return New-Object ...
0
votes
0answers
11 views
Powershel Get-Winevent time issue
I am having some issues with a Powershell script I have writen to collect information from the application event log and display the timegenerated Source and full error data. I am running this from a ...
1
vote
3answers
58 views
How to insert 0 in a string
this is my array :
eth1
eth12
eth5
eth11
When my string contains a number between 1 and 9 i want to add a 0 before, to obtain an array like this :
eth01
eth12
eth05
eth11
How can i achieve ...
1
vote
2answers
33 views
0
votes
1answer
41 views
How to extract number from string
my array contains string like this :
eth1
eth12
eth20
eth35
eth5
I want another array who contains only the number of these string :
1
12
20
35
5
I tried with Trimend() function, but i don't ...
0
votes
1answer
47 views
How can I have threadsafe instance variables within Inlinescript block when using Powershell workflows?
I'm using PowerShell 3 and playing with Workflows and I have run across something curious.
I am using an inlinescript block hold some code to represent a task that I want to run many instances of. ...
0
votes
2answers
47 views
Empty value powershell array
i have a strange issue, this is my csv
Serveur;Carte;Cordon;IP;Mac;Vmnic ;Vmnic mac;Connect;Port
Dexter;eth1;405;172.16.5.117;00:24:e8:36:36:df;Vmnic0;00:50:56:56:36:df;sw-front-1;A1
...
0
votes
1answer
26 views
How to have both write -host and html
I have written a code snippet and I have incorporated write host in it i want both write host and convert html to run for this snippet can any one help me with that.
$arrComputers = get-Content ...
1
vote
2answers
21 views
Powershell outputs Directory paths differently sometimes
I'm using ls to find directories by convention. It works in that it finds them, but I'm piping the results to other functions. Depending on the way 'ls' (aka: dir) is called. Why is this happening? ...
0
votes
1answer
61 views
How to store data from foreach function in HTML file in powershell and get Physicall ram
I have written a for each file which stores the BIOS information of the systems in a network and the result is being displayed on my console but I want them to be in a HTML file in an order.
Code:
...
1
vote
0answers
84 views
Configuring IIS using Powershell results in Error: There is a duplicate 'system.web.extensions/scripting/scriptResourceHandler' section defined
We are automating our IIS server build and configuration using Powershell on Windows Server 2012 / IIS8.
The scripts create websites, application pools, set permissions, bind certificates etc. The ...