Quantcast
Viewing all 15370 articles
Browse latest View live

PowerShell ISE vs PowerShell behaviors

Hello Community!

I have an odd (for me) behavior in a PowerShell script I've been working on to create new user accounts. We have created a CSV sheet that captures all the pertinent user data we require. The CSV file then has a secondary sheet that truncates, concatenates, and otherwise manipulates the data for the script to actually create the user account.

We have an identified requirement to protect these formulated columns from alteration or accidental deletion. To that end, we have copied the formulated cells down to row 100 even though it is highly unlikely that we'd ever reach this number in a single run. As the CSV is populated, the secondary sheet will be filled in accordingly. But this also leaves rows of data with empty formula values.

This seems to be the issue between ISE and standard PowerShell running the script and looking...


Putting A .csv File Into Two Different Arrays And Than Generating A Result

Hey everyone!

I'm currently working on a project in Powershell for work where I have a .csv file that I need to import into Powershell, and than compare two rows of columns in the .csv file and if the comparison comes out false, I have to output "No Relation" or if it is, I have to output "Relation".

For example, the project we're doing is currently trying to organize our media collection, so we put all the titles in a .csv file, and I have to compare if there's at least one match between "Genre" and "Company", so if I input "Romance" and "Sony", Powershell would generate "No Relation", because there's no relation in the .csv file between "Sony" and "Romance" but if I put "Action" and "Sony", Powershell would generate "Relation" because there is at least one match.

What I currently have is -

$Genre = Import-csv CompanyMovies |...

PowerShell 7 Preview 6 has shipped - Why Does This Matter?

So in a great article here, superstarTimb0slice pointed out the latest preview release of the upcoming PowerShell 7 open source product. But why does this matter? Why should YOU spend time reading about it and exploring more?

The reasons are simple (well I think they are simple). First, PowerShell 7 IS the future of PowerShell. Microsoft's Windows PowerShell is feature complete - supported but with no new features added. The intention is that going forward, IT Pros migrate to PowerShell 7 and I understand there are options for including it in the box with future feature releases of Windows 10 and Windows Server. Plus, there are a LOT of new features that any serious PowerShell user is just going to love.

For example - the cmdlet Test-NetConnection is an awesome replacement to Ping.Exe as it assesses the ability to connect to a specific...

Reading different data sets from single SCV file..

Hi,

In the screen shot, there are 2 sets of data, 1 for Windows and 1 for VMware.

What I want to do is to run a script that will only read the Windows Start to Windows End part of the data, and a second script that only read VMware part of the data.

I could not find a way to do this, is it even possible.

Thank You

Image may be NSFW.
Clik here to view.

Connect to Graph API Powershell

Came across these Graph API PowerShell examples for controlling Intune and wanted to share:

https://github.com/microsoftgraph/powershell-intune-samples/blob/master/Applications/Application_And...

The one application that I used was to load up Intune with a list of Android Applications with Icons for the Company Portal NOT using Google Managed Play.

The part that was pretty sweet was the connection bit davefalkus put together that just asks for the Global Admin and then creates all the API and JSON for you. Hitting Accept after the MFA login screen allows the correct access permissions.

Good luck and happy computing!

Using a form button to call another form?

I'm using a function to create buttons, the process looks like this:

Powershell
Process{$Button=New-ObjectSystem.Windows.Forms.Button-Property@{Location=New-ObjectSystem.Drawing.Point($X_Position,($Y_Position+$Order*$Y_Height))Size=New-ObjectSystem.Drawing.Size($X_Size,$Y_Size)Name=$NameText=$TextDialogResult=[System.Windows.Forms.DialogResult]::$DialogResult}$Form.AcceptButton=$Button$Form.Controls.Add($Button)}}

I'm trying to use this function to create a button which opens another form window. I've got a proof of concept using this:

Powershell
#Calls the required modules for the scriptAdd-Type-AssemblySystem.Windows.FormsAdd-Type-AssemblySystem.Drawing#Form Details$Form = New-Object System.Windows.Forms.Form -Property @{  Text = 'form' ...

PowerShell: File vs. Console Output

I need your help fam. I am building a PowerShell script pulling some SHA1 hashes from an API into a variable.

Powershell
$hashes=Invoke-WebRequest-Uri"https://api.org.com"|select-ExpandPropertycontent

The output format from the API looks like this...

{partial hash value}:{how many times the hash appears is in the list}

Text
FF2CB655CE08DB53D721D10DC1EBE159D1E:2 FF457ED69101D5FA9657D0AC888BFF1632E:1 FF535E8286A9D9394E33ED388B20F73A794:4 FFCDFF228BE98F296C0CA4CE1FC8815A30E:5 

I need to split the string on either side of the colon. This is where I get lost. I use the cmdlet below to split the line using the colon as a delimiter

Powershell
foreach($hashin$hashes){$hash|ConvertFrom-String-Delimiter":"-PropertyNamesHash,Occurrence}

If I take the output from the API query putting it directly into a variable and then...

How to know who are login/using to powershell command Office365

Hi Guys,

Previously I received report from customer about they need to know who are used Office365 by powershell and how to know someone login with admin credential in powershell.

I search on Mcrosoft document or some website but nothing there.
Thanks.

Auto CompressArchive by date?

Hello guys. I'm a newbie... , so maybe somebody can help me with one 'simple' script.

So.. I have a folder eg: 

C:\logs\xxx , in this folder 'xxx' i have many subfolders , eg: x1, x2, x3, etc .. , in this subfolders have many files. Some from 2016, 2017, 2018, 2019 , etc. I need to archive files from subfolder (x1,x2,x3...) by date, all files with date 2018 from folder x1 per example arhive in folder x1 > x1_2018.zip . Files with date 2019 arhive x1_2019. ((( eg: (Files from x2 > x2_2018, x2_2019,,, etc ))). 

Thank's in advance.

Automating Logins from Windows Login Screen?

Hi,

I have been searching and cannot find a way to do this so I am guessing it is considered a vulnerability and not possible...

Background:

So when we have exams running we (The IT Team) have to manually go to the suite and manually log each Computer into an Exam account and ensure its ready for the exam. Due to the nature of the accounts, lots of things are locked down and automated by GPO such as spell check and internet being disabled and Documents and logins are tracked and backed up to network locations for each account.So this would be us logging in around 40 machines, manually typing username and passwords and pressing enter each time.

This is boring and tedious :(

Question:

So I was just trying to find a way of just scripting the login. I thought the theory is simple, a list of PC-Names in a CSV and a List of Username&Passwords in a...

Get list of mapped drives

I'm trying to get a list of mapped drives on some computers, as I suspect a couple of users have drives mapped that are not part of a group policy.

This works great, but only on my computer, 50% of the time.

Powershell
$computer=Read-Host'Enter computer name'$GWO_MappedDrives=get-wmiobject-Classwin32_mappedlogicaldisk-ComputerName'$computer'$MappedDrives=foreach($GWOMD_Itemin$GWO_MappedDrives){[PSCustomObject]@{DriveLetter=$GWOMD_Item.NamePath=$GWOMD_Item.ProviderName}}$MappedDrives

Image may be NSFW.
Clik here to view.

If I do 'localhost' all mapped drives are listed. If I do the name of my PC, only 4 drives are listed, Sometimes I get 'The RPC Server is unavailable', sometimes I don't. Sometimes I don't even get a result, it's just blank.

Image may be NSFW.
Clik here to view.

I tried this, which only gives me the 4 drives I would get with the other script, although they appear to...

please help to get window update from powershell, I get no reply from powershell

Hi There,

I have tried following cammand to window update history. but no reply. I installed this month security patches but not able to get form powershell. please help me,how i can get it from powershell. why command are not working ?

1.wmic qfe list
2. Get-hotfix
3.Wmic get-wmiobject -class win32_quickfixengineering
none of them worked.

I dont know the issue with this VM.


Image may be NSFW.
Clik here to view.

Read-Host not working in remote PS Session

I have a Powershell script which contains a Read-Host cmdlet, something simple like:

Powershell
$name=Read-Host-Prompt"What is your name?"

I typically execute such Powershell scripts from a fileshare like:

Powershell
powershell-ExecutionpolicyBypass\\UNC\path\to\myscript.ps1

When I execute this script while locally logged on to a Windows Server 2016 server, the Read-Host line works as expected. Likewise, when logged on directly to the server if I manually execute the Read-Host line at the Powershell prompt, it also works as expected.

However, if I initiate a remote Powershell session from my local workstation to the server using:

Powershell
Enter-PSSession-ComputerName<redacted-AuthenticationCredssp-CredentialDOMAIN\username

and then I execute the script via the UNC share, the Read-Host line does not work. It never...

<

Powershell - Regex log files

Maybe I'm going about this wrong. I have a log file that contains Date, Time, Name. I can use a regex for each to find the data in a line of text:

Powershell
$regdt='\b\d{1,2}\/\d{1,2}\/\d{1,4}\ \d{1,2}\:\d{1,2}\:\d{1,2}\b'$regtime='\d{1,2}\:\d{1,2}\:\d{1,2}\b'$regnm='\w+\ \w+\ * \(\w{2,}\)'

This obviously outputs each match from each line. However, I would like for them all to output with the other data from the line. For example, my incoming text looks like this:

Text
log:221:11/23/19 15:56:07.372 S I [T-16136] - HTTP UserMgr: Start User login notify for user: Bob Smith (Home) log:248:11/23/19 16:56:07.950 S I [T-16136] - User Logout: Bob Smith (Home) 

The output I am looking for is:

Text
11/23/19, 15:56:07, User Login, Bob Smith (Home) 11/23/19, 16:56:07, User Logout, Bob Smith (Home) 

I am using the following to Output:...

Script help

Hello all, I need to install over 40 languages which I did by using lpksetup to install the .cab files. Now I have to install the local experience packs for the same amount. Of course, these are in individual folders, and they also have a corresponding license file. I am hoping for an automated way via a script since I have the wim mounted. Basically I would like the script to recurse the folder structure and install appx file and the corresponding license file in the folder. I appreciate any suggestions.


Powershell - Create custom hash table

Hi All,

I'm trying to work out on how this could be done, but unfortunately not able to figure this out

Basically I'm trying to create a hash table based on some custom values/variables

Powershell
Powershell
$SourceItems=Get-Item$SourceItems_ID=$SourceItems.ID$SourceItems_Name=$SourceItems.Name$childItem1=Get-Item$childItem1_ID=$childItem1.ID$childItem1_Name=$childItem1.Name$childItem2=Get-Item$childItem2_ID=$childItem2.ID$childItem2_Name=$childItem2.Name$childItem3=Get-Item$childItem3_ID=$childItem3.ID$childItem3_Name=$childItem3.Name$childItem4=Get-Item$childItem4_ID=$childItem4.ID$childItem4_Name=$childItem4.Name$output=@()foreach($SourceItemin$SourceItems){if($childItem1_ID-eq$SourceItem.ID){$objectproperty1=[ordered]@{"SourceItem_Name"=$SourceItem.NameStatus=...

How can I add Sticky Notes fpr all users over powershell commands

Hello everyone,

I tried to Add Sticky Notes over Add-AppxPackage on my own User and that works perfect.

My question now is what can I do to Add/reinstall Sticky Notes over Powershell for all user and not only for the current.

Thanks for every help

Create Variable from Output in Powershell

Hello everyone,

can someone maybe tell me how I create a variable from an Output in Powershell?  

Example:

Output in Powershell is:

Name                 : Microsoft.MicrosoftStickyNotes
Publisher             : C=US
Architecture         : X64
Version               : 3.1.46.0

So how can I pick for example The Output "Publisher" and create a Variable for my next command

Thanks!

Issues with -join.

Greetings!

I'm running into an issue where I'm not understanding the inner-working of -join.

In the below section, -join works if the answer to IF is true.

If the answer is false, PowerShell is concatenating the variables, but not joining them with the commas.

Why will -join work on the true section, but not the false section?


$HostnameQuestion = Read-Host -Prompt "Is ($SplitServerListLine[0]) the current hostname?`nEnter [Y]es or [N]o."

If ($HostnameQuestion -like "Y") {
Write-Host "The hostname does not need to be changed. Continuing with script..."
$RebuildServerLine = $SplitServerListLine[0..1] + $SplitWorkstation[0] + $RebuildCertPath2 + $NewPassword -join ","
} Else {
Write-Host "The hostname needs to be updated."
$UpdatedHostname = Read-Host -Prompt "What is the current hostname?"
$RebuildServerLine = $UpdatedHostname +...

Script to uninstall .exe not working

Howdy all, I am wondering if anyone knows why this isn't working/has time to assist :)

I have a batch of computers that I am trying to uninstall Softros LAN Messenger from.

I have found this script online and modified it to suit my needs, however it is not working.

At this point I am just testing it on my machine, but it does not uninstall the software.

It errors out like so;

Get-Process : A positional parameter cannot be found that accepts argument '$null'.
At line:1 char:1
+ PS C:\windows\system32 $softros = Get-ChildItem -Path HKLM:\SOFTWARE ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-Process], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.GetProcessCommand

Does anyone know what the issue is?

Full...

Viewing all 15370 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>