Questions tagged [powershell]

19204 questions
1

votes
2

answer
2.7k

Views

Powershell get laptop brand

Is there a way to get a laptops brand like acer, hp, samsung via powershell? I looked at get-wmiobject to no avail. I know this is probably a long shot. Any help would be appreciated!
user2526047
1

votes
1

answer
2.5k

Views

Unable to index into an array to turn it into a hash table

I am trying to convert an array into a hashtable but I keep getting this error Unable to index into an object of type System.Management.Automation.PSObject. I have searched everywhere and could not find others having the same problem. My code: [array]$compArray = $ds3 | select -Property DeviceName,...
JasonBluefire
1

votes
2

answer
11.2k

Views

Create a process using Plink in PowerShell and sending commands to it

I need to be able to create a process on a remote device and send come commands to it using a PowerShell script. I need to do it this way because I get prompts when I use a command. I have been trying to figure out how to do this by using Google searches and the following link: http://tartarus.org/~...
Programmer_D
1

votes
1

answer
1.4k

Views

Hyper-V 2012 R2 WMI error in Msvm_ResourceAllocationSettingData class property conenction

In Hyper-V 2008 R2 and Hyper-V 2012 I used the following code to find the VM name associated with the VHD files. It worked fine Function strGetVMname(strVHD) Set VMList = objWMIService.ExecQuery("SELECT * FROM Msvm_ComputerSystem Where Caption='Virtual Machine'") For Each VirtualMachine in VMList Se...
Kanvas
1

votes
5

answer
39.2k

Views

Import Excel data into PowerShell variables

I have an Excel File which has an unknown number of records in it, and these 3 columns: Variable Name, Store Number, Email Address I use this in QlikView to import data for certain stores and then create a separate report for each store in the list. I then need to email each report to each individua...
user2725402
1

votes
1

answer
1.6k

Views

List All Text Files in a Directory with more than 100 Lines using PowerShell

Hello I'm PowerShell beginner. I'm looking for a script which finds and list all text files in a directory (*.TXT) with more than 100 lines. This code show max and min number of lines in a directory but doesn't list files with min or max number of lines. dir . -filter "*.txt" -Recurse -name | foreac...
john
0

votes
1

answer
21

Views

How to call power shell script file by passing attributes in c#

How to call power shell script file by passing attributes in c#. I'm using below code to call ps1 file by passing inputs but getting error near invoke. error message: System.Management.Automation.CommandNotFoundException: 'The term 'Get-Childitem C:\Anand\samplemm.ps1' is not recognized as the name...
Jack
0

votes
0

answer
7

Views

Remote printer discovery via Windows API

In a Windows network where each computer runs an SCCM client, is there any way of discovering and listing the Printer objects available to one machine, via an API call from another? Can this be done via SCCM, Powershell, or any REST library?
PNS
1

votes
1

answer
12

Views

How to make powershell emit an error on undeclared command line arguments

Given the following script.ps1 Param([switch]$Foo) Write-Output $Foo How can I make it error on undeclared arguments, such as script.ps1 -Bar? I can write my own code to do it by interpreting $args, but it seems like powershell should be able to do it for me, as it already parses the arguments.
cdmihai
1

votes
1

answer
2.8k

Views

Using PowerShell to find the differences in strings

So I'm playing around with Compare-Object, and it works fine for comparing files. But what about just strings? Is there a way to find the difference between strings? CompareTo() is good about reporting that there is a difference, but not what the difference is. For example: PS:> $a = "PowerShell roc...
James Brown
1

votes
1

answer
5.2k

Views

Possible to combine .csv where-object filters?

I'm trying to filter a .csv file based on a location column. The column has various location entries and I only need information from the rows that contain certain locations, that information then gets exported out to a separate .csv file. I can get it to work by searching the .csv file multiple t...
tlock
0

votes
0

answer
4

Views

IBM UCD - Download Artifacts - Directory Offset

I am using IBM UCD for deploy. while configuring the directory offset of the download artifacts, which is one of the steps under processes. However, I am having a hard time in changing the path to another drive. For example , if my working directory is C:/program files/agents/workspace/dir1 If I pu...
Ray Z
2

votes
0

answer
18

Views

Powershell: How to find out which running services aren't part of OS and non-MS

Is there a way to find out using Powershell which running services are non-native to Windows ? In other words, services that aren't part Windows OS and are non-Microsoft. I want to find out all the services that were installed by our vendors. Finding out running services is easy: Get-Service | Where...
newprint
1

votes
1

answer
250

Views

How to create a new Azure Website with integration to private Github repo using the Azure REST API?

There are many trivial examples that show how this is done without the Github integration. The Azure Powershell commandlet New-AzureWebsite supports only public repos (can be confirmed from source code [1]). Has anyone tried to create it with a connection to a private repo? It doesn't seem to be doc...
Kyberias
1

votes
2

answer
1.4k

Views

Powershell get-childitem needs a lot of memory

My question is pretty much the same as the one posted on metafilter. I need to use a PowerShell script to scan through a large amount of files. The issue is that it seems that the "Get-ChildItem" function insists on shoving the whole folder and file structure in memory. Since the drive has over a mi...
greenhoorn
1

votes
1

answer
10.6k

Views

Close a file handle opened by .NET

I'm working on a script to rename files based on EXIF data. param([string]$path) # http://blogs.technet.com/b/jamesone/archive/2007/07/13/exploring-photographic-exif-data-using-powershell-of-course.aspx [reflection.assembly]::loadfile( "C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dl...
Gerald Schneider
1

votes
1

answer
1.6k

Views

Invoke-RestMethod isn't passing headers

Got a really bizarre problem with Invoke-RestMethod. I'm using it send a GET and include a cookie in the request: $getEndpoint = "http://YYYYYYYYYYYYYY/clients/XXXXXX/dev" $authheader = "auth_tkt=\""XXX""" Invoke-RestMethod -Headers @{"cookie" = "$authheader"} -Uri $getEndpoint If I look at the req...
jamiet
1

votes
2

answer
7.4k

Views

Get-ADUser -Filter fails when comparing to an object's property

I have a powershell question that has to do with importing a csv file, then going through a foreach through the csv file. I have something like the following: $infile = "c:\temp\infile.csv" $outfile = "c:\temp\outfile.csv" $csv = Import-csv -path $infile foreach ($line in $csv) { $data = Get-ADUse...
mart2001
1

votes
1

answer
1k

Views

Iterate Generic List of Strings (Lync chatroom members) in Powershell

I can't iterate through a Generic List of Strings in Powershell. The Object is the members of a Lync chatroom. Command to get the Generic List: $crMembers = get-csPersistentChatroom -identity "XXXX" | select members The error I receive when trying to read the Strings in the Generic List is: WARNING:...
Plarsen
0

votes
2

answer
22

Views

Export Folder Permissions

I want to Export folder Permissions for a subset of folders. Each Folder in 'Department' has two child's, 'Public' and 'Internal". For example, I want the permissions of the folder 'D:\Data\Department\Science\Public' or 'D:\Data\Department\Sales\Public'. $FolderPath = dir -Directory -Path "D:\Data\...
Ralf W
0

votes
3

answer
28

Views

When I copy a user in Active Directory it doesn't copy the street address

So I'm trying to use PowerShell and a CSV file to populate users street address as well as city, state, zip, etc (in case they move to a new office location their street, city, state, zip will be updated appropriately). Obviously, my OUs are structured by location. My CSV file has 5 columns (Stree...
Jas
1

votes
2

answer
1.7k

Views

Powershell Copy files and folders

I have a PS script which Zips up the previous months logs and names the zip file FILENAME-YYYY-MM.zip This works What I now want to do is copy these zip files off to a network share but keeping some of the folder structure. I currently a folder structure similar to the following; C:\Folder1\ C:\Fol...
Wiggum123
1

votes
1

answer
9.4k

Views

Cannot bind argument to parameter “FilePath” because it is null

Every time I run the script below I get Cannot bind argument to parameter 'FilePath' because it is null. It was working last night. No changes have been made and this morning it just fails. the funny thing is if i save the script and then run it, it works. However if I clear console then run it agai...
Norrin Rad
1

votes
1

answer
627

Views

How to make PSCmdlet bool parameter to work like a flag?

Using System.Management.Automation you can create custom PSCmdlets in C#. Now if you create boolean parameter like this: [Parameter()] public bool ShowDefinition { get; set; } You have to invoke cmdlet like this: PS> Get-CustomValues -ShowDefinition 1 But I would like to invoke it without passing va...
mswietlicki
1

votes
2

answer
2.3k

Views

How do I implement a filter in PowerShell?

I'm trying to figure out a way to incorporate a filter into a custom function and I haven't been able to get it working: Function Test-Me{ Param ( $Filter = "Number -like ""Three""" ) $Obj = New-Object PSObject -Properties &{ Number = "One","Two","Three" } If($Filter){ $Obj | Where-Object $Filter }e...
Colyn1337
1

votes
1

answer
2.5k

Views

How to find and replace within a large binary file with PowerShell?

I have binary files larger than 50 GB, which contain a specific string I want to replace with equal length all-spaces string. The string I am looking for is in the beginning of file, say within the first megabyte. How can I do this with PowerShell? I am afraid [System.IO.File]::ReadAllBytes("myfile....
Travenin
1

votes
1

answer
3.6k

Views

How to start and stop processes in PowerShell?

This should work fine in PowerShell older than 3. I need to run two processes: wuapp.exe and desk.cpl with ScreenSaver's tab. The problem I have is that once I start wuapp.exe the process name shows up in Task Manager as explorer.exe - the current code works for wuapp.exe but not on every machine. T...
ppiotrek
0

votes
0

answer
7

Views

Access VBA7 and Win64 Conditional Compiler constant through Powershell

I have software that can run either a VBS or Powershell script on a targeted endpoint (these are the only options). I want to use this software to determine whether the version of MS Office that is installed is x64 or x86. There are registry keys that can be an indicator but in testing they have not...
Landon Tholen
1

votes
2

answer
569

Views

calling rmdir node_modules /S /Q from powershell

Is it possible to call: rmdir node_modules /S /Q From powershell. I get the dreaded path too long error with certain folders in powershell. Using rmdir would get round this.
dagda1
1

votes
1

answer
692

Views

FQDN with SmtpClient in Powershell

I am using the .Net class System.Net.Mail.SmtpClient in Powershell to send a mail with some attached documents. It all works great in our test environment, but fails in production. The problem is, that a fully specified domain name is required in production to send the mails. However the SmtpClient...
G_hi3
11

votes
1

answer
123

Views

Generate data seeding script using PowerShell and SSMS

Here I found a solution for the manual creation of the data seeding script. The manual solution allows me to select for which tables I want to generate the inserts I would like to know if there is an option to run the same process via PowerShell? So far I have managed how to create a SQL script whic...
GoldenAge
1

votes
3

answer
7.6k

Views

Powershell Subtract 1 day from variable date

How can I use a variable containing a date to act like get-date function in powershell? I have a variable $date containing 2016-09-08. I want to subtract one day from the $date. something like: $date = "2016-09-08" $date.AddDays(-1) It doesn't work.
Joey
1

votes
1

answer
8.7k

Views

Can I use TLS with Send-MailMessage cmdlet?

I am trying to send an email using PowerShell, but need to use TLS. Any way I can do that using Send-MailMessage cmdlet? This is my code: $file = "c:\Mail-content.txt" if (test-path $file) { $from = "[email protected]" $to = "","" $pc = get-content env:computername $subject = "Test message " + $p...
Sergio Calderon
1

votes
1

answer
123

Views

Azure Get-AzureRmMlService not found Powershell

How do I get the azure web service from powershell? I am following the docs here, which says I need to call the Get-AzureRmMlWebService cmdlet. But when I follow the command line in the doc and run Get-AzureRmMlWebService, it says the term is not recognized. Any body knows how to solve the issue? I...
Psidom
1

votes
1

answer
4.1k

Views

How do I get the Update History from Windows Update in PowerShell?

Can someone give me an example of how to get the Update History from Windows Update in PowerShell? I found the API documentation here: https://msdn.microsoft.com/en-us/library/windows/desktop/bb394842(v=vs.85).aspx But, there is very little on how to call it from PowerShell.
TravisEz13
1

votes
2

answer
934

Views

Prevent bypassing powershell execution policy

We have Powershell installed on our RDS environment. It's currently being used for tasks like remote management and App-V virtual application publishing. To my understanding it's fairly easy to bypass a restricted execution policy. I can't however find any useful information on preventing bypassing...
John Dane
1

votes
2

answer
10.7k

Views

use PowerShell to search for string in registry keys and values

I'd like to use PowerShell to find all registry keys and values within a particular hive that contain a string foo, possibly embedded within a longer string. Finding the keys is not hard: get-childitem -path hkcu:\ -recurse -ErrorAction SilentlyContinue | Where-Object {$_.Name -like "*foo*"} The pro...
Alan
1

votes
2

answer
7.7k

Views

how to run a powershell script as a windows service from inside a Java program?

I have the following code that runs a windows service from inside Java.The code uses JInterop Java library, JInterop is a pure Java COM client for windows COM server. More details of JIntop are available here [http://fishi.devtail.io/weblog/2015/01/21/pure-java-dcom-bridge-j-interop/] String cmdFile...
Manjur
1

votes
4

answer
778

Views

Detect if process executes inside a Windows Container

It's simple. I would like to detect with code if my process is running inside a windows container. There are examples but they are all for linux based containers. I'm looking for something unique and explicit to docker that can be used to make a safe conclusion whether a process is executing inside...
Alex Sarafian
1

votes
1

answer
6.4k

Views

Change wallpaper powershell

Hello i'm trying to make a little script to change my wallpaper every given time i have a folder in which the pictures are name 1.bmp , 2.bmp etc i made this script but it doesn't work at all PS D:\Téléchargements\images\Wallpapers> for($i=1; $i -le 6; $i++){ >> reg add "HKEY_CURRENT_USER\Contro...
Edo Youss

View additional questions