Go Premium for a chance to win a PS4. Enter to Win

x

Powershell

16K

Solutions

7K

Contributors

Windows PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework. PowerShell provides full access to the Component Object Model (COM) and Windows Management Instrumentation (WMI), enabling administrators to perform administrative tasks on both local and remote Windows systems as well as WS-Management and Common Information Model (CIM) enabling management of remote Linux systems and network devices.

Share tech news, updates, or what's on your mind.

Sign up to Post

Hi,

I've got a Script to read out all the Disk Sizes of my VMs in the Virtual Machine Manager (see below).

First I read out all VMs ($VMs). This is working correctly when checking the variable.
Then I go into the loop for all VMs. In there I'm getting all the Disks of the VMs. When checking the variable $Disks, the disks are correctly read out of the Server.
After that I've created a loop, which should write the Disksize to $VM.Disk1, $VM.Disk2, VM.Disk3... (depending on the count of Disks).

$VMs = Get-VM | Sort-Object -Property Name
foreach ($VM in $VMs){
    $Disks = $VM | Get-VirtualHardDisk

    $int = 1

    foreach ($Disk in $Disks){
        $Disksize = [Math]::Round($Disk.MaximumSize / 1073741824, 2)

        $VM."Disk$int" = $Disksize

        $int += 1
    }
}

Open in new window


The problem:
There's a server, let's call it "Server1" which has 2 Disks (100GB and 50GB).
I want it to be shown like:
$Server1.Disk1 = 100
$Server1.Disk2 = 50
$Server1.Disk3 = null
$Server1.Disk4 = null
...
But me result look like this:
$Server1.Disk1 = 100
$Server1.Disk2 = 50
$Server1.Disk3 = 50
$Server1.Disk4 = 100
$Server1.Disk5 = 50
$Server1.Disk6 = 100
$Server1.Disk7 = 50
$Server1.Disk8 = 100

It look's like it's going through the $Disks loop several times. But when checking the $Disks variable there are only 2 Disks shown.
Has somebody got any idea, what I'm doing wrong?
0
Lessons on Wi-Fi & Recommendations on KRACK
Lessons on Wi-Fi & Recommendations on KRACK

Simplicity and security can be a difficult  balance for any business to tackle. Join us on December 6th for a look at your company's biggest security gap. We will also address the most recent attack, "KRACK" and provide recommendations on how to secure your Wi-Fi network today!

I have created a Powershell script that will replace a character string with another string, this works file along as only one file is in the directory.

This is the script I am using

#Example of PowerShell replacing text
Clear-host
$Location = "C:\Users\luketr\Desktop\test\*.txt"
$Change = Get-Content $Location
$Change | ForEach-Object {$_ -Replace "'THIRD',", ""} | Set-Content $Location
$Change | ForEach-Object {$_ -Replace "'SECOND',", ""} | Set-Content $Location
$Change | ForEach-Object {$_ -Replace "'FOURTH',", ""} | Set-Content $Location

If I have more than one file in the directory the files are merged.

I have attached the files I am wanting the place the word, SECOND, THIRD and FOURTH in the separate files.

Thanks

Luke
bacotim0.20986.txt
bacotim0.21008.txt
bacotim0.21033.txt
0
Hi All,

I need all the information Active Directory can provide on a user account:

So far i have this code:

Get-ADUser -Filter 'Name -like "*kelly*"' | select *

Open in new window


The above code, is that all the information it can provide? is there a better code i can utilise?

thank you in advance.

Kelly
0
I need to use Group Policy to make it so that only domain admins can run and use powershell. I have tried to use the "Don't run specified Windows applications," however it only blocks use through Windows Explorer/Start Menu/Run.. - I can still open a CMD and run Powershell within in.

Is there a way to make it so that no normal user can use Powershell?
0
Hello, we have three domains. domain1, domain2, domain3
I have a list of computer that i need to remove from domain2.
Once i enter the powershell session with my domain admin account, the session is created under domain1.

Get-Content C:\Users\domainadmin-SA\Documents\ComputerList.txt | Remove-ADComputer -WhatIf

How do i create the pssession under domain2 so when i read the computer list the computer accounts are removed ?

Thanks
0
I am struggling to get my Powershell output to print out completed.  The data is just what I want ... but it truncates with ...}.
Get-Datastore | Select Name, @{N="NumVM";E={@($_ | Get-VM)}}

Such as :  DS-34            {apmyvdisa1, apmyvs1, apmyvdimr1, apmyfusionapp1...}

Can someone help with me with how to stop this:  I've Googled and tried variations of -autosize, -wrap, out-string, etc.. - I just can't make it stop.

Thanks
0
Good afternoon,

Since last month, we suddenly started experiencing mapping issues on 10% percent of our computers with no clear pattern on what the issue may be.  

We have a network composed of 400 computers running Windows 7 Pro using the same login script with no persistent mapping (VBS) under the same domain policy. Our DCs and File server are  Windows Server 2008r2.

The computers experiencing mapping issues  (Red X), they are able to get some of the mapped drives with no issues from the same and only file server.

On startup (First boot of the day), when we open Windows Explorer some of our network drives are shown with a red "X". If we click the network drives with a red x, they connect and display the content with no issues but the red X does not go away. If I run any application that needs files on those drives, it will say the resource is unavailable.

Typing net use does not display the network drives with a red x. Trying to map with net use the red x maps result in a message that the network drives are already in use. Same result trying to clean or map the red x network drives with powershell.

After the issue appeared, we started removing the following registry keys aiming to force the disconnection of the ghost network maps (Red X) with no good results:

o      HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2
o      HKEY_USERS\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2
o      …
0
I need a way to tell when a computer name was changed.  This could be through PowerShell, SCCM, WMI, etc....  

Bonus for being able to retrieve old and new name at the same time.

Anyone have a way to do this?
0
We are looking for ideas on getting Microsoft to defederate a domain.

We were looking to purchase Office 365 through GoDaddy. During that process, they asked if our domain pbhcpa.com had been federated previously to 365. Since we (here in IT) had made no conscious decision to do so, we said “no, it has not been federated.” We have three O365 accounts that are pbhcpa.onmicrosoft.com but pbhcpa.com was not affected by this. We purchased office 365 through GoDaddy. Our GoDaddy team got the message “pbhcpa.com has already been used to setup an Office 365 account at Microsoft. Before you can create any new users here, you must remove pbhcpa.com and any associated accounts from your previous Office 365 account.”

pbhcpa.com has already been used to setup an Office 365 account at Microsoft
We didn’t have any 365 accounts with pbhcpa.com so we opened a case with Office 365 support. The first tech found that someone at the firm, a year ago, created a Power BI account. The signup caused Office 365 to reserve our domain but never set it up as an actual tenant. This caused a shadow tenancy. The tech said this is a flaw on the Microsoft side and that he would have to escalate it. He had us log into our onmicrosoft account and run a Powershell script to defederate.

We connected to Exchange Online using https://technet.microsoft.com/library/jj984289.aspx

Then he had us run a modified version of this:

Set-Mailbox Identity -EmailAddress <NEW primary E-mail address>
Set-Mailbox identity -EmailAddresses @{Remove="<E-mail …
0
So I found a vbs script to write information into the computer description field upon login

Here's the code and my error shows below the code.

Not sure how to fix this, especially since I'm a scripting novice

Option Explicit
Const ADS_PROPERTY_UPDATE = 2 
Dim objSysInfo, objUser, objNetwork, strComputer, strDescription

Set objSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" "&" objSysInfo.UserName)

Set objNetwork = CreateObject("Wscript.Network")
strComputer = objNetwork.ComputerName

strDescription = "Logged on to " "&" strComputer "&" " at " "&" Date "&" " " "&" Time

objUser.Put "description", strDescription
objUser.SetInfo

Open in new window


I want to run this as a PS1 file but I get the following errors

At C:\Users\ed.crist\Desktop\loguser.ps1:6 char:35
+ Set objUser = GetObject("LDAP://" "&" objSysInfo.UserName)
+                                   ~~~
Unexpected token '"&"' in expression or statement.
At C:\Users\ed.crist\Desktop\loguser.ps1:6 char:34
+ Set objUser = GetObject("LDAP://" "&" objSysInfo.UserName)
+                                  ~
Missing closing ')' in expression.
At C:\Users\ed.crist\Desktop\loguser.ps1:6 char:58
+ Set objUser = GetObject("LDAP://" "&" objSysInfo.UserName)
+                                                          ~
Unexpected token ')' in expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnexpectedToken
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE
LVL 5
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Hi,

I'd like to use winscp but do not have a fingerprint. Yes, I know that's a security risk but not where I use it.

This is the tool https://gallery.technet.microsoft.com/WinSCP-PowerShell-Module-ee1601ff



How can I find a way around it?
J.
0
I need some advice on how I can execute a script on multiple computers within my organization.
Lets say I have 4 computers. It will be done in a chain e.g it starts with my computer and if the script fails then it will try and run it on computer 2 and if it fails then the 3rd and so on, but if it succeed then it won't be run on the remaining computers.
0
Hello All,

I have been given access to two subscription which are of two separate projects. When I run the command Get-AzurePublishSettingsFile using powershell it show me one one subscription, and when I use Get-AzureRmSubscription it shows me the other one.

Now I want the 2nd one which needs be made as default and when I download the file it should show me all or the one which I want to use henceforth as default.

For Subscription A I have access as Owner and for B I have as contractor. I need to be using Subscription B from now on. All commands and management or admin commands should be executed on Subscription B.

Also, I wanted to know what is the difference B/W these 2 commands: Get-AzureRmSubscription & Get-AzureSubscription

Any help or assistance is appreciable.

Please let me know if you require anymore info.
0
I am trying to audit the permissions on a file server as a domain administrator and am getting an error for 'unauthorized operation' on some uses. When I use D:\Share\IT, I am able to get the command to run; when I use \Prod I cannot.

I am using the following in PowerShell:
Get-ChildItem D:\Share\Prod -Directory -Recurse | Get-Acl | Select-Object path,accesstostring,owner| Export-Csv C:\Temp\file.csv

I am receiving the following error:
Get-Acl : Attempted to perform an unauthorized operation.
At line:1 char:51
+ Get-ChildItem D:\Share\Prod -Directory -Recurse | Get-Acl |Select-Object  ...
    + CategoryInfo          : NotSpecified: (:) [Get-Acl], UnauthorizedAccessException
    + FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.GetAclCommand

I am logged in as a domain administrator, with PowerShell using Run As Administrator.
0
Thanks to Rick_2CA - https://gallery.technet.microsoft.com/office/Mailbox-Pre-Archive-347f9162/view/Discussions

I have been able to Modify this script to include: TotalDeleteditemSize and TotalDeleteditemCount

This outputs the below and works exactly how I want:

ItemsCount      
ArchiveItemsCount      
ItemsSizeBytes      
ArchiveItemsSizeBytes      
TotalDeletedItemSize            
DeletedItemCount


The part I am having trouble with, and where I would like a push in the right direction is how to obtain the ArchiveTotalDeleteditemSize & ArchiveTotalDeleteditemCount (The count and size of data that CAN be archived, same as what is output from "ArchiveItemsSizeBytes")

Below is the script, that I have manipulated to include the

TotalDeleteditemSize & TotalDeleteditemCount......

I have attempted to match what was already in the script, by copying the code, and changing the values (Via Powershell ISE), However, I just end up with nothing being returned or getting the identical results as the ArchiveItemsizebytes

Essentially I am after the Archivable size & Count for recoverable deleted items

Any assistance would be greatly appreciated!!!

If I have worded anything wrongly, or something does not make sense, please let me know, and I will be happy to clarify...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


# Exchange 2010 Mailbox PreArchive Statistics
# Purpose:  Query mailboxes for mail older than X days in order …
0
Hello experts,

One of the application teams is using a java application to authenticate users and for SSO, the app authenticates the user and if his password is set to expire in 14 days, the app throws a message to the user that his password is expiring in 14 days, and the user clicks OK, and after that he is redirected to a server/app that uses SSO and the decryption of his password fails and he cannot login to the app (although the user is initially authenticated successfully). This only happens for users whose password is set to expire in 14 days. The java app is working fine for 99% of the users, except for those users whose password is set to expire in 14 days.

Any ideas as to how I could assist the application team, as to why this behavior, and what could be wrong.

Your assistance is much appreciated.
0
I need help in fixing this script. When I run it, it gives me the HostName of the computer but the TaskName does not come out correct. This script is checking for any scheduled tasks that run under the "UserA" account

This is how I would like it to show in the CSV file
Example.
HostName, TaskName
Server100, Reboot
Server100, Shutdown
Server101, Reboot


$Servers = Get-Content servers.txt
$user = "UserA"

foreach ($computername in $Servers)
{

$schtask = schtasks.exe /query /s $computername /V /FO CSV | ConvertFrom-Csv | Where { $_."Run As User" -eq $user}

    {
    $object = New-Object –TypeName PSObject
            $object | Add-Member –MemberType NoteProperty –Name HostName –Value $computername
                  $object | Add-Member –MemberType NoteProperty –Name TaskName –Value $($schtask.TaskName)
                  $findings+=$object;
    }
}

$findings | Export-CSV -path ServerSchedultTasks.csv

Your help is greatly appreciated.
0
I am looking for a script (PowerShell or JS) that will create multiple Calendar overlays for a SharePoint online Calendar. I found some for SharePoint 2013, but it does not work for SharePoint online. When creating a SharePoint site template, Calendar Overlays are stripped. Unless anyone can think of another way of automatically creating them, Scripting seems the way to go.

Any help will be great. Thank you.
0
I want to write a script in Windows PowerShell ISE that will ask the user for their name and also ask a question to the user with three options. it need to run on of the options and display the output.
0
Configuration Guide and Best Practices
LVL 1
Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

Hey EE

Can someone help add to this script a progress bar ?  I use this to add 1000s of accounts and it would be nice to see a progress or percentate status ,

Import-Csv "c:\Temp\YourCSVFile.csv" |
ForEach{
       Add-ADGroupMember -Identity $_.Group -Members $_.SamAccountName    
       }
0
Hi All,

I have the below working script, though would like to pick some experts brains please.

A)Is there anything wrong, i.e, can I cause harm/damage if I am running the "Unlock-AD" if the actual account isn't even locked?

eg, should it include something like - If Username is locked, then Unlock?

B)Is the below formatting OK, or is there a better "Preferred/Recommended" way I should be using?

C)As I work in 1st/2nd Line Support I often get calls for AD unlocks, any other suggestions I should be running this script to make it more efficient

eg, does anyone use a script to search for surname and first name to pick up female name changes etc instead of by username or how else do others do their environment?

Thanks,

Import-Module ActiveDirectory

$Credentials = Get-Credential $UserName = Read-Host "Enter in the Username to check"

Get-ADUser $UserName -Properties Displayname, LockedOut, badPwdCount, AccountLockoutTime, PasswordExpired `
| Select-Object -Property Displayname, LockedOut, badPwdCount, AccountLockoutTime, PasswordExpired

Unlock-ADAccount $UserName -Credential $Credentials

Open in new window

0
cannot find SERVER Manager ( windows server 2012)cannot find SERVER Manager ( windows server 2012),i run a powershell script to enable multiple users and i restart rdp and now i cannot find servr manager how to enable it?
0
Hi All,

I am trying to put together a little GUI to be used by my team so that we can run a selection of PS scripts at the click of a few buttons.

The idea i have seen in an old job several years back was something sort of like this,

Basically a page with Buttons and text box descriptions,

then a text file or even integrated for a task list that I can edit the Function and Description of the buttons.

Has anyone seen anything like this, i am new to programming and cant afford to spend several hundred for PowerStudio i was hoping to find a easier way that I can edit someone elses work?

thanks
ideas
0
I am trying to create  a script that could help me create many folders. No problems with that, but I wanted to suppress the output of new-item . If I use  | out-null on a PS Prompt I see the Output remains suppressed, but when I use it in my script it does not suppress the output. Any idea?

-------------------------------------

Write-Host  "*** Welcome ***"
$path = get-location
$a = Read-Host "Enter the Number for Iteration 1"
$b = Read-Host "Enter the Number for Iteration 2"
for ($i=0;$i -lt $a ; $i++) { $i1 = $i+1 ; $pfname = "AAA$i1" ; Write-Host "Creating Parent Level Folder $pfname " ; New-Item -type Directory -path $path -name $pfname  | out-null ; for ($j=0 ; $j -lt $b ; $j++) { $childpath = "$path\$pfname"  ; $j1 = $j +1; $cfname = "BBB$j1" ; Write-Host "Creating Child Level Folder $cfname" ;  new-item -type Directory -path $childpath -name $cfname | out-null }}


--------------------------------------------------------------------------------
0
when i export Get-MailboxFolderStatistics username | Select Name, Identity,FolderandSubFolderSize,ItemsinFolderandSubfolders
there are items in  Top of Information Store, when I went to my outlook I do n ot see any items but when I uncheck "Show home page by default for this folder" I still see my mailbox have no items in Top of Information Store..

how is Get-MailboxFolderStatistics get these items and are there actually items in  Top of Information Store ?
0

Powershell

16K

Solutions

7K

Contributors

Windows PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework. PowerShell provides full access to the Component Object Model (COM) and Windows Management Instrumentation (WMI), enabling administrators to perform administrative tasks on both local and remote Windows systems as well as WS-Management and Common Information Model (CIM) enabling management of remote Linux systems and network devices.