Quantcast
Channel: /r/powershell – How to Code .NET
Viewing all 8793 articles
Browse latest View live

Need a script for locating an account number within an excel file.

$
0
0

I am new to PowerShell and coding for that matter. I’ve been through a bunch of YouTube videos and have a sense of what I need to do I just don’t know how to do it. Here’s the run down I have a spreadsheet where I find an account number under an “identifier” and then I have to find that account number buried in the files on my desktop in an excel spreadsheet. This takes a lot of time. Does anyone have any resources to help? Anywhere for me to start figuring out how to accomplish what I’m trying to accomplish? If I can figure out how to enter the account number and have it loop through all the directories to find the right excel file my project would take a couple hours versus a week. I’m also very interested in this stuff and want to learn how to do it. Thanks for you any direction

submitted by /u/banana8906
[link] [comments]

The post Need a script for locating an account number within an excel file. appeared first on How to Code .NET.


File Creation Notification

$
0
0

Hi All!! I don’t have much experience with scripting or using the powershell although I do have experience coding. I need something running in the background of either windows 10 or 7 that monitors when a file is put into a particular directory and either opens the file, creates a notification, or something to that effect. I would imagine this is a simple task but my lack of knowledge on the subject is weighing me down drastically and I would appreciate any assistance on the subject. I believe that the best chances I have will be creating a script or using filesystemwatcher. Please link me to any guides or share your own experiences.

Thank you!

submitted by /u/jerfmuffay
[link] [comments]

The post File Creation Notification appeared first on How to Code .NET.

New to Powershell, hoping for some help with a script

$
0
0

I am working on a script that would search AD by Computername and move the results of that search to a partuicular OU. The organization I work for has common naming conventions for computers that should correlate to the AD groups they are in. Just learning powershell and wanted to get some feedback on what I have done so far. This is the first script I have worked on and any feedback is appreciated.

This is the script:

$Name=”Computer Name”

$TargetOU=”OU Path”

$NamedGroup= Get-ADComputer filter | Where-Object {Name -like “$name*”}

$NamedGroup | ForEach-Object Move-ADObject-TargetPath $TargetOU

submitted by /u/ihatedebate
[link] [comments]

The post New to Powershell, hoping for some help with a script appeared first on How to Code .NET.

Favorite Modules

$
0
0

Over the years I have gathered a collection of modules. Here are some of my favorites:

  • dbachecks – SQL Server Infrastructure Tests
  • dbatools – automate database development and server administration
  • ImportExcel – import/export Excel spreadsheets, without Excel
  • NTFSSecurity – manage file and folder security on NTFS volumes
  • Pansies – handling color and cursor positioning via ANSI escape sequences
  • PoshRSJob – use runspaces to create jobs that allow throttling and quicker execution of commands
  • PowerLine – richer output and prompts
  • PSEverything – Powershell access to Everything for fast file system searches
  • PSLogging – creates and manages log files for your scripts
  • PSWindowsUpdate – Windows Update Client
  • SNMP – manage systems using SNMP
  • SqlServer – automate database development and server administration
  • Universal Dashboard – cross-platform module for developing websites and REST APIs
  • VMware.PowerCLI – manage Vmware environments
  • Z – quickly navigate the file system based on your cd command history

I know there are definitely some gems I am missing or I should switch from one to another.
What are some of your favorite modules? Did you write one you like to share? Do you know a nicely curated list of awesome ones?

submitted by /u/kortex81
[link] [comments]

The post Favorite Modules appeared first on How to Code .NET.

Get-SMBMapping on remote computer

$
0
0

I have connected to a remote computer using

 Enter-PSSession -ComputerName COMP-L005 

It connects me without any issues and then I run

Get-SMBmapping 

I know the user has mapped drives connected but I dont see anything in the output

The server i am connecting from is Windows Server 2013 R2 and the client is Windows 10 Pro

submitted by /u/AussieTechGuy
[link] [comments]

The post Get-SMBMapping on remote computer appeared first on How to Code .NET.

Questions about using powershell for automating PC repair

$
0
0

So currently, I work to repair a large volume of computers on a daily basis and I would like to start automating some of that work with scripts. I’m having a hard time finding any resources online with help on what I am trying to accomplish. For example, lots of computers I work on require a winsock reset to get their adapters functioning again. Normally, I would have to go through device manager, identify and uninstall the network adapter, run the command and restart the system. I know it’s a pretty simple task, but it would make life a lot easier for some of the guys I work with. This is just one example of what I’m trying to automate. Are tasks such as this even possible using scripts? If not, is there an alternative? I will admit that I know next to nothing about powershell scripting. I do however have some basic knowledge of Java, PHP, and C++, but it’s been a while.

submitted by /u/jcspears2014
[link] [comments]

The post Questions about using powershell for automating PC repair appeared first on How to Code .NET.

RegEx and Windows Form

$
0
0

Hello, I’m trying to do validation on a text box. The problem I’m running into is individually typing in the characters VS copy and paste. Copy and paste seems to work just fine, but I get errors when typing individually.

if ($textbox.Text.Trim() -match '[Pp]{1}[Cc]{1}d{6}$|[Ss]{1}[Vv]{1}d{5}$') { $textbox2.Text = "Finding PC" #Find-Computer } else { $wshell = New-Object -ComObject Wscript.Shell $wshell.Popup("Please type in correct Asset Number", 0, "Notification") } 

submitted by /u/WindowsUser127
[link] [comments]

The post RegEx and Windows Form appeared first on How to Code .NET.

Suppressing the “Suggestion” output when a binary happens to be in your current directory but not in $env:Path?

$
0
0

So I have nuget.exe located C:Userszeroadminnuget.exe, and my current directory is C:Userszeroadmin, but C:Userszeroadmin is NOT part of $env:Path, then I do:

PS C:Userspddomain> Get-Command nuget *>null.txt Suggestion [3,General]: The command nuget was not found, but does exist in the current location. Windows PowerShell does not load commands from the current location by default. If you trust this command, instead type: ".nuget". See "get-help about_Command_Precedence" for more details. 

How do I suppress the ‘Suggestion’ output? I tried redirecting all streams to a file but…it’s not a stream? :/

submitted by /u/fourierswager
[link] [comments]

The post Suppressing the “Suggestion” output when a binary happens to be in your current directory but not in $env:Path? appeared first on How to Code .NET.


Is scripting with PS-Exec possible?

$
0
0

I currently have to manually remove and install registry keys using psexec. I was wondering if it was possible to automate this at all. I have to use psexec to remotely run an installer.

EDIT: To clarify, I have to do this on multiple computer ids which is why I’m wondering if I can make a script. I’m wondering if I can put a variable in the psexec command identifying dynamically the computer’s id. EXAMPLE: PC1034, PC1035, PC1036, etc.

submitted by /u/bitcolor
[link] [comments]

The post Is scripting with PS-Exec possible? appeared first on How to Code .NET.

Enumerate variables inside Switch

$
0
0

I have an hastable of variables and I am using a Switch statement to work on their values. If a value is $null, I want to know which item in the hashtable, it is. What am I missing here?

[hashtable]$variables = @{InstallPath = $a; ADQueryIntValue = $b} Switch ($variables) { {$_.Value -eq $null} { Write-Host ("{0}: The variable {1} was null. Please re-run the script and provide a value for the variable." -f (Get-Date -Format s), $_.Name) } } 

Thanks.

submitted by /u/wetling
[link] [comments]

The post Enumerate variables inside Switch appeared first on How to Code .NET.

I’m Trying so hard and failing at powershell.

$
0
0

I’ll be honest. I’ve tried to avoid Powershell in the past. at my old company it was just 45 people, I was sole I.T. and we were on 365 but basically a completely vanilla setup.

New job. 450 people. JUST deploying 365.

Discovered mid migration (doing only a couple of people a day) that we HAD to migrate boardrooms. I had no time to prep and I’m frantically trying to sort out permissions and management can’t seem to make up their mind about what they actually want.

Since I have to figure everything out as I go along, its taking me ages.

I’m trying to Loop a command through a table of results, and I just can’t get it to work.

Can someone sanity check this for me?

$rooms = Get-Mailbox -RecipientTypeDetails RoomMailbox

$rooms | ft

$rooms | %{Add-MailboxPermission -AccessRights FullAccess -Identity $_ -User Resource_Calendar_Delegate_access}

It returns with this error:

A positional Parameter cannot be found that accepts argument ‘<boardroomname>’. InvalidArgument: (:) [Add-MailboxPermission] ParameterBindingException

Ive been staring at powersheel screens since 8am this morning and My brain is so fried and this has to be running by tomorrow. I’m at a total loss.

submitted by /u/sudz3
[link] [comments]

The post I’m Trying so hard and failing at powershell. appeared first on How to Code .NET.

Fun with AD

Can you help? Checking links within files

$
0
0

hallo leute,
I’m running at a loss to think of a way to do the following

Declare a folder

Have an automated “thing” run through all files(microsoft office files) within document and check hyperlinks within documents

Then output list of links that contain “\abc

The story goes along the lines of a DFS migration with users refusing to have anything moved due to a domain change.

This will break links and I’m told is completely unnessecary.

My body is ready for the Karma downvote train.

danke

submitted by /u/excelbeginnerDE
[link] [comments]

The post Can you help? Checking links within files appeared first on How to Code .NET.

Powershell copy file to multiple locations

$
0
0

Ok say if i had mutiple folders accross multiple servers.

The folder names are all FILESXXX – where the XXX’s are individual numbers and none are the same.

In order to copy a file to each of the 20 servers each with their own FILESXXX directories how would i achieve this in powershell

Seem to be able to do a server list and file list but the actual destination path doesn’t seem to take wildcards

Just need a way to copy one file to multiple FILESXXX directories on multiple servers

submitted by /u/electrical23456
[link] [comments]

The post Powershell copy file to multiple locations appeared first on How to Code .NET.

Generate CSV file from SQL using Encryption

$
0
0

Hi,

I have been trying to generate a CSV FILE using SQL SERVER 2014. I am unable to resolve the errors below…

The PowerShell code has been posted in pastebin

https://pastebin.com/embed_js/VyJQZ01a

I am encrypting the password using the code and saving the outcome of the encrypted password in SQLConfig.xml file

SQLConfig.xml $password = read-host -prompt “Enter your Password” $secure = ConvertTo-SecureString $password -force -asPlainText $bytes = ConvertFrom-SecureString $secure $bytes

ERROR New-Object : Exception calling “.ctor” with “2” argument(s): “password must be marked as read only.”

At D:SQLData2CSVBUILDINGFINAL CODE WIP.ps1:70 char:24

  • … $sqlCred = New-Object System.Data.SqlClient.SqlCredential($sUserName …

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvocationException

+ FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand

Exception calling “Fill” with “1” argument(s): “Login failed for user ”.”

At D:SQLData2CSVBUILDINGFINAL CODE WIP.ps1:84 char:13

+ $SqlAdapter.Fill($DataSet);

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~

+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException

+ FullyQualifiedErrorId : SqlException

Export-Csv : Cannot bind argument to parameter ‘InputObject’ because it is null.

At D:SQLData2CSVBUILDINGFINAL CODE WIP.ps1:87 char:29

  • … $DataSetTable | Export-Csv -NoTypeInformation $CSVFileName

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ CategoryInfo : InvalidData: (:) [Export-Csv], ParameterBindingValidationException

+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ExportCsvCommand

Any help in resolving the error would be really helpful

submitted by /u/nottyheadedboss
[link] [comments]

The post Generate CSV file from SQL using Encryption appeared first on How to Code .NET.


Wondering why TsProfilePath not working in Powershell

$
0
0

Can someone please help me? I have a fully functional script that creates a new user and fill all important information into AD. It chooses the OUPath on user, check whether the user ID already exist, i have variables and parameters, it can copy member-off details to the new user, create folders, assign rights on folders and enable a mailbox. I have put a lot time in it and the last thing I need to figure out is th TSProfilePath. I have tested a lot of attributes but none of them are working as because they don’t exist. Who can help me? I really need this to finish my script so that HR can use this. We at the SD have a lot of work to do. When this only attirubte is resolved into my script than HR can use it … /u/MrEpiX/

submitted by /u/WhatTheHomePod
[link] [comments]

The post Wondering why TsProfilePath not working in Powershell appeared first on How to Code .NET.

Using hashtable for param validation

$
0
0

Say for example I have a hashable

$hash1 = @{'thing1','thing2','thing3'}

and I have a parameter that Id like to take an int or string, say 2 and return the second entry of that hashtable – how would I go about doing that?

For context, Im writing a function to generate lab vm’s in hyper v. This parameter will determine which ISO will be inserted via Set-VMDvdDrive on the -Path parameter.

submitted by /u/toe-fu
[link] [comments]

The post Using hashtable for param validation appeared first on How to Code .NET.

Getting error when trying to set access rule

$
0
0

$san=’jsmith’

$Acl = Get-Acl “\rrs-dc1users$san”

$permission = $san,’Modify’, ‘ContainerInherit,ObjectInherit’, ‘None’, ‘Allow’

$Ar = New-Object System.Security.AccessControl.FileSystemAccessRule $permission

$Acl.SetAccessRule($Ar)

Set-Acl “\rrs-dc1users$san” $Acl

This script works if I run it by itself, which is so annoying. However, I have this at the end of a long user creation script. And it’s not working. Any ideas? I can run $san and get jsmith right before this.

submitted by /u/lakerskill
[link] [comments]

The post Getting error when trying to set access rule appeared first on How to Code .NET.

Trying to display EventLong errors for system and applicaiton

$
0
0

I’m making a script that searches between dates and shows the errors for system and application. So far my script works to show the errors for system OR application. I’m not sure what cmdlet will let me combine the system and application into one table. I was trying to tinker with foreach-object but it I coulndn’t get it to do anything.

Param ([datetime]$starttime, [datetime]$endtime)
cls
Get-EventLog System -EntryType Error |
Where-Object {$.TimeGenerated -ge (“$starttime”) -and
$
.TimeGenerated -lt (“$endtime”)}

submitted by /u/SomeCallMeDonnie
[link] [comments]

The post Trying to display EventLong errors for system and applicaiton appeared first on How to Code .NET.

How to test scripts?

$
0
0

Hey guys I am trying to test this script out:

$computers = Get-ADComputer -Filter * -Searchbase "OU=Laptops,OU=Computers,OU=Company,DC=domain,DC=com" $list = Foreach ($laptop in $computers) { Get-ADObject -Filter {objectclass -eq "msFVE-RecoveryInformation"} -Searchbase $laptop.DistinguisedName -Properties msFVE-RecoveryPassword } $list | export-csv "Bitlocker_Recovery.csv" 

Basically what I want to do is grab all the computer objects in that specfic OU and display their Bitlocker Recovery information. I want to know the correct procedure to test this script out rather than just releasing it into Production. This is my first script and I was using this as a guide https://ndswanson.wordpress.com/2014/10/20/get-bitlocker-recovery-from-active-directory-with-powershell/.

submitted by /u/chen1201
[link] [comments]

The post How to test scripts? appeared first on How to Code .NET.

Viewing all 8793 articles
Browse latest View live